parsers

Methods

(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