All Projects → hustcc → tplv

hustcc / tplv

Licence: MIT license
👣 Nano string template library for modern, based on ES6 template string syntax.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
Smarty
1635 projects

Projects that are alternatives of or similar to tplv

Mightystring
Making Ruby Strings Powerful
Stars: ✭ 28 (-9.68%)
Mutual labels:  string, strings
StringPool
A performant and memory efficient storage for immutable strings with C++17. Supports all standard char types: char, wchar_t, char16_t, char32_t and C++20's char8_t.
Stars: ✭ 19 (-38.71%)
Mutual labels:  string, strings
Util
A collection of useful utility functions
Stars: ✭ 201 (+548.39%)
Mutual labels:  string, strings
indexed-string-variation
Experimental JavaScript module to generate all possible variations of strings over an alphabet using an n-ary virtual tree
Stars: ✭ 16 (-48.39%)
Mutual labels:  string, strings
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (+12.9%)
Mutual labels:  string, strings
Golang Combinations
Golang library which provide an algorithm to generate all combinations out of a given string array.
Stars: ✭ 51 (+64.52%)
Mutual labels:  string, strings
Stringsimilarity.net
A .NET port of java-string-similarity
Stars: ✭ 242 (+680.65%)
Mutual labels:  string, strings
fuzzywuzzyR
fuzzy string matching in R
Stars: ✭ 32 (+3.23%)
Mutual labels:  string
PSStringScanner
Provides lexical scanning operations on a String
Stars: ✭ 45 (+45.16%)
Mutual labels:  string
Stringfication
🔨 Make all objects to String!
Stars: ✭ 33 (+6.45%)
Mutual labels:  string
unescape-js
Unescape special characters encoded by JavaScript escape sequences
Stars: ✭ 36 (+16.13%)
Mutual labels:  string
split-on-first
Split a string on the first occurrence of a given separator
Stars: ✭ 68 (+119.35%)
Mutual labels:  string
normalize-text
📝 Provides a simple API to normalize texts, whitespaces, paragraphs & diacritics.
Stars: ✭ 54 (+74.19%)
Mutual labels:  string
str
str is a string module with useful methods that don't exist in Lua's core
Stars: ✭ 30 (-3.23%)
Mutual labels:  string
couplet
Unicode code points support for Clojure
Stars: ✭ 21 (-32.26%)
Mutual labels:  string
Data-Structures-Algorithms-Handbook
A series of important questions with solutions to crack the coding interview and ace it!
Stars: ✭ 30 (-3.23%)
Mutual labels:  strings
Prestyler
Elegant text formatting tool in Swift 🔥
Stars: ✭ 36 (+16.13%)
Mutual labels:  string
myleetcode
♨️ Detailed Java & Python solution of LeetCode.
Stars: ✭ 34 (+9.68%)
Mutual labels:  string
Regular Expressions
🔍 Swirl course on regular expressions and the regex family of functions in R
Stars: ✭ 21 (-32.26%)
Mutual labels:  strings
InterviewBit
Collection of solution for problems on InterviewBit
Stars: ✭ 77 (+148.39%)
Mutual labels:  strings

TPLV

Nano(~170 bytes), High performance string template library, based on ES6 String template syntax.

npm Version Build Status Coverage Status npm License

Install

$ npm i --save tplv

Usage

  • render template string
import { render } from 'tplv';

const template = '${ name }, ${value}(${percent} | Top ${array[2]})';

const data = {
  name: 'Hangzhou',
  value: 1200,
  percent: '13%',
  array: [1, 2, 3, 4]
};

render(template, data); // `Hangzhou, 1200(13% | Top 3)` will be got
  • compile mode

For 13x faster performance then render mode.

import { compile } from 'tplv';

const template = '${ name }, ${value}(${percent} | Top ${array[2]})';

const data = {
  name: 'Hangzhou',
  value: 1200,
  percent: '13%',
  array: [1, 2, 3, 4]
};

const fn = compile(template, ['name', 'value', 'percent', 'array']);

fn(data); // `Hangzhou, 1200(13% | Top 3)` will be got

Perf

Run performance test with rendering-test.

perf test

Principle

The core code and principles are as follows:

function render(template, data) {
  const ks = Object.keys(data);
  const vs = ks.map((k) => data[k]);

  const t = `return \`${template}\``;
  const f = new Function(...ks, t);

  return f(...vs);
}

Dev

# install dependence
$ npm install

# run test cases
$ npm run test

# run performance for render / compile mode
$ npm run perf

# build package
$ npm run build

License

MIT@hustcc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].