You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Supports positional and dictionary interpolation
-Supports multiple error handling mechanisms
-Support for null value processing mechanism
-Support filter chain processing of input variable values
-Support variable prefix suffix
-98%+unit test coverage
Getting Started
import{FlexVars}from"flexvars"constflexvars=newFlexVars({filters:{currency:{args:["prefix","suffix","sign"],default:{prefix:"USD ",suffix:"",sign:"$"}next:(value:any,args:Record<string,any>,context:FlexFilterContext)=>{
return `${args.prefix}${args.sign}${value}${args.suffix}`}}}})const_=flexvars.replaceconsole.log(_("hello {}","flexvars"))// => hello flexvarsconsole.log(_("I am {}","tom")).toBe("I am tom")// => I am tomconsole.log(_("{ value | currency}",100)).toBe("USD $100"))// => USD $100console.log(_("{ value | currency('RMB','¥','元')}",100)).toBe("RMB ¥100元"))//// => RMB ¥100元console.log(_("{ value | currency({prefix:'EUR '',suffix:''',sign:'€'})}",100)).toBe("RMB €100"))// => EUR €100flexvars.addFilter({name:"add",args:["step"],default:{step:1},next(value:any,args:Record<string,any>,context:FlexFilterContext){returnparseInt(value)+args.step}})// call chainingconsole.log(_("{ value | add}",100)).toBe("101")console.log(_("{ value | add|add }",100)).toBe("102")console.log(_("{ value | add(2)|add(3) }",100)).toBe("105")console.log(_("{ value | add(2)|add(3)|add(4) }",100)).toBe("109")