util collect
-
-
promisify fs
-
let fs = require('fs'); bluebird.promisifyAll('fs');
-
util.fs.readFileAsync(path.resolve(__diranme, './')).then(content => { // => file content }).catch(err => { // => readFile error })
-
-
-
str(Any): string ready to parse -
(Object | String): if str is a JSON,return Object,else return itself -
util.parse.json(`{"a":1}`); // => { a: 1 } util.parse.json('normal string'); // => normal string
-
-
-
num(Any): value ready to parsedefault(Number): if parse fail,return default value, default to 0 -
(Number=0): if parse fail,return default value, default to 0 -
util.parse.number('1'); // => 1 util.parse.number('normal string', 10); // => 10 util.parse.number('normal string'); // => 0
-
-
-
url(String): url string ready to parseprotocol='http'(String):url protocol -
(String): parse url with protocol -
util.parse.url('127.0.0.1'); // => 'http://127.0.0.1' util.parse.url('http://127.0.0.1'); // => 'http://127.0.0.1' util.parse.url('127.0.0.1:6379', 'redis'); // => 'redis://127.0.0.1:6379'
-