项目作者: TMWare

项目描述 :
Variable Parser helps you translate in-string variables to preset values.
高级语言: TypeScript
项目地址: git://github.com/TMWare/variable-parser.git
创建时间: 2020-08-25T08:25:41Z
项目社区:https://github.com/TMWare/variable-parser

开源协议:MIT License

下载


Variable Parser

Variable Parser helps you translate in-string variables (i.e. {something} like this, where something would be a variable) to values.

Getting Started

Installation

With npm: npm install --save @tmware/variable-parser

With yarn: yarn add @tmware/variable-parser

Usage

  1. const VariableParser = require('@tmware/variable-parser')
  2. const YourParser = new VariableParser() // initialize without data
  1. const YourParser = new VariableParser({
  2. testVariable: 'World',
  3. anotherOne: 'Hello',
  4. someNumber: 69
  5. })
  6. // initialize with data
  1. console.log(
  2. YourParser.parse(
  3. '{anotherOne} {testVariable}! some text to show you that this works. {someNumber}'
  4. )
  5. )
  6. // => 'Hello World! some text to show you that this works. 69'

More advanced examples

Custom indicators (those things around the variables. default: {})

  1. const YourParser = new VariableParser({ someVariable: 3 }, '[]')
  2. const result = YourParser.parse('[someVariable]')
  3. console.log(result)
  4. // => '3'
  5. // Note: This is still a string

License

Please refer to the LICENSE file.