1.1.1 • Published 3 years ago

common-fn-js v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

common-fn-js

A collection of functions I often use in my node.js projects

I was tired of either rewriting this stuff, or keeping track of different files of different versions - so I figured I would group everything into one public place.

File I/O Methods

Method NameDescriptionSignature
loadFileReads file from given filename, returning promise of that file(STRING, STRING) -> PROMISE(*)
loadTextLoads file as text, returning promise of read text(STRING) -> PROMISE(STRING)
loadJSONLoads file as JSON, returning promise of read JSON(STRING) -> PROMISE(JSON)
writeFileWrite data to given filename using given encoding, returning a promise of the filename if successful(STRING, *, STRING) -> PROMISE(STRING)
writeTextWrites text to given filename, returning promise of filename(STRING) -> PROMISE(STRING)
writeJSONWrite JSON to given filename, returning promise of filename(STRING) -> PROMISE(STRING)
nameOfFileReturns filename without path or extension(STRING) -> PROMISE(STRING)
readDirReturns a promise for an array of paths for the given directory filepath(STRING) -> PROMISE(STRING)
fileStatsReturns promise of file stats for the given filename(STRING) -> PROMISE(fs.Stats)
listFilesReturns an array of every file in every subdirectory of given directory filtered by optional file extension(STRING, STRING) -> PROMISE(STRING)

Functional Programming Methods

Method NameDescriptionSignature
composeAllTransforms a list of unary functions into a single unary function(FUNCTION) -> FUNCTION
flattenReturns a single array of elements from an array that may contain other arrays([*]) -> (*)
assocBinds the given property with the given value to the given object(STRING, *) -> (OBJECT) -> OBJECT
rassoc"Reverse" assoc operation; takes the object before binding identifier to value of given object(OBJECT) -> (STRING, *) -> OBJECT
foldObjReduces the given object to the given accumulator using the given function(OBJECT, (ACC, KEY, VALUE, OBJECT) -> ACC, ACC) -> ACC

CLI Methods

Method NameDescriptionSignature
VARGSReturn promise of variable number of argument from command line(STRING) -> PROMISE({STRING:STRING})
logPrints value to console then returns value(*) -> *
errPrints value to error then returns value(*) -> *
execAsyncRuns shell command, returning promise of result(STRING) -> PROMISE(STRING)

Time/Date Methods

Method NameDescriptionSignature
TimerFinds the amount of time that's elapsed between a "start" DATE object and an "end" DATE object(DATE, DATE) -> TIMER
timeFormatNamespace for standarized time formatting methodsOBJECT
timeFormat.appendZeroAppends 0 to a month less than 10STRING -> STRING
timeFormat.printDateReturns date formatted as mm-dd-yy(DATE) -> STRING
timeFormat.printTimeReturns time formatted as hours:minutes:seconds:milliseconds(DATE) -> STRING
timestampPrints formatted timestamp as timeFormat.printDate|timeFormat.printTime(DATE) -> STRING

Parsing Methods

Method NameDescriptionSignature
parseArrayRecursively applies function to every element of an array, returning a resulta, (b, a, NUMBER, a -> b, b), b -> b
parseObjRecursively applies function to every property of an object, returning a result{x:y}, (b, y, x, {x:y}) -> b, b -> b