hingsir / regular-format

A format tool implemented by regular expression

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regular-formatnpm version

A format tool implemented by regular expression

Install

Install with npm

$ npm install regular-format --save

Usage

require the format module

var format = require('regular-format')
  • printf() c语言printf
format.printf('%% %s %d %f','hingsir',99,1.35)
  • date() 格式化日期
format.date(new Date,'yyyy-MM-dd hh:mm:ss')
  • template() 字符串模版,支持数组
var tpl = 'name\n{{users.0.name}}\n{{users.1.name}}'
var ret = format.template(tpl,{
    users:[
        {name:'hingsir'},{name:'chexingyou'}
    ]
})
console.log(ret)
  • thousands() 数字千分位分隔
format.thousands('12345678.9999');
//=> 12,345,678.999,9
  • bankCard() 银行卡号空格
format.bankCard('6222021********1245');
//=> 6222 021* **** ***1 245
  • mobiblePhone() 11位手机号码格式化
format.mobilePhone('13812345678','-');
//=> 138-1234-5678

License

Copyright © 2015 hingsir Released under the MIT license.

About

A format tool implemented by regular expression

License:MIT License


Languages

Language:JavaScript 100.0%