Skip to content

heliorc/wc-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functions

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

isEmpty(val)

Returns wether or not the string or Array is empty or undefined/null

Kind: global function

Param Type
val String | Array

deprecated(method, otherMethod)

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

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.

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';

toParams(str)

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'

};

getFromObj(path, obj, fb)

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';

template(template, map, fallback)

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.';

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published