增加formaterVarsRegexp
This commit is contained in:
parent
139e2e2282
commit
95a2b4b29f
@ -156,10 +156,10 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
currency : {
|
||||
units : ["Thousands","Millions","Billions","Trillions"], //千,百万,十亿,万亿
|
||||
default : "{symbol}{value}",
|
||||
long : "{prefix} {symbol}{value}{suffix}",
|
||||
short : "{symbol}{value}",
|
||||
units : ["","Thousands","Millions","Billions","Trillions"], //千,百万,十亿,万亿
|
||||
default : "{symbol}{value}{unit}",
|
||||
long : "{prefix} {symbol}{value}{unit}{suffix}",
|
||||
short : "{symbol}{value}{unit}",
|
||||
symbol : "$", // 符号
|
||||
prefix : "", // 前缀
|
||||
suffix : "", // 后缀
|
||||
|
@ -17,6 +17,9 @@ let varWithPipeRegexp = /\{\s*(?<varname>\w+)?(?<formatters>(\s*\|\s*\w*(\(.*\))
|
||||
|
||||
let varReplaceRegexp =String.raw`\{\s*{varname}\s*\}`
|
||||
|
||||
// 提取匹配("a",1,2,'b',{..},[...])
|
||||
let formaterVarsRegexp = String.raw`((([\'\"])(.*?)\3)|(\w)|(\{.*?\})|(\[.*?\])),?`
|
||||
|
||||
/**
|
||||
* 考虑到通过正则表达式进行插件的替换可能较慢,因此提供一个简单方法来过滤掉那些
|
||||
* 不需要进行插值处理的字符串
|
||||
@ -64,6 +67,7 @@ function parseFormatters(formatters){
|
||||
let lastIndex = formatter.lastIndexOf(")")
|
||||
if(firstIndex!==-1 && lastIndex!==-1){ // 带参数的格式化器
|
||||
const argsContent = formatter.substr(firstIndex+1,lastIndex-firstIndex-1).trim()
|
||||
// 此处采用,分割参数,存在的问题,如果参数里面存在,会导致分解析参数错误,TODO: 采用正则表达式进行解析
|
||||
let args = argsContent=="" ? [] : argsContent.split(",").map(arg=>{
|
||||
arg = arg.trim()
|
||||
if(isNumber(arg)){ // 数字
|
||||
|
@ -216,9 +216,11 @@ const expectEnDatetimes =[
|
||||
|
||||
const MONEY = 123456789.8848
|
||||
const zhMoneys = [
|
||||
"商品价格: { value | currency }", // 默认格式,由语言配置指定,不同的语言不一样
|
||||
"商品价格: { value | currency }", // 默认格式
|
||||
"商品价格: { value | currency('long')}", // 长格式
|
||||
"商品价格: { value | currency('short')}", // 短格式 == short(0)
|
||||
"商品价格: { value | currency('short')}", // 短格式
|
||||
"商品价格: { value | currency('unit',0)}", // 短格式
|
||||
|
||||
"商品价格: { value | currency('long',1)}", // 长格式: 万元
|
||||
"商品价格: { value | currency('long',2)}", // 长格式: 亿
|
||||
"商品价格: { value | currency('long',3)}", // 长格式: 万亿
|
||||
|
Loading…
x
Reference in New Issue
Block a user