- colorand()
- escapeHTML()
- isValidFunctionName()
- normalizePath()
- simpleReplace()
- str2node()
- str2time()
- strand()
- strSlug()
- trimChar()
- ucfirst()
colorand - Generate random hex color value
colorand() // stringGenerates a random hex color value
The function has no parameters.
| Type/Value | Description |
|---|---|
| String | Color hex |
colorand(); // #67aa9descapeHTML - Escape html special chars
escapeHTML( text ) // stringEscape html special chars, only: &><"'
| Parameter | Type | Default | Description |
|---|---|---|---|
| text | String | - | String to escape |
| Type/Value | Description |
|---|---|
| String | Escaped string |
escapeHTML( 'foo > 1' ); // 'foo > 1'isValidFunctionName - Check string for a valid function name
isValidFunctionName( str ) // booleanVery basic function name check, does not deal with reserved words or any other special cases.
| Parameter | Type | Default | Description |
|---|---|---|---|
| str | String | - | String to check |
| Type/Value | Description |
|---|---|
| Boolean | True if valid |
isValidFunctionName( ',._!not-valid' ); // false
isValidFunctionName( '_fn' ); // truenormalizePath - Normalizes a path string for comparison.
normalizePath( path ) // stringVery basic normalization, removes prefix and trailing slash from given path string.
| Parameter | Type | Default | Description |
|---|---|---|---|
| str | String | - | Path to check |
| Type/Value | Description |
|---|---|
| String | Normalized path |
normalizePath( '/foo/bla/' ); // 'foo/bla'
normalizePath( '/foo/bla' ); // 'foo/bla'simpleReplace - Replace variables inside a string
simpleReplace( tmpl, data, prefix = ':', suffix = '' ) // stringReplaces an objects properties as variables in a given string with the corresponding object values.
| Parameter | Type | Default | Description |
|---|---|---|---|
| tmpl | String | - | Template string to replace variables in |
| data | Object | - | Data object with properties and values |
| prefix | String | ':' | Prefix for the matching regex |
| suffix | String | '' | Suffix for the matching regex |
| Type/Value | Description |
|---|---|
| String | Replaced template string |
simpleReplace( 'Hello :name!', { name : 'Coder' } ); // 'Hello Coder!'str2node - Convert a html string to an actual element
str2node( str, multiple = true ) // Node|NodeListCan convert a html string to a node object that can be used in the DOM.
| Parameter | Type | Default | Description |
|---|---|---|---|
| str | String | - | HTML string to convert |
| multiple | Boolean | true | Return firstChild only if set to false, used when converting single nodes |
| Type/Value | Description |
|---|---|
| null | Returned if the string was empty |
| HTMLElement | Returned if multiple is set to false |
| NodeList | Returned if multiple is set to true |
str2node( '<button type="submit"><span>submit</span></button>' ); // HTMLButtonElementstr2time - Convert a string to Date object
str2time( value ) // DateConverts a string date y-m-d or d-m-y to Date object or returns null if failed.
| Parameter | Type | Default | Description |
|---|---|---|---|
| value | String | - | String to convert |
| Type/Value | Description |
|---|---|
| null | Could not be converted |
| Date | Date object |
str2time( '28.02.1984'); // Datestrand - Generate a random string
strand() // stringGenerates a random string 10 characters in length, this function is optimized for speed not uniqueness.
The function has no parameters.
| Type/Value | Description |
|---|---|
| String | Random string |
strand(); // npnm623gm2strSlug - Convert string to slug
strSlug( str ) // stringConvert string to slug, removes all sorts of special characters.
| Parameter | Type | Default | Description |
|---|---|---|---|
| str | String | - | String to sanitize |
| Type/Value | Description |
|---|---|
| String | Sanitized string |
strSlug( 'äöüà' ); // aouatrimChar - Trim custom character
trimChar( string, charToRemove ) // stringTrim a string with a custom char.
| Parameter | Type | Default | Description |
|---|---|---|---|
| str | String | - | String to trim |
| charToRemove | String | - | Character to trim |
| Type/Value | Description |
|---|---|
| String | Trimmed string |
trimChar( 'foo', 'o' ); // 'f'ucfirst - Capitalize the first character
ucfirst( str ) // stringCapitalize the first character.
| Parameter | Type | Default | Description |
|---|---|---|---|
| str | String | - | String to capitalize first character |
| Type/Value | Description |
|---|---|
| String | Capitalized string |
ucfirst( 'foo' ); // 'Foo'