Z1 Preset Task
Documentation under construction.
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 @z1/preset-task
Import
import { task } from '@z1/preset-task'
Example
const fn = task((t,a) => { /* t = syncFN , a = asyncFN */ })
const channel = task(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 | ✔️ | t.anyOf([a → Boolean, b → Boolean, ...]) | anyOf |
allOf | ✔️ | 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 | ✔️ | t.eq(object, object) | shorthand for equals |
neq | ✔️ | 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 | ✔️ | 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 | |
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 | ✔️ | t.isType(object, string) | equals(toLower(rType(subject)), toLower(matcher)) |
ofType | ✔️ | t.ofType(matcher, subject) | ofType |
notType | ✔️ | t.notType(fn,'Object') | (subject, typeKey) => not(isType(subject, typeKey)) |
when | t.when(a → Boolean, fn) | when | |
isZeroLen | ✔️ | t.isZeroLen(list/string) | isZeroLen |
notZeroLen | ✔️ | t.notZeroLen(]) | pipe(isZeroLen, not) |
noLen | ✔️ | t.noLen(list/string) | isZeroLen |
hasLen | ✔️ | t.hasLen(list/string) | notZeroLen |
valPipe | ✔️ | t.valPipe | val => (...args) => pipe(...args)(val) |
vPipe | ✔️ | t.vPipe | valPipe |
runMatch | ✔️ | t.runMatch() | runMatch |
getMatch | ✔️ | t.getMatch(prop.match)(match) | getMatch |
match | ✔️ | 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 | ✔️ | t.trampoline(async function rollup(props){}) | trampoline |
async
fn | custom fn | usage | docs |
---|---|---|---|
event | ✔️ | a.event(server, 'listen') | Waits for emitter to emit an eventName event. |
callback | ✔️ | 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 | ✔️ | 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 | ✔️ | a.single([ fetch(remoteFile), read(localFile) ]) | Waits for the first Promise in list to resolve. |
set | ✔️ | a.set([fn, fn,...,], count) | Waits for the first count Promises in list to resolve. |
list | ✔️ | a.list([fn, fn, ...] | Waits for all Promises in list to resolve. |
object | ✔️ | a.object({container: fn, foo: fn, bar: fn, ...}) | Waits for all Promises in the keys of container to resolve. |
map | ✔️ | a.map(list, concurrency, fn) | Passes each item in list to the Promise-returning function fn , running at most concurrency simultaneous promises. |
failure | ✔️ | a.failure(promise) | Waits for promise to reject, returning the Error object. If promise resolves successfully, returns undefined . |
success | ✔️ | a.success(promise) | Waits for the value of promise . If promise throws an Error, returns undefined . |
result | ✔️ | a.result(promise) | Waits for promise to resolve or reject. Returns either the resolved value, or the Error object. |
of | ✔️ | Waits for promise to resolve or reject. Returns either the resolved value, or the Error object. |