1.0.5 • Published 4 years ago
@xeerx/node v1.0.5
xNode
xeerx nodeJs helper functions
Install
npm i @xeerx/node
Usage
const xnode = require('@xeerx/node');
Functions
Files
// async
xnode.files.read(path[STRING],mode[STRING]='utf8')
// async
xnode.files.write(path[STRING],data[STRING]='',mode[STRING]='utf8')
// async
xnode.files.info(path[STRING]) // get file stat object
// async
xnode.files.readWithInfo(path[STRING],mode[STRING]='utf8')
// async
xnode.files.watch(path[STRING],callback[FUNCTION])
// async
xnode.files.exists(path[STRING])
// async
xnode.files.isDir(path[STRING]) // check if path is folder
// async
xnode.files.file(path[STRING],data[STRING]='') // create file if not exists
// async
xnode.files.folder(path[STRING]) // create folder if not exists
// async
xnode.files.folders(path[STRING]) // get all folders in path
// async
xnode.files.files(path[STRING]) // get all files in path
// async
xnode.files.tree(path[STRING]) // get files tree in path
Codes
xnode.code.gen(length[INT]=10,input[STRING]='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
xnode.code.num(length[INT]=10,input[STRING]='0123456789')
xnode.code.str(length[INT]=10,input[STRING]='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
xnode.code.ms() // current time as ms
Compress
// async
xnode.compress.gzip(data[STRING],options[OBJECT],mode[STRING]='utf8')
// async
xnode.compress.gunzip(data[GZIP],options[OBJECT])
Parse
xnode.parse.json(data[STRING|OBJECT])
xnode.parse.object(data[JSON STRING])
xnode.parse.url(data[STRING])
xnode.parse.query(data[STRING])
xnode.parse.path(data[STRING])
xnode.parse.hostname(hosts[ARRAY],target[STRING])
xnode.parse.mime(data[STRING])
xnode.parse.multipart(data[STRING],header[STRING])
Workspace
// async
xnode.workspace.init(tree[OBJECT],path[STRING]=root)