craydent-string

Node module to extend string functionality and simplify code for maintainability and readability

Usage no npm install needed!

<script type="module">
  import craydentString from 'https://cdn.skypack.dev/craydent-string';
</script>

README

Craydent 0.13.4

by Clark Inada

Craydent is all inclusive utility library. There are several ways to use the library in NodeJS. More detailed documentation on constants can be found at Craydent Properties. More detailed documentation on methods can be found at Craydent Methods

// require with prototypes - this require will add prototypes to extend classes and add two constants ($c, $g) to the global space.
// $g is an alias to global and $c is the constant containing all the utility methods and properties.
require('craydent-string');
$c.logit($c.VERSION);
arr.prototypedMethod(args);
// require no conflict - this require is the fully modular version with no global constants, prototypes, or methods.
var $c = require('craydent-string/noConflict');
$c.logit($c.VERSION);
$c.prototypedMethod(arr, args);
// require global - this require constants and methods in the global space and add prototypes to extend classes.
// $g is an alias to global and $c is the constant containing all the utility methods and properties.
require('craydent-string/global');
logit($c.VERSION);
arr.prototypedMethod(args);

Categories

Constants

CONSOLE_COLORS (Object) LOCAL_IP (String) TEMPLATE_TAG_CONFIG (Object)
DEBUG_MODE (Boolean) MODULES_LOADED (Object) TEMPLATE_VARS (Array)
ERROR_TYPES (Array) PUBLIC_IP (String) VERSION (String)
HTTP_STATUS_TEMPLATE (Object) RESPONSES (Object)

Methods

String


acronymize


Info: String class extension to create an acronym from the given string

Return: (String)

Parameters:

  • capsOnly: (Boolean) Flag to indicate to use capital letters only.

Overloads:

Parameters

  • match: (RegExp) Pattern to match to qualify the Acronym.

Parameters

  • capsOnly: (Boolean) Flag to indicate to use capital letters only.
  • delimiter: (String|RegExp) Character or RegExp pattern that delimits the string.

Parameters

  • match: (RegExp) Pattern to match to qualify the Acronym.
  • delimiter: (String|RegExp) Character or RegExp pattern that delimits the string.

capitalize


Info: String class extension to capitalize parts of the string

Return: (String)

Parameters:

  • pos?: (Int|Int[]) Index of the string to capitalize
  • everyWord?: (Bool) Flag to capital every word

Overloads:

None


convertUTCDate


Info: String class extension to convert date string to UTC format

Return: (String)

Parameters:

  • delimiter: (String) Character that delimits the date string

Overloads:

None


count


Info: Object class extension to count the properties in the object/elements in arrays/characters in strings.

Return: (Int)

Parameters:

None

Overloads:

Parameters

  • option: (WhereCondition) Query used in Array.where when counting elements in an Array

Parameters

  • option: (String) Word or phrase to count in the String

Parameters

  • option: (RegExp) Word or phrase pattern to count in the String

cut


Info: String class extension to remove between the provided indexes

Return: (String)

Parameters:

  • start_index: (Integer) Start index to cut
  • end_index: (Integer) End index to cut
  • replacement?: (String) String to put in place of the cut

Overloads:

None


ellipsis


Info: String class extension to shorten by ellipsis

Return: (String)

Parameters:

  • before: (Int) Number of characters to use before using ellipsis
  • after?: (Int) Number of characters to use after the ellipsis

Overloads:

None


highlight


Info: String class extension to surround search words with the given tag(default span) and class (default chighlight)

Return: (String)

Parameters:

  • search: (String|RegExp) String or Regular expression to search
  • cssClass?: (String) Class to add for highlighting
  • tag?: (String) Tag to use to surround the search

Overloads:

None


indexOfAlt


Info: Array class extension to find index of a value based on a callback function & String class extension to find the index based on a regular expression

Return: (Integer)

Parameters:

  • value: (any) value to find
  • func: (ArrayIterator<T, TResult>) Callback function used to do the comparison

Overloads:

Parameters

  • regex: (RegExp) Regular expression to check value against
  • pos?: (Int) Index offset to start

ireplaceAll


Info: String class extension to replace all substrings ignoring case

Return: (String)

Parameters:

  • replace: (String|String[]) String or Array of strings to replace
  • subject: (String|String[]) String or Array of strings to replace with

Overloads:

None


ireplace_all


Info: String class extension to replace all substrings ignoring case

Return: (String)

Parameters:

  • replace: (String|String[]) String or Array of strings to replace
  • subject: (String|String[]) String or Array of strings to replace with

Overloads:

None


isBlank


Info: String class extension to check if the string is empty

Return: (Bool)

Parameters:

None

Overloads:

None


isCuid


Info: String class extension to check if the string is a cuid

Return: (Bool)

Parameters:

  • msFormat?: (Bool) use microsoft format if true

Overloads:

None


isValidEmail


Info: String class extension to check if string is a valid email

Return: (Bool)

Parameters:

None

Overloads:

None


lastIndexOfAlt


Info: String class extension to find the last index based on a regular expression

Return: (Int)

Parameters:

  • regex: (RegExp) Regular expression to check value against
  • pos?: (Int) Max index to go up to in the search

Overloads:

None


ltrim


Info: String class extension to remove characters from the beginning of the string

Return: (String)

Parameters:

  • character?: (Char[]) Character to remove

Overloads:

None


pluralize


Info: String class extension to do a best guess pluralization of the string

Return: (String)

Parameters:

None

Overloads:

None


randIndex


Info: Return a random index without the bounds

Return: (Number)

Parameters:

  • subject?: (String) String to get valid random index

Overloads:

None


replaceAll


Info: String class extension to replace all substrings (case sensitive)

Return: (String)

Parameters:

  • replace: (String|String[]) String or Array of strings to replace
  • subject: (String|String[]) String or Array of strings to replace with

Overloads:

None


replace_all


Info: String class extension to replace all substrings (case sensitive)

Return: (String)

Parameters:

  • replace: (String|String[]) String or Array of strings to replace
  • subject: (String|String[]) String or Array of strings to replace with

Overloads:

None


reverse


Info: String class extension to reverse the string

Return: (String)

Parameters:

None

Overloads:

None


rtrim


Info: String class extension to remove characters from the end of the string

Return: (String)

Parameters:

  • character?: (Char[]) Character to remove

Overloads:

None


sanitize


Info: String class extension to remove potential XSS threats

Return: (String)

Parameters:

None

Overloads:

None


singularize


Info: String class extension to do a best guess singularization of the string

Return: (String)

Parameters:

None

Overloads:

None


startItWith


Info: String class extension to guarantee the original string starts with the passed string

Return: (String)

Parameters:

  • starting: (String) String to start with

Overloads:

None


strip


Info: String class extension to remove characters from the beginning and end of the string

Return: (String)

Parameters:

  • character?: (Char[]) Character to remove

Overloads:

None


substringBetween


Info: String class extension to substring by character instead of using indexes

Return: (String)

Parameters:

  • start?: (Char) Character to use for the starting index (required if end is not passed)
  • end?: (Char) Character to use for the ending index (required if start is null or undefined)

Overloads:

None


substringEndAt


Info: String class extension to substring by character instead of using indexes

Return: (String)

Parameters:

  • end: (Char) Character to use for the ending index

Overloads:

None


substringStartFrom


Info: String class extension to substring by character instead of using indexes

Return: (String)

Parameters:

  • start: (Char) Character to use for the starting index

Overloads:

None


toCurrencyNotation


Info: String class extension to change number to use separater character

Return: (String)

Parameters:

  • separator?: (Char) Character to use as delimiter

Overloads:

None


toDateTime


Info: String class extension to convert string to datetime

Return: (Date|String)

Parameters:

  • options?: (DateTimeOptions) specs with optional properties:
    (Bool) gmt
    (Int) offset
    (String) format

Overloads:

None


toObject


Info: String class extension to convert to JSON

Return: (Object)

Parameters:

  • assignmentChar?: (Char) Character to use as assignment delimiter. Defaults to '&'.
  • delimiter?: (Char) Character to use as pair delimiter

Overloads:

None


trim


Info: String class extension to remove characters from the beginning and end of the string.

Return: (Bool)

Parameters:

  • character?: (Char[]) Character to remove in the String

Overloads:

None

Download