0.0.4 • Published 7 months ago
@dtyq/es6-template-strings v0.0.4
@dtyq/es6-template-strings
ES6 Template Strings Parser Engine
Overview
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.
Usage
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"]Configuration Options
| 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 |
Notes
- 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
Development
To set up the development environment:
- Clone the repository
- Install dependencies:
npm install - Build the package:
npm run build - Run tests:
npm test
Iteration Process
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: 1. Fork the repository 2. Create a feature branch 3. Submit a pull request with detailed description of changes