@materya/carbon
A collection of useful modules with a no-dependency, clean, tested and lightweight code philosophy.
Install
npm i @materya/carbon
Modules
fs
Module dedicated to explore and manipulate filesystem related operations.
find
up
Search a given file name
in the current directory cwd
and up the tree until it reaches the top. Will throw if no matching file is found.
crawl
list
Crawl from directory
, listing all files sorted until depth
is reached.
/*> list[ 'filename1.ext', 'filename2.ext', 'dir1/filename1.ext', 'dir1/filename2.ext', 'dir1/dir2/filename1.ext',]*/
tree
Crawl from directory
, sorting out files and directories in a tree-like object until depth
is reached.
/*> tree{ files: ['filename.ext', 'filename.ext'], directories: { somedir: { files: ['filename.ext', 'filename.ext'], directories: {}, }, ... },}*/
trigger
Crawl from directory
, triggering action(name: string, path: string)
callback on each file found.
carbon.crawl.triggerprocess.cwd, action
env
Module dedicated to manage process.env
and access environment variables.
get
Get a given name
env variable. Will throw unless a defaultValue
is provided.
tools
Various utility methods to make life easier.
merge
Deep merge together nested arrays or maps.
NOTE: The later sources keys take precedence over the previous same ones if a "conflict" arise.
/*> merged{ animals: { cats: { types: ['lion', 'tiger', 'cheetah'], props: { run: true, eat: true, die: false, fly: false, }, }, cars: ['dodge', 'ford', 'audi', 'bmw'], },}*/