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 Name
Description
Signature
loadFile
Reads file from given filename, returning promise of that file
(STRING, STRING) -> PROMISE(*)
loadText
Loads file as text, returning promise of read text
(STRING) -> PROMISE(STRING)
loadJSON
Loads file as JSON, returning promise of read JSON
(STRING) -> PROMISE(JSON)
writeFile
Write data to given filename using given encoding, returning a promise of the filename if successful
(STRING, *, STRING) -> PROMISE(STRING)
writeText
Writes text to given filename, returning promise of filename
(STRING) -> PROMISE(STRING)
writeJSON
Write JSON to given filename, returning promise of filename
(STRING) -> PROMISE(STRING)
nameOfFile
Returns filename without path or extension
(STRING) -> PROMISE(STRING)
readDir
Returns a promise for an array of paths for the given directory filepath
(STRING) -> PROMISE([STRING])
fileStats
Returns promise of file stats for the given filename
(STRING) -> PROMISE(fs.Stats)
listFiles
Returns an array of every file in every subdirectory of given directory filtered by optional file extension
(STRING, STRING) -> PROMISE([STRING])
Functional Programming Methods
Method Name
Description
Signature
composeAll
Transforms a list of unary functions into a single unary function
([FUNCTION]) -> FUNCTION
flatten
Returns a single array of elements from an array that may contain other arrays
([[*]]) -> ([*])
assoc
Binds 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
foldObj
Reduces the given object to the given accumulator using the given function
The Tidelift Subscription provides access to a continuously curated stream of human-researched and maintainer-verified data on open source packages and their licenses, releases, vulnerabilities, and development practices.