reach-et-utilities
v2.0.1-alpha.0
Published
Utility Functions to use in my projects
Downloads
40
Readme
reach-et-utilities
Utility functions for editorial tools
Usage
Checker functions
import { isFunction, isMap, isNumber, isObject, isSet, isString, matchingTypes } from 'reach-et-utilities/dist/checks';
isFunction(() => 'a function'); // return true
isMap(new Map()); // return true
isNumber(10); // return true
isObject({}); // return true
isSet(new Set()); // return true
isString('some string'); // return true
matchingTypes('some string', 'another string'); // returns true
matchingTypes('some string', 2); // returns false
Element functions
isElement
<div id="my-element"></div>
import { isElement } from 'reach-et-utilities/dist/elements';
const el = document.getElementById('my-element');
isElement(el); // returns trur
checkElements
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
import { checkElements } from 'reach-et-utilities/dist/elements';
const elements = document.querySelectorAll('li');
checkElements(...elements); // returns true
parseBoolean
<div id="my-element" data-boolean="true"></div>
import { parseBoolean } from 'reach-et-utilities/dist/elements';
const el = document.getElementById('my-element');
parseBoolean(el.dataset.boolean); // returns true
el.dataset.boolean = 'false';
parseBoolean(el.dataset.boolean); // returns false
el.dataset.boolean = 'foo';
parseBoolean(el.dataset.boolean); // returns null
parseNumber
<div id="my-element" data-num="123"></div>
import { parseBoolean } from 'reach-et-utilities/dist/elements';
const el = document.getElementById('my-element');
parseBoolean(el.dataset.num); // returns 123
el.dataset.num = 'foo';
parseBoolean(el.dataset.num); // returns null
Currying
This allows you to curry a function. For more information on currying see https://mostly-adequate.gitbooks.io/mostly-adequate-guide/content/ch04.html
import curry from 'reach-et-utilities/dist/curry';
const adder = (a, b) => a + b;
const add2 = curry(adder, 2); // return function
add2(3); // return 5
add2(5); // return 7
Copyright (c) 2019 "Reach Shared Services Ltd"