zhike-util
public function library for zhike
INSTALL
npm install zhike-util
API
md5(s)
Hash a string with md5
Params
- s(String): string before md5
Usage
var util = ;util; // 5d41402abc4b2a76b9719d911017c592
randString(length)
Generate a specified length string randomly
Params
- length(Number): length of string
Usage
var util = ;util; // B2UT7Z3E
getFields(data, fields, notSetNull)
Extract fields which contains by data
Params
- data(Object): object which is extracted
- fields(Array): array of keys
- notSetNull(Boolean, default: false): fields not contained by object should set null or not
Usage
var util = ;var data = id: 1 name: 'fengliner' sex: 'male';var fields = 'id' 'name' 'age';util; // {id: 1, name: 'fengliner', age: ''}util; // {id: 1, name: 'fengliner', age: undefined}
toCamel(name)
Convert underlined or middlelined string to camel
Params
- name(String)
Usage
var util = ;var name = 'love_is-love';util; // loveIsLove
getIp(req)
Get ip address from the request header
Params
- req(Object)
Usage
var util = ;var app = ;app
getIPInfo(ip)
Get location from ip
Params
- ip(String)
Usage
let util = ; util util
dateFormat(fmt, d)
Format a specified date
Params
- fmt(String): date format, example: yyyyMMddHHmmss
- d(date): date
Usage
var util = ;var date = ;util; // 20161114105537util; // 2016-11-14 10:55:37
request(options, callback)
Thunkify request which could be used by yield directly
Params
- options(Object): any options supported by request,
method
defaultGET
andjson
defaulttrue
Usage
var util = ;var co = ;
TEST
npm run test