Methods
(inner) buildPath() → {String}
- Description:
Builds a string path from passed in args ( i.e. path/to/thing ).
- Source:
Returns:
- built path from arguments
- Type
- String
(inner) camelCase(string) → {String}
- Description:
Converts a string to camel case.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to be converted |
Returns:
- string in camel case format
- Type
- String
(inner) camelCasePath(path) → {String}
- Description:
Turns a path string into a camel-cased string, if there is more than one step in the path. If there isn't, just returns path.
- Source:
Example
camelCasePath('settings.agendaMap.Count') -> 'settingsAgendaMapCount'
camelCasePath('settings') -> 'settings'
Parameters:
Name | Type | Description |
---|---|---|
path |
String |
Returns:
camel-cased string
- Type
- String
(inner) capitalize(string, lowercaseTailopt) → {String}
- Description:
Converts first letter of a string to be capitalized.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
string |
String | |||
lowercaseTail |
Boolean |
<optional> |
true
|
if true, will also lowercase the all characters except the first |
Returns:
- Passed in string, but capitalized
- Type
- String
(inner) cleanStr(string) → {String}
- Description:
Converts
-
and_
to white space and calls remove removeDot, to remove a period.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to be converted |
Returns:
- cleaned string
- Type
- String
(inner) containsStr(string, substring, fromIndexopt) → {Boolean}
- Description:
Checks if a string contains another string.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
string |
String | value to be checked |
|
substring |
String | value to search for |
|
fromIndex |
Number |
<optional> |
Index of the string to search from |
Returns:
- if the substring exists string
- Type
- Boolean
(inner) delimitString(str, delimiter, delimitersopt) → {String}
- Description:
Converts a string into a delimted script based on the passed in arguments
- Source:
Example
delimitString('fooBar', '_') === 'foo_Bar'
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
str |
String | string of any casing |
|
delimiter |
String | How the string should be split e.g. '_' |
|
delimiters |
Array.<string> |
<optional> |
An array of delimiter characters on which this function searches and breaks. |
Returns:
- A new string with the specified delimiter delimiting each word
- Type
- String
(inner) eitherStr(str1, str2) → {String}
- Description:
Checks if the first param is a string, and returns it.
If it's not a string, the second param is returned
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str1 |
String | return if is string |
str2 |
String | use if first is not a string |
Returns:
- Type
- String
(inner) getNearestDelimiterIndex(text, index, delimiters)
- Description:
Helper for
getWordStartingAt
that finds the index of the exclusive end of the word, given the available ending delimiters
- Source:
Parameters:
Name | Type | Description |
---|---|---|
text |
String | |
index |
Number | |
delimiters |
Array.<string> |
(inner) getWordEndingAt(text, index, delimitersnullable)
- Description:
Gets the word in text ending at index (exclusive)
- Source:
Example
const text = 'foo bar bin'
const word = getWordEndingAt(text, 3)
word === 'foo'
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
String | ||
index |
Number | the exclusive ending index of the word to get |
|
delimiters |
Array.<string> |
<nullable> |
optional array of strings that delimit the start of words. Defaults to the space character. |
(inner) getWordStartingAt(text, index, delimitersnullable)
- Description:
Gets the word in text starting at index
- Source:
Example
const text = 'foo bar bin'
const word = getWordStartingAt(text, 4)
word === 'bar'
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
String | ||
index |
Number | the inclusive starting index of the word to get |
|
delimiters |
Array.<string> |
<nullable> |
optional array of strings that delimit words. Defaults to the space character. |
(inner) hashString(str, maxLengthopt) → {String}
- Description:
Creates a hash from a passed in string consistently
Not intended to be secure
Value comes from being a pure function
Given the same input, it will always return the same output
There is no expectation to convert back from the hash to the original string
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
str |
String | String to be hashed |
|
maxLength |
number |
<optional> |
Max length of the returned hash |
Returns:
- Hashed version of the string
- Type
- String
(inner) hyphenator(str) → {String}
- Description:
Converts a camelCase style rule into a hyphenated style rule
Caches the response to make future conversions faster
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | camelCase style rule rule |
Returns:
- Hyphenated style rule
- Type
- String
(inner) isEmail(string) → {Boolean}
- Description:
Check if string is a email.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to check |
Returns:
- if it's a email
- Type
- Boolean
(inner) isIp(string) → {Boolean}
- Description:
Check if string is an Ip address, both Ip4 and Ip6
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to check |
Returns:
- if it's an Ip address
- Type
- Boolean
(inner) isIp4(string) → {Boolean}
- Description:
Check if string is an IP4 address
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to check |
Returns:
- if it's an IP4 address
- Type
- Boolean
(inner) isIp6(string) → {Boolean}
- Description:
Check if string is an IP6 address
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to check |
Returns:
- if it's an IP6 address
- Type
- Boolean
(inner) isLowerCase(str) → {Boolean}
- Description:
Checks if a string is all lowercase letters
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | String to check if it's lowercase |
Returns:
- True if str is lowercase
- Type
- Boolean
(inner) isPhone(str) → {Boolean}
- Description:
Check if string is a phone number.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to check |
Returns:
- True if str is a phone number
- Type
- Boolean
(inner) isQuoted(str, quotesopt, nullable) → {Boolean}
- Description:
Checks if the string contains quoted text
- Source:
Examples
isQuoted('foo') // false
isQuoted('"foo"') // true
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
str |
String | string to check |
|
quotes |
Array.<string> |
<optional> <nullable> |
optional array of valid quote strings to check with. Defaults to single and double quote characters. |
Returns:
true if str
is a quoted string
- Type
- Boolean
(inner) isStr(str) → {Boolean}
- Description:
Check if passed in value is a string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
* | param to check if type is a string |
Returns:
- True if it's a string
- Type
- Boolean
(inner) isUpperCase(str) → {Boolean}
- Description:
Checks if a string is all capital letters
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | String to check if it's uppercase |
Returns:
- True if str is uppercase
- Type
- Boolean
(inner) isUrl(string) → {Boolean}
- Description:
Check if string is a url.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to check |
Returns:
- if it's a url
- Type
- Boolean
(inner) isUuid(str) → {Boolean}
- Description:
Check if string is a uuid.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to check |
Returns:
- if it's a uuid
- Type
- Boolean
(inner) mapString(str, charMapper) → {String}
- Description:
Maps a string by applying function
charMapper
to each character.
- Source:
Example
mapString("hello", c => c === 'h' ? 'x' : c) // returns 'xello'
Parameters:
Name | Type | Description |
---|---|---|
str |
String | String to be mapped |
charMapper |
function | Function of form (character) => |
Returns:
- String with each character mapped by charMap.
If str is not a string or charMapper not a function, just returns the passed in str argument
- Type
- String
(inner) parseJSON(string) → {Object}
- Description:
Convert JSON string into object, wrapped in a try / catch.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String |
Returns:
- JSON object
- Type
- Object
(inner) plural(str) → {String}
- Description:
Adds an
s
to the end of a string, if one does not exist.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to convert |
Returns:
string as a plural
- Type
- String
(inner) removeDot(str) → {String}
- Description:
Removes a
.
from the start and end of a string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to convert |
Returns:
- string without the
.
- Type
- String
(inner) removeQuotes(str) → {String}
- Description:
Removes quotes from a string
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to convert |
Returns:
string without quotes
- Type
- String
(inner) reverseStr(str) → {String}
- Description:
Reverses string
- Source:
Example
reverseStr('foo') // 'oof'
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to reverse |
Returns:
reversed str
- Type
- String
(inner) sanitize(string) → {String}
- Description:
Sanitize a string of HTML content.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String |
Returns:
- cleaned string
- Type
- String
(inner) singular(str) → {String}
- Description:
Remove an
s
at the end of a string, if the last char is ans
,
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to convert |
Returns:
string as singular
- Type
- String
(inner) snakeCase(str) → {String}
- Description:
Converts a string to snake_case.
- Source:
Example
snakeCase('fooBar') === 'foo_bar'
Parameters:
Name | Type | Description |
---|---|---|
str |
String | String to be converted |
Returns:
- The string in snake_case, or the input if it is not a string
- Type
- String
(inner) spaceJoin(original, toAdd) → {String}
- Description:
Joins strings and array of string together with spaces
- Source:
Parameters:
Name | Type | Description |
---|---|---|
original |
String | The default string that other strings get added to |
toAdd |
string | Array | String of Array of Strings to add to the original |
Returns:
Joined strings seperated by space
- Type
- String
(inner) styleCase(str) → {String}
- Description:
Converts a string to css in js format. Useful for converting css rules into js format, I.E. margin-top => marginTop.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to be converted |
Returns:
- string in style case format
- Type
- String
(inner) template(template, data, fallback) → {String}
- Description:
Simple template replace for ES6 template strings
- Source:
Example
template('${ who } in ${ where }!', { who: 'goats', where: 'boats' })
// Returns "goats in boats"
Parameters:
Name | Type | Description |
---|---|---|
template |
String | String with ES6 syntax items to be replaced |
data |
Object | Array | Data used to replace the ES6 placeholders |
fallback |
any | Used it data does not contain key to be replaced |
Returns:
- template with placeholder values filled
- Type
- String
(inner) templateRx(template, data, fallback, RegEx?opt) → {String}
- Description:
Helper to wrap the template method, and allow passing a custom regex argument Custom regex is used instead the default regex of the template method
- Source:
Example
template('${{ who }} in ${{ where }}!', { who: 'goats', where: 'boats' })
// Returns "goats in boats"
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
template |
String | String with ES6 syntax items to be replaced |
|
data |
Object | Array | Data used to replace the ES6 placeholders |
|
fallback |
any | Used it data does not contain key to be replaced |
|
RegEx? |
Object |
<optional> |
Regular Express to replace the default |
Returns:
- template with placeholder values filled
- Type
- String
(inner) toStr(val) → {String}
- Description:
Converts a passed in value to a string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
val |
* | value to be converted |
Returns:
- value converted into a string
- Type
- String
(inner) trainCase(string) → {String}
- Description:
Converts a string to train case, I.E. marginTop => margin-top.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to be converted |
Returns:
- string in train case format
- Type
- String
(inner) validFilename(fileName) → {Boolean}
- Description:
Checks whether a given string is a valid filename
- Source:
Parameters:
Name | Type | Description |
---|---|---|
fileName |
String | The file name to check if valid |
Returns:
- Type
- Boolean
(inner) wordCaps(string) → {String}
- Description:
Converts all words in a string to be capitalized.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
string |
String | to be converted |
Returns:
- string with all words capitalized
- Type
- String