- isEmpty(val)
Returns wether or not the string or Array is empty or undefined/null
- deprecated(method, otherMethod)
Use this method to mark deprecated methods in libraries so they show up in the console.
- toQueryString(options, base)
Converts an Object of String/Value pairs to a query string for URL parameters prepended with the "base" character. Encodes unsafe url characters to url safe encodings.
- toParams(str)
Converts URL parameters to a Object collection of key/value pairs Decodes encoded url characters to back to normal strings.
- getFromObj(path, obj, fb)
Returns the value of an object via the path as a string
- template(template, map, fallback)
Processes a string formatted like an ES6 template against an object
Returns wether or not the string or Array is empty or undefined/null
Kind: global function
Param | Type |
---|---|
val | String | Array |
Use this method to mark deprecated methods in libraries so they show up in the console.
Kind: global function
Param | Type |
---|---|
method | String |
otherMethod | String |
Converts an Object of String/Value pairs to a query string for URL parameters prepended with the "base" character. Encodes unsafe url characters to url safe encodings.
Kind: global function
Param | Type |
---|---|
options | Object |
base | String |
Example (convert object to query string)
import {toQueryString} from '@helio/utils';
let queryString = toQueryString({
foo: 'bar',
hello: ['world', 'array'],
unsafe: 'I am an unsafe string'
}, '#');
queryString == '#?foo=bar&hello=world&hello=array&unsafe=I%20am%20an%20unsafe%20string';
Converts URL parameters to a Object collection of key/value pairs Decodes encoded url characters to back to normal strings.
Kind: global function
Param | Type |
---|---|
str | String |
Example (convert query string to object:)
import {toParams} from '@helio/utils';
let paramsObject = toParams('#?foo=bar&hello=world&hello=array&unsafe=I%20am%20an%20unsafe%20string');
paramsObject == {
foo: 'bar',
hello: ['world', 'array'],
unsafe: 'I am an unsafe string'
};
Returns the value of an object via the path as a string
Kind: global function
Param | Type | Description |
---|---|---|
path | String |
|
obj | Object |
Object to find the property in |
fb | String |
Fallback string when not found |
Example
let result = getFromObj('hello.foo', {
hello: {
foo: 'bar'
}
});
result == 'bar';
Processes a string formatted like an ES6 template against an object
Kind: global function
Param | Type | Description |
---|---|---|
template | String |
the string template |
map | Object |
Key/Value pairs to process the string against |
fallback | String |
they string fallback when the value is missing. |
Example
let result = template('I am a string literal formatted ${message.label}.', {
message: {
label: 'to look like an ES6 template'
}
});
result == 'I am a string literal formatted to look like an ES6 template.';