ES6 Template Strings Parser Engine
This package provides a template string parsing engine that supports ES6-style syntax. It allows you to interpolate variables and expressions within strings using the ${expression}
syntax.
import { resolveToString, resolveToArray } from "@dtyq/es6-template-strings";
// Basic usage
console.log(resolveToString("hello ${name}", { name: "world" }));
// Output: "hello world"
// Return array of template parts and substitutions
console.log(resolveToArray("hello ${name}", { name: "world" }));
// Output: ["hello ", "world"]
Option | Description | Type | Default | Required |
---|---|---|---|---|
notation | Template syntax prefix | string | "$" | No |
notationStart | Template syntax start marker | string | "{" | No |
notationEnd | Template syntax end marker | string | "}" | No |
partial | Skip failed expressions instead of returning undefined | boolean | false | No |
- When an expression cannot be resolved:
- If
partial: true
, the original${expression}
string will be preserved - If
partial: false
(default), undefined will be returned for that expression
- If
- The package handles nested expressions and escape sequences properly
To set up the development environment:
- Clone the repository
- Install dependencies:
npm install
- Build the package:
npm run build
- Run tests:
npm test
The package follows semantic versioning:
- Bug fixes result in patch version increments
- New features that maintain backward compatibility result in minor version increments
- Breaking changes result in major version increments
For contributing:
- Fork the repository
- Create a feature branch
- Submit a pull request with detailed description of changes