helper for stc.
npm install stc-helper
import {isFile} from 'stc-helper';
if(isFile('xxx')){
}
check is stream.
import {isStream} from 'stc-helper';
if(isStream(stream){
}
check is buffer.
import {isBuffer} from 'stc-helper';
if(isBuffer(buf){
}
check is array.
check is function.
check is RegExp.
check file/dir is exist.
deep copy
let obj = extend({}, {name: 'stc'})
get files from dir.
import {getFiles} from 'stc-helper';
let files = getFiles('/path/to'); // return is array
make callback function to promise.
import {promisify} from 'stc-helper';
import fs from 'fs'
let fn = promisify(fs.readFile, fs);
fn('/path/to/file', 'utf8').then(content => {
})
get Deferred object.
import {defer} from 'stc-helper';
let fn => {
let deferred = defer();
if(xxx){
deferred.resolve('xxx');
}else{
deferred.reject(new Error());
}
return deferred.promise;
}
get content md5 value.
async content replace
import {asyncReplace} from 'stc-helper';
let fn = async content => {
return asyncReplace(content, /\d+/, (a, b) => {
return Promise.resolve(a);
});
}
check is remote url
isRemoteUrl('http://www.stcjs.org/'); //true
isRemoteUrl('https://www.stcjs.org/'); //true
isRemoteUrl('//www.stcjs.org/'); //true