Description
Utils for node.js
Normal API
getTimeString(type)
getDay(number)
eg:-1,0,1,2,3...getFileExtension(file)
: Return the extension of the file. The file here can be any string that contains the file name.
type options
getTimeString()
: 2019年03月17日 11:31:18getTimeString('yyyymmdd')
: 20190317getTimeString('yyyy年mm月dd日')
: 2019年03月17日getTimeString('yyyy-mm-dd')
: 2019-03-17getTimeString('yyyy/mm/dd')
: 2019/03/17getTimeString('mmdd')
: 0317getTimeString('mm月dd日')
: 03月17日getTimeString('mm-dd')
: 03-17getTimeString('mm/dd')
: 03/17getTimeString('hh:mm:ss')
: 11:31:18getTimeString('hh时:mm分:ss秒')
: 11时31分18秒
Promise API
rename(old_file, new_file)
copy(from,to)
mkdir_p(folder)
rm_rf(folder)
readFile(file)
readJson(jsonFile)
createFile(file)
writeFile(file,data)
writeJson(file,json_data)
exists(Path)
: The Path here is belong to file-system, which is a bit difference from jsexec_cmd(linux_cmd,cb)
: cb will exec after linux_cmd, note the result of the linux_cmd will not show in screen, so you should make it into a output stream, likeecho hello > a.txt
, ofcourse you can excute bash heregetFileList(options)
:Recive options, data structure liike{folder:"",skip:[],ext:[]}
, return a obj like{files:[...],dirs:[...]}
example
getTimeString(type)
const getTimeString = ;
mkdir(dir)
const mkdir = ;
exists(filePath)
exec_cmd(linx_cmd)
getFileList(options)
options<Object>
- folder: The path of the folder
- skip: The folder you want to skip, it must be an Array
- ext: Filter the extension, it must be an Array
example:
const options= folder: path skip:'node_modules/slimz''node_modules/fs-extra' ext:'md' //also you can do like this:const getFileList = { const options = folder:"/Volumes/datavolumn_bmkserver_Pub/新做稿" skip:'摄影' ext:'xls''xlsx' let files = await console}