🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

flexvars

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flexvars

Powerful string interpolation tool library

latest
npmnpm
Version
1.0.9
Version published
Maintainers
1
Created
Source

FlexVars

Powerful string interpolation tool library

WebSite

Features

-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"

const flexvars = new FlexVars({
    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.replace

console.log(_("hello {}","flexvars"))
// => hello flexvars
console.log(_("I am {}","tom")).toBe("I am tom")
// => I am tom
console.log(_("{ value | currency}",100)).toBe("USD $100"))
// => USD $100
console.log(_("{ value | currency('RMB','¥','元')}",100)).toBe("RMB ¥100元"))// 
// => RMB ¥100元
console.log(_("{ value | currency({prefix:'EUR '',suffix:''',sign:'€'})}",100)).toBe("RMB €100"))
// => EUR €100

flexvars.addFilter({
    name:"add",
    args:["step"],
    default:{step:1},
    next(value:any,args:Record<string,any>,context:FlexFilterContext){
        return parseInt(value)+args.step
    }
})
// call chaining
console.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")

FAQs

Package last updated on 16 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts