@mightyplow/jslib
Version:
js helpers library
429 lines (301 loc) • 12 kB
Markdown
## Objects
<dl>
<dt><a href="#array">array</a> : <code><a href="#object">object</a></code></dt>
<dd></dd>
<dt><a href="#function">function</a> : <code><a href="#object">object</a></code></dt>
<dd></dd>
<dt><a href="#html">html</a> : <code><a href="#object">object</a></code></dt>
<dd></dd>
<dt><a href="#object">object</a> : <code><a href="#object">object</a></code></dt>
<dd></dd>
<dt><a href="#string">string</a> : <code><a href="#object">object</a></code></dt>
<dd></dd>
<dt><a href="#stylesheet">stylesheet</a> : <code><a href="#object">object</a></code></dt>
<dd></dd>
</dl>
<a name="array"></a>
## array : [<code>object</code>](#object)
**Kind**: global namespace
* [array](#array) : [<code>object</code>](#object)
* [.chunkedForEach(ar, fn, chunkSize)](#array.chunkedForEach) ⇒ <code>Promise</code>
* [.ensureArray(val)](#array.ensureArray)
* [.module.exports(ar)](#array.module.exports) ⇒ <code>\*</code>
* [.module.exports(ar)](#array.module.exports) ⇒ <code>Array</code>
* [.head(ar)](#array.head) ⇒ <code>\*</code>
* [.tail(ar)](#array.tail) ⇒ <code>T</code>
* [.toArray(arraylike)](#array.toArray)
* [.module.exports(ar)](#array.module.exports)
<a name="array.chunkedForEach"></a>
### array.chunkedForEach(ar, fn, chunkSize) ⇒ <code>Promise</code>
Splits an array into chunks and breaks the execution queue to ensure reactivity.
**Kind**: static method of [<code>array</code>](#array)
| Param | Type |
| --- | --- |
| ar | <code>Array</code> |
| fn | [<code>function</code>](#function) |
| chunkSize | <code>number</code> |
<a name="array.ensureArray"></a>
### array.ensureArray(val)
**Kind**: static method of [<code>array</code>](#array)
| Param |
| --- |
| val |
<a name="array.module.exports"></a>
### array.module.exports(ar) ⇒ <code>\*</code>
**Kind**: static method of [<code>array</code>](#array)
| Param |
| --- |
| ar |
<a name="array.module.exports"></a>
### array.module.exports(ar) ⇒ <code>Array</code>
Returns all values of an array, which are not undefined.
**Kind**: static method of [<code>array</code>](#array)
| Param | Type |
| --- | --- |
| ar | <code>Array</code> |
<a name="array.head"></a>
### array.head(ar) ⇒ <code>\*</code>
**Kind**: static method of [<code>array</code>](#array)
| Param |
| --- |
| ar |
<a name="array.tail"></a>
### array.tail(ar) ⇒ <code>T</code>
**Kind**: static method of [<code>array</code>](#array)
| Param |
| --- |
| ar |
<a name="array.toArray"></a>
### array.toArray(arraylike)
**Kind**: static method of [<code>array</code>](#array)
| Param |
| --- |
| arraylike |
<a name="array.module.exports"></a>
### array.module.exports(ar)
**Kind**: static method of [<code>array</code>](#array)
| Param |
| --- |
| ar |
<a name="function"></a>
## function : [<code>object</code>](#object)
**Kind**: global namespace
* [function](#function) : [<code>object</code>](#object)
* [.enqueueWithResults](#function.enqueueWithResults) ⇒
* [.argsToArray(fn)](#function.argsToArray) ⇒ [<code>function</code>](#function)
* [.checkTypes()](#function.checkTypes)
* [.combine()](#function.combine) : [<code>function</code>](#function)
* [.curry(fn)](#function.curry) ⇒ <code>curried</code>
* [.module.exports(fn, timeout)](#function.module.exports) ⇒ [<code>function</code>](#function)
* [.enqueue(promiseGenerators)](#function.enqueue) ⇒
* [.indentity(arg)](#function.indentity)
* [.measureTime(label, fn)](#function.measureTime)
* [.memoize(fn, [timeout])](#function.memoize) ⇒ [<code>function</code>](#function)
* [.module.exports()](#function.module.exports)
* [.promisify(fn, context)](#function.promisify)
<a name="function.enqueueWithResults"></a>
### function.enqueueWithResults ⇒
Returns a function which executes promises one after another. The resulting function
returns a promise, which gets filled with an array of the results of the single promises.
**Kind**: static constant of [<code>function</code>](#function)
**Returns**: function which executes the promises
| Param | Description |
| --- | --- |
| promiseGenerators | an array of functions which return a promise |
<a name="function.argsToArray"></a>
### function.argsToArray(fn) ⇒ [<code>function</code>](#function)
**Kind**: static method of [<code>function</code>](#function)
| Param |
| --- |
| fn |
<a name="function.checkTypes"></a>
### function.checkTypes()
**Kind**: static method of [<code>function</code>](#function)
<a name="function.combine"></a>
### function.combine() : [<code>function</code>](#function)
**Kind**: static method of [<code>function</code>](#function)
<a name="function.curry"></a>
### function.curry(fn) ⇒ <code>curried</code>
**Kind**: static method of [<code>function</code>](#function)
| Param |
| --- |
| fn |
<a name="function.module.exports"></a>
### function.module.exports(fn, timeout) ⇒ [<code>function</code>](#function)
Creates a function which debounces with the given timeout and resets the timer
on every function call.
The returned debounced function has a function property abort() which aborts the timer.
**Kind**: static method of [<code>function</code>](#function)
| Param | Type |
| --- | --- |
| fn | [<code>function</code>](#function) |
| timeout | <code>number</code> |
<a name="function.enqueue"></a>
### function.enqueue(promiseGenerators) ⇒
returns a function which executes promises one after another
**Kind**: static method of [<code>function</code>](#function)
**Returns**: function which executes the promises
| Param | Description |
| --- | --- |
| promiseGenerators | an array of functions which return a promise |
<a name="function.indentity"></a>
### function.indentity(arg)
**Kind**: static method of [<code>function</code>](#function)
| Param |
| --- |
| arg |
<a name="function.measureTime"></a>
### function.measureTime(label, fn)
Takes a function and logs the time it takes on the console.
**Kind**: static method of [<code>function</code>](#function)
| Param |
| --- |
| label |
| fn |
<a name="function.memoize"></a>
### function.memoize(fn, [timeout]) ⇒ [<code>function</code>](#function)
Caches a function result for a specified time.
**Kind**: static method of [<code>function</code>](#function)
| Param | Type | Description |
| --- | --- | --- |
| fn | [<code>function</code>](#function) | the function of which the result should be cached |
| [timeout] | <code>number</code> | the time in ms which tells the time after which the results should be deleted from the cache |
<a name="function.module.exports"></a>
### function.module.exports()
**Kind**: static method of [<code>function</code>](#function)
<a name="function.promisify"></a>
### function.promisify(fn, context)
**Kind**: static method of [<code>function</code>](#function)
| Param |
| --- |
| fn |
| context |
<a name="html"></a>
## html : [<code>object</code>](#object)
**Kind**: global namespace
<a name="html.createLinkTag"></a>
### html.createLinkTag(filename, mediaQuery) ⇒ [<code>string</code>](#string)
**Kind**: static method of [<code>html</code>](#html)
| Param |
| --- |
| filename |
| mediaQuery |
<a name="object"></a>
## object : [<code>object</code>](#object)
**Kind**: global namespace
* [object](#object) : [<code>object</code>](#object)
* [.defaults(obj, values)](#object.defaults) ⇒ <code>Object</code>
* [.extract(props)](#object.extract) ⇒ [<code>function</code>](#function)
* [.filter(obj, pred)](#object.filter) ⇒ <code>\*</code>
* [.fromArray(array, key, keep)](#object.fromArray) ⇒ <code>\*</code>
* [.merge(targetObject, objects)](#object.merge) ⇒ <code>Object</code>
* [.prop(prop)](#object.prop) ⇒ [<code>function</code>](#function)
* [.removeProp(object)](#object.removeProp)
<a name="object.defaults"></a>
### object.defaults(obj, values) ⇒ <code>Object</code>
Populates an object with default values.
**Kind**: static method of [<code>object</code>](#object)
**Returns**: <code>Object</code> - a new object with the default values and the object values
| Param | Type | Description |
| --- | --- | --- |
| obj | <code>Object</code> | the object to populate the values on |
| values | <code>Object</code> | the default values to populate on the target object |
<a name="object.extract"></a>
### object.extract(props) ⇒ [<code>function</code>](#function)
Creates a function which extracts some properties out of an object.
**Kind**: static method of [<code>object</code>](#object)
| Param | Type |
| --- | --- |
| props | [<code>Array.<string></code>](#string) |
<a name="object.filter"></a>
### object.filter(obj, pred) ⇒ <code>\*</code>
**Kind**: static method of [<code>object</code>](#object)
| Param |
| --- |
| obj |
| pred |
<a name="object.fromArray"></a>
### object.fromArray(array, key, keep) ⇒ <code>\*</code>
Receives an array of objects and extracts an object with the given key as index. The key
must be a property of the array items. If the property is not found on the item, the item
is omitted.
**Kind**: static method of [<code>object</code>](#object)
| Param | Type | Description |
| --- | --- | --- |
| array | <code>Array.<Object></code> | |
| key | [<code>string</code>](#string) | |
| keep | <code>boolean</code> | should the extracted prop be kept in the result object |
<a name="object.merge"></a>
### object.merge(targetObject, objects) ⇒ <code>Object</code>
Merges too objects deeply.
**Kind**: static method of [<code>object</code>](#object)
| Param | Type |
| --- | --- |
| targetObject | <code>Object</code> |
| objects | <code>Array.<Object></code> |
<a name="object.prop"></a>
### object.prop(prop) ⇒ [<code>function</code>](#function)
Creates a function which returns a property of a passed object.
**Kind**: static method of [<code>object</code>](#object)
**Returns**: [<code>function</code>](#function) - function to return a property from a passed object
| Param | Type | Description |
| --- | --- | --- |
| prop | [<code>string</code>](#string) | the property to return from the passed object |
<a name="object.removeProp"></a>
### object.removeProp(object)
**Kind**: static method of [<code>object</code>](#object)
| Param |
| --- |
| object |
<a name="string"></a>
## string : [<code>object</code>](#object)
**Kind**: global namespace
* [string](#string) : [<code>object</code>](#object)
* [.append(str, append)](#string.append)
* [.ciCompare(val1, val2)](#string.ciCompare)
* [.toBool(val)](#string.toBool)
<a name="string.append"></a>
### string.append(str, append)
**Kind**: static method of [<code>string</code>](#string)
| Param |
| --- |
| str |
| append |
<a name="string.ciCompare"></a>
### string.ciCompare(val1, val2)
**Kind**: static method of [<code>string</code>](#string)
| Param |
| --- |
| val1 |
| val2 |
<a name="string.toBool"></a>
### string.toBool(val)
**Kind**: static method of [<code>string</code>](#string)
| Param |
| --- |
| val |
<a name="stylesheet"></a>
## stylesheet : [<code>object</code>](#object)
**Kind**: global namespace
* [stylesheet](#stylesheet) : [<code>object</code>](#object)
* [.createStylesheetAst(rules)](#stylesheet.createStylesheetAst) ⇒ <code>Object</code>
* [.getRules(css)](#stylesheet.getRules)
* [.isRuleType(type)](#stylesheet.isRuleType)
<a name="stylesheet.createStylesheetAst"></a>
### stylesheet.createStylesheetAst(rules) ⇒ <code>Object</code>
**Kind**: static method of [<code>stylesheet</code>](#stylesheet)
| Param |
| --- |
| rules |
<a name="stylesheet.getRules"></a>
### stylesheet.getRules(css)
**Kind**: static method of [<code>stylesheet</code>](#stylesheet)
| Param |
| --- |
| css |
<a name="stylesheet.isRuleType"></a>
### stylesheet.isRuleType(type)
**Kind**: static method of [<code>stylesheet</code>](#stylesheet)
| Param |
| --- |
| type |