UNPKG

numvert

Version:

数字转换插件

39 lines (33 loc) 980 B
'use strict'; var numeral = require('numeral'); numeral.register('format', 'abbr', { regexps: { format: /r/ }, format: function format(value, _format, roundingFunction) { var space = numeral._.includes(_format, ' r') ? ' ' : ''; var abbreviations = ''; if (value > 100000000) { value = value / 100000000; abbreviations = '亿'; } else if (value > 10000) { value = value / 10000; abbreviations = '万'; } _format = _format.replace(/\s?r/, ''); var output = numeral._.numberToFormat(value, _format, roundingFunction); return '' + output + space + abbreviations; } }); numeral.register('format', 'cent', { regexps: { format: /cent/ }, format: function format(value, _format2, roundingFunction) { value = value / 100; _format2 = _format2.replace(/\s?cent/, ''); var output = numeral._.numberToFormat(value, _format2, roundingFunction); return output; } }); module.exports = numeral;