A small collection of date, string and type utilities for Node.js.
npm install eutilconst eutil = require('eutil');dateFormat(date, fmt)- Format a date. 将日期按指定格式输出dateGetNextDay(date, n)- Get date n days later. 获取未来 n 天的日期dateGetBeforeDay(date, n)- Get date n days before. 获取过去 n 天的日期dateAddMilliseconds(date, n)- Add milliseconds. 增加毫秒数dateAddSeconds(date, n)- Add seconds. 增加秒数dateAddMinutes(date, n)- Add minutes. 增加分钟数dateAddHours(date, n)- Add hours. 增加小时数dateAddDays(date, n)- Add days. 增加天数dateAddMonth(date, n)- Add months. 增加月份dateSubMonth(date, n)- Subtract months. 减少月份dateAddYears(date, n)- Add years. 增加年份dateDiff(start, end)- Get difference between two dates. 计算两个日期的差值dateGetGMT()- Current GMT time. 获取 GMT 时间
strSubLeft(str, len)- Substring from left. 从左侧截取指定长度strSubRight(str, len)- Substring from right. 从右侧截取指定长度strReplaceAll(str, search, replace)- Replace all matches. 全局替换文本strReplaceAll2(str, search, replace)- Replace all with regex support. 正则全局替换strPadstr(str, pad, width, right)- Pad string to width. 字符串填充strRemoveCharAt(str, index)- Remove char at index. 删除指定位置字符strVerifyPassword(str)- Validate simple password. 密码格式校验
isArray(value)- Check for Array. 是否为数组isObject(value)- Check for plain object. 是否为对象isString(value)- Check for string. 是否为字符串isNumber(value)- Check for number. 是否为数字isDate(value)- Check for Date. 是否为日期isFunction(value)- Check for function. 是否为函数isBoolean(value)- Check for boolean. 是否为布尔值isMap(value)- Check for Map. 是否为 MapdateFormat(date, fmt)dateGetNextDay(date, n)dateGetBeforeDay(date, n)dateAddMilliseconds(date, n)dateAddSeconds(date, n)dateAddMinutes(date, n)dateAddHours(date, n)dateAddDays(date, n)dateAddMonth(date, n)dateSubMonth(date, n)dateAddYears(date, n)dateDiff(start, end)dateGetGMT()
strSubLeft(str, len)strSubRight(str, len)strReplaceAll(str, search, replace)strReplaceAll2(str, search, replace)strPadstr(str, pad, width, right)strRemoveCharAt(str, index)strVerifyPassword(str)
isArray(value)isObject(value)isString(value)isNumber(value)isDate(value)isFunction(value)isBoolean(value)isMap(value)
const eutil = require('eutil');
console.log(eutil.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss'));
console.log(eutil.strReplaceAll('a-b-c', '-', '#')); For a full list of helpers see index.js.
MIT