0.5.30 • Published 6 months ago

@z1/preset-task v0.5.30

Weekly downloads
46
License
MIT
Repository
github
Last release
6 months ago

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

fncustom fnusagedocs
att.at(pathAt, object)at
atOrt.atOr(fallback, pathAt, object)atOr
addIndext.addIndex((value, index) => {}, object)addIndex
adjustt.adjust(index, R.toUpper, list)adjust
andt.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
appendt.append(object, object)append
composet.compose(t.toUpper ,(a => ${a})))compose
concatt.concat(object, object)concat
dropLastt.dropLast(n, array/string )dropLast
endsWitht.endWith(object, listOfObjects)endsWith
equalst.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)
filtert.filter(fn, list)filter
findt.find(fn, list)find
findIndext.findIndex(fn, list)findIndex
flattent.flatten([replaced, remainder, toAdd])flatten
forEacht.forEach(fn, object)forEach
forEachObjIndexedt.forEachObjIndexed((value, key), object)forEachObjIndexed
fromPairst.fromPairs(objectOfPairs)fromPairs
groupByt.groupBy(fn)groupBy
gtt.gt(a-> int/string, b-> int/string)gt
gtet.gte(a-> int/string, b-> int/string)gte
hast.has(key)({ key: value })has
hasInt.hasIn(prop, object)hasIn
headt.head(list/string)head
includest.includes(object, list/string)includes
isEmptyt.isEmpty(object/list)isEmpty
notEmptyt.notEmpty(object/list)pipe(isEmpty, not)
isNilt.isNil(value)isNil
notNilt.notNil(value)pipe(isNil, not)
keyst.keys(object)keys
keysInt.keysIn(object)keysIn
lastt.last(list/string)last
lengtht.length(list/string)length
lent.len(list/string)shorthand for length
ltt.lt(a → int/string, b → int/string)lt
ltet.lte(a → int/string, b → int/string)lte
mapt.map(fn, list)map
mapIndexed:heavy_check_mark:t.mapIndex((value, index) => {}, list)addIndex(map)
mapObjIndexedt.mapObjIndexed(fn, list)mapObjIndexed
merget.merge(object/list, object/list)merge
mergeAllt.mergeAll(object/list, object/list)mergeAll
mergeDeepRightt.mergeDeepRight(object/list, object/list)mergeDeepRight
nott.not(boolean)not
omitt.omit(keyA,keyB, list/object)omit
ort.or(a → Boolean, b → Boolean, ...)or
patht.path(key, ..., object)path
pathOrt.pathOr(fallback, key, ..., object)pathOr
pickt.pick(keys, object)pick
pipet.pipe(fn,fn,...)pipe
pluckt.pluck(prop)pluck
prependt.prepend(item, object)prepend
propt.prop(key, object/list)prop
ranget.range(from, to)range
reducet.reduce(fn, object, list)reduce
repeatt.repeat(object/list/string, x)repeat
replacet.replace(toReplace, replceWith, string)replace
sortt.sort((a,b) => a - b)sort
sortByt.sortBy(t.prop(0))sortBy
sortWitht.sortWith(fn, fn, ...)sortWith
descendt.sort(t.descend(t.Prop(0)), list)descend
ascendt.sort(t.ascend(t.Prop(0)), list)ascend
reverset.reverse(list/string)reverse
splitt.split(toSplitOn, string)split
startsWitht.startsWith(string,string)startsWith
slicet.slice(fromIndex(inclusive), toIndex(exclusive), string, string)split
sumt.sum(list)sum
tailt.tail(list)tail
taket.take(number, list)take
takeLastt.takeLast(number, list)takeLast
toPairst.toPairs(object)toPairs
toStringt.toString(number/object/list)toString
trimt.trim(string)trim
tryCatcht.tryCatch(fn, fn)tryCatch
typet.type(*)type
updatet.update(index, value, list)update
uniqt.uniq(list)uniq
valuest.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))
whent.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.valPipeval => (...args) => pipe(...args)(val)
vPipe:heavy_check_mark:t.vPipevalPipe
runMatch:heavy_check_mark:t.runMatch()runMatch
getMatch:heavy_check_mark:t.getMatch(prop.match)(match)getMatch
match:heavy_check_mark:match
tot.to.fn(string)to
caseTot.caseTo(string)Same as above to fn
htmlt.html(string)html
safeHtmlt.safeHtml(string)safeHtml
oneLinet.oneLine(multiline string)oneLine
oneLineTrimt.oneLineTrim(multiline string)oneLineTrim
stripIndentt.stripIndent(string)stripIndent
stripIndentst.stripIndents(string)stripIndents
inlineListst.lineLists(string)inlineLists
oneLineInlineListst.oneLineInlineLists(list)oneLineInlineLists
commaListst.commaLists(list)commaLists
oneLineCommaListst.oneLineCommaLists(list)oneLineCommaLists
globrext.globrex(pattern).regex.test(string)globrex
throttlet.throttle(fn, number options={})throttle
trampoline:heavy_check_mark:t.trampoline(async function rollup(props){})trampoline

async

fncustom fnusagedocs
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.