- Source:
Methods
(static) decodeHtmlEntities(str) → {string}
Decodes HTML entities in a string using the following rules:
- & becomes &
- " becomes "
- ' becomes '
- < becomes <
- > becomes >
It is different than dom.decodeHTML, which decodes all characters using the browser's DOMParser. This function only decodes the characters listed above and should be used when DOMParser is not available.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
The string to decode |
Returns:
- Type:
-
string
The decoded string
Example
htmlDecode('<a href="#">Link</a>') // <a href="#">Link</a>
(static) encodeHtmlEntities(str) → {string}
Encodes HTML entities in a string using the following rules:
- & (ampersand) becomes &
- " (double quote) becomes "
- ' (single quote) becomes '
- < (less than) becomes <
-
(greater than) becomes >
It is different than dom.encodeHTML, which encodes all characters using the browser's DOMParser. This function only encodes the characters listed above and should be used when DOMParser is not available.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
The string to encode |
Returns:
- Type:
-
string
The encoded string
Example
htmlEncode('<a href="#">Link</a>') // <a href="#">Link</a>
(static) parseAttributes(str)
Parse a string of attributes and return an object
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
Returns:
object
Example
parseAttributes('button text="Click me" data='{"key": \"value"}' class="btn btn-primary"')
// => { button: null, text: 'Click me', data: '{"key": "value"}', class: 'btn btn-primary' }
(static) parseResolutionString(res)
Parses a resolution string into a number. Resolution string is in the format of 'width:height', e.g. '16:9'
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
res |
string
|
Resolution string. Format is 'width:height', e.g. '16:9', or 'widthxheight', e.g. '16x9', or 'width-height', e.g. '16-9', or 'width/height', e.g. '16/9' |
Returns:
number
Example
parseResolutionString('16:9') // => 1.7777777778
parseResolutionString('4:3') // => 1.3333333333
parseResolutionString('4x3') // => 1.3333333333
parseResolutionString('4-3') // => 1.3333333333
(static) parseUrlParameters(paramString, decodeopt) → {object}
Parses a string of url parameters into an object of key value pairs
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
paramString |
string
|
The string to parse without ? or # and with & as separator |
||
decode |
boolean
|
<optional> |
true |
Whether to decode the values or not |
Returns:
- Type:
-
object
of key value pairs
Example
parseUrlParams('foo=true&baz=555') // { foo: true, baz: 555 }
parseUrlParams('foo=bar&baz=qux', false) // { foo: 'true', baz: '555' }
parseUrlParams('foo&bar&baz=qux') // { foo: undefined, bar: undefined, baz: 'qux' }
(static) serializeAttributes(obj) → {string}
Serialize an object of key value pairs into a string of attributes
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object
|
The object to serialize |
Returns:
- Type:
-
string
of attributes
Example
serializeAttributes({ button: null, text: 'Click me', data: '{"key": "value"}', class: 'btn btn-primary' }) // button text="Click me" data="{\"key\": \"value\"}" class="btn btn-primary"
(static) serializeUrlParameters(obj, encodeopt) → {string}
Serialize an object of key value pairs into a string of url parameters
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj |
object
|
The object to serialize |
||
encode |
boolean
|
<optional> |
true |
Whether to encode the values or not |
Returns:
- Type:
-
string
of url parameters
Example
serializeUrlParams({ foo: true, baz: 555 }) // foo=true&baz=555
serializeUrlParams({ bar: undefined, baz: 'qux' }, false) // bar=&baz=qux