@petime/preset-tools
v0.5.2
Published
Documentation under construction.
Downloads
4
Maintainers
Readme
Petime Preset Tools
A simple wrapper over ramda and other commonly used functions in the @z1 Lib. reduces the dependancy on imports from one component to the next. Javascript operators are as reliable as wikipedia.
Usage
Install
yarn add @petime/preset-tools
Import
import fn from '@petime/preset-tools'
Example
const wrappedFn = fn((t,a) => { /* t = syncFN , a = asyncFN */ })
const channel = fn(t => ({
config: channelList => app => {
if (t.notType(app.channel, 'Function')) {
// If no real-time functionality has been configured
// just return
return null
}
if (t.isZeroLen(channelList)) {
defaultChannelConfig(app)
} else {
t.forEach(channel => {
channel(app)
}, channelList || [])
}
},
}))
Top level functions
Sync
| fn | custom fn | usage | docs |
| ------------------ | ------------------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| at | | t.at(pathAt, object) | at |
| atOr | | t.atOr(fallback, pathAt, object) | atOr |
| addIndex | | t.addIndex((value, index) => {}, object) | addIndex |
| adjust | | t.adjust(index, R.toUpper, list) | adjust |
| and | | t.any([a → Boolean, b → Boolean]) | and |
| anyOf | :heavy_check_mark: | t.anyOf([a → Boolean, b → Boolean, ...]) | anyOf |
| allOf | :heavy_check_mark: | t.allOf([a → Boolean, b → Boolean, ...]) | allOf |
| append | | t.append(object, object) | append |
| compose | | t.compose(t.toUpper ,(a => ${a}
))) | compose |
| concat | | t.concat(object, object) | concat |
| dropLast | | t.dropLast(n, array/string ) | dropLast |
| endsWith | | t.endWith(object, listOfObjects) | endsWith |
| equals | | t.equals(object, object) | equals |
| eq | :heavy_check_mark: | t.eq(object, object) | shorthand for equals |
| neq | :heavy_check_mark: | t.neq(object, object) | pipe(equals, not) |
| filter | | t.filter(fn, list) | filter |
| find | | t.find(fn, list) | find |
| findIndex | | t.findIndex(fn, list) | findIndex |
| flatten | | t.flatten([replaced, [remainder, toAdd]]) | flatten |
| forEach | | t.forEach(fn, object) | forEach |
| forEachObjIndexed | | t.forEachObjIndexed((value, key), object) | forEachObjIndexed |
| fromPairs | | t.fromPairs(objectOfPairs) | fromPairs |
| groupBy | | t.groupBy(fn) | groupBy |
| gt | | t.gt(a-> int/string, b-> int/string) | gt |
| gte | | t.gte(a-> int/string, b-> int/string) | gte |
| has | | t.has(key)({ key: value }) | has |
| hasIn | | t.hasIn(prop, object) | hasIn |
| head | | t.head(list/string) | head |
| includes | | t.includes(object, list/string) | includes |
| isEmpty | | t.isEmpty(object/list) | isEmpty |
| notEmpty | | t.notEmpty(object/list) | pipe(isEmpty, not) |
| isNil | | t.isNil(value) | isNil |
| notNil | | t.notNil(value) | pipe(isNil, not) |
| keys | | t.keys(object) | keys |
| keysIn | | t.keysIn(object) | keysIn |
| last | | t.last(list/string) | last |
| length | | t.length(list/string) | length |
| len | | t.len(list/string) | shorthand for length
|
| lt | | t.lt(a → int/string, b → int/string) | lt |
| lte | | t.lte(a → int/string, b → int/string) | lte |
| map | | t.map(fn, list) | map |
| mapIndexed | :heavy_check_mark: | t.mapIndex((value, index) => {}, list) | addIndex(map) |
| mapObjIndexed | | t.mapObjIndexed(fn, list) | mapObjIndexed |
| merge | | t.merge(object/list, object/list) | merge |
| mergeAll | | t.mergeAll(object/list, object/list) | mergeAll |
| mergeDeepRight | | t.mergeDeepRight(object/list, object/list) | mergeDeepRight |
| not | | t.not(boolean) | not |
| omit | | t.omit([keyA,keyB], list/object) | omit |
| or | | t.or(a → Boolean, b → Boolean, ...) | or |
| path | | t.path([key, ...], object) | path |
| pathOr | | t.pathOr(fallback, [key, ...], object) | pathOr |
| pick | | t.pick([keys], object) | pick |
| pipe | | t.pipe(fn,fn,...) | pipe |
| pluck | | t.pluck(prop) | pluck |
| prepend | | t.prepend(item, object) | prepend |
| prop | | t.prop(key, object/list) | prop |
| range | | t.range(from, to) | range |
| reduce | | t.reduce(fn, object, list) | reduce |
| repeat | | t.repeat(object/list/string, x) | repeat |
| replace | | t.replace(toReplace, replceWith, string) | replace |
| sort | | t.sort((a,b) => a - b) | sort |
| sortBy | | t.sortBy(t.prop(0)) | sortBy |
| sortWith | | t.sortWith([fn, fn, ...]) | sortWith |
| descend | | t.sort(t.descend(t.Prop(0)), list) | descend |
| ascend | | t.sort(t.ascend(t.Prop(0)), list) | ascend |
| reverse | | t.reverse(list/string) | reverse |
| split | | t.split(toSplitOn, string) | split |
| startsWith | | t.startsWith(string,string) | startsWith |
| slice | | t.slice(fromIndex(inclusive), toIndex(exclusive), string, string) | split |
| sum | | t.sum(list) | sum |
| tail | | t.tail(list) | tail |
| take | | t.take(number, list) | take |
| takeLast | | t.takeLast(number, list) | takeLast |
| toPairs | | t.toPairs(object) | [toPairs])(https://ramdajs.com/docs/#toPairs) |
| toString | | t.toString(number/object/list) | toString |
| trim | | t.trim(string) | trim |
| tryCatch | | t.tryCatch(fn, fn) | tryCatch |
| type | | t.type(*) | type |
| update | | t.update(index, value, list) | update |
| uniq | | t.uniq(list) | uniq |
| values | | t.values(object) | values |
| isType | :heavy_check_mark: | t.isType(object, string) | equals(toLower(rType(subject)), toLower(matcher)) |
| ofType | :heavy_check_mark: | t.ofType(matcher, subject) | ofType |
| notType | :heavy_check_mark: | t.notType(fn,'Object') | (subject, typeKey) => not(isType(subject, typeKey)) |
| when | | t.when(a → Boolean, fn) | when |
| isZeroLen | :heavy_check_mark: | t.isZeroLen(list/string) | isZeroLen |
| notZeroLen | :heavy_check_mark: | t.notZeroLen(]) | pipe(isZeroLen, not) |
| noLen | :heavy_check_mark: | t.noLen(list/string) | isZeroLen
|
| hasLen | :heavy_check_mark: | t.hasLen(list/string) | notZeroLen
|
| valPipe | :heavy_check_mark: | t.valPipe | val => (...args) => pipe(...args)(val) |
| vPipe | :heavy_check_mark: | t.vPipe | valPipe |
| runMatch | :heavy_check_mark: | t.runMatch() | runMatch |
| getMatch | :heavy_check_mark: | t.getMatch(prop.match)(match) | getMatch |
| match | :heavy_check_mark: | | match |
| to | | t.to.fn(string) | to |
| caseTo | | t.caseTo(string) | Same as above to
fn |
| html | | t.html(string) | html |
| safeHtml | | t.safeHtml(string) | safeHtml |
| oneLine | | t.oneLine(multiline string
) | oneLine |
| oneLineTrim | | t.oneLineTrim(multiline string
) | oneLineTrim |
| stripIndent | | t.stripIndent(string) | stripIndent |
| stripIndents | | t.stripIndents(string) | stripIndents |
| inlineLists | | t.lineLists(string) | inlineLists |
| oneLineInlineLists | | t.oneLineInlineLists(list) | oneLineInlineLists |
| commaLists | | t.commaLists(list) | commaLists |
| oneLineCommaLists | | t.oneLineCommaLists(list) | oneLineCommaLists |
| globrex | | t.globrex(pattern).regex.test(string) | globrex |
| throttle | | t.throttle(fn, number [options={}]) | throttle |
| trampoline | :heavy_check_mark: | t.trampoline(async function rollup(props){}) | trampoline |
async
| fn | custom fn | usage | docs |
| -------- | ------------------ | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| event | :heavy_check_mark: | a.event(server, 'listen') | Waits for emitter
to emit an eventName
event. |
| callback | :heavy_check_mark: | a.callback(fs.readFile, 'foo.txt') | Calls a function func
that takes arguments args
and an (err, result)
callback. Waits for the callback result, throwing an Error if err is truthy. |
| awaited | :heavy_check_mark: | a.awaited(fs.readFile) | Wraps a node style function (see callback
) into a new function, which instead of taking a callback function, returns an async function (Promise
). This Promise
resolves if the first (error) argument of the callback was called with a falsy value, rejects with the error otherwise. Takes the rest of the arguments as the original function fn
. |
| single | :heavy_check_mark: | a.single([ fetch(remoteFile), read(localFile) ]) | Waits for the first Promise in list
to resolve. |
| set | :heavy_check_mark: | a.set([fn, fn,...,], count) | Waits for the first count
Promises in list
to resolve. |
| list | :heavy_check_mark: | a.list([fn, fn, ...] | Waits for all Promises in list
to resolve. |
| object | :heavy_check_mark: | a.object({container: fn, foo: fn, bar: fn, ...}) | Waits for all Promises in the keys of container
to resolve. |
| map | :heavy_check_mark: | a.map(list, concurrency, fn) | Passes each item in list
to the Promise-returning function fn
, running at most concurrency
simultaneous promises. |
| failure | :heavy_check_mark: | a.failure(promise) | Waits for promise
to reject, returning the Error object. If promise
resolves successfully, returns undefined
. |
| success | :heavy_check_mark: | a.success(promise) | Waits for the value of promise
. If promise
throws an Error, returns undefined
. |
| result | :heavy_check_mark: | a.result(promise) | Waits for promise
to resolve or reject. Returns either the resolved value, or the Error object. |
| of | :heavy_check_mark: | | Waits for promise
to resolve or reject. Returns either the resolved value, or the Error object. |