Comparing version 1.1.5 to 1.1.6
{ | ||
"name": "ez-string", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "A string template renderer for JavaScript without memory leaks.", | ||
"main": "index.js", | ||
"main": "ez-string.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"esdoc": "esdoc -c ./esdoc.json", | ||
"eslint-fix": "eslint --config=./config/eslint.config.json --fix src/**/*.js test/**/*.js gulpfile.js", | ||
"eslint-watch": "esw --config=./config/eslint.config.json -w --fix src/**/*.js test/**/*.js gulpfile.js", | ||
"generate": "node ./src/private/generator.js", | ||
"test-watch": "cross-env TEST_MODE=DEV mocha --reporter spec -w --recursive test/specs/*.spec.js", | ||
"dev-test": "cross-env TEST_MODE=DEV nyc --reporter=html --reporter=text --report-dir=./build/coverage --check-coverage --lines 100 --functions 100 --branches 100 mocha --reporter spec test/specs/*.spec.js", | ||
"gen-test": "cross-env TEST_MODE=GEN nyc --reporter=html --reporter=text --report-dir=./build/generated-coverage mocha --reporter spec test/specs/*.spec.js", | ||
"test": "cross-env TEST_MODE=DEV nyc --reporter=html --reporter=text --report-dir=./build/coverage mocha --reporter spec test/specs/*.spec.js", | ||
"prod-test": "nyc --reporter=html --reporter=text --report-dir=./build/postbuild-coverage mocha --reporter spec test/specs/*.spec.js", | ||
"web-test": "mocha --reporter spec test/browser/*.spec.js", | ||
"webpack": "webpack --config ./config/webpack.config.js" | ||
}, | ||
@@ -26,3 +36,21 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/Kirusi/ez-string#readme" | ||
"homepage": "https://github.com/Kirusi/ez-string#readme", | ||
"devDependencies": { | ||
"coveralls": "^3.0.0", | ||
"cross-env": "^5.2.0", | ||
"esdoc": "^1.0.4", | ||
"esdoc-node": "^1.0.2", | ||
"esdoc-standard-plugin": "^1.0.0", | ||
"eslint": "^4.18.2", | ||
"eslint-watch": "^3.1.3", | ||
"gulp": "^4.0.0", | ||
"gulp-util": "^3.0.8", | ||
"jison": "^0.4.18", | ||
"mocha": "^4.1.0", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"nyc": "^11.4.1", | ||
"selenium-webdriver": "^4.0.0-alpha.1", | ||
"should": "^13.1.3", | ||
"webpack": "^3.10.0" | ||
} | ||
} |
104
README.md
# ez-string | ||
A string template renderer for JavaScript without memory leaks. | ||
[![Travis build status badge](https://api.travis-ci.org/Kirusi/ez-string.svg?branch=master)](https://travis-ci.org/Kirusi/ez-string) | ||
[![ESDoc coverage badge](https://doc.esdoc.org/github.com/Kirusi/ez-string/badge.svg)](https://doc.esdoc.org/github.com/Kirusi/ez-string/) | ||
A string template renderer for JavaScript without memory leaks. It supports referencing variables by position, by name. One can access properties and array elements. | ||
## Example | ||
```js | ||
const render = require('ez-string'); | ||
let book; | ||
// Format using variable's position | ||
book = render('One of my favorite books is "{0}" by {1}.', 'The Name of the Wind', 'Patrick Rothfuss'); | ||
// book = 'One of my favorite books is "The Name of the Wind" by Patrick Rothfuss.' | ||
// Format using variable's name | ||
// Variable names must use A-Za-z0-9$_ | ||
book = render('One of my favorite books is "{title}" by {author}.', | ||
{ title: 'The Name of the Wind', author: 'Patrick Rothfuss'}); | ||
// book = 'One of my favorite books is "The Name of the Wind" by Patrick Rothfuss.' | ||
// Curly braces are escaped by using double braces | ||
let example; | ||
example = render('{{title}}'); | ||
// example = '{title}' | ||
// One can use array indices | ||
book = render('"{arr[0]}" was first published in {arr[1]}.', | ||
{ arr: ['The Hobbit', 1937]}); | ||
// book = '"The Hobbit" was first published in 1937.' | ||
// One can use object properties. | ||
// Properties with names consisting of A-Za-z0-9$_ can be accessed using property notation | ||
// Properties with other names can be accessed using index notation | ||
book = render('"{book.title}" was written by {book.author["first name"]} {book.author["last name"]}. It was published in {book.year}.', { | ||
book: { | ||
title: 'Marina', | ||
year : 1999, | ||
author: { | ||
'first name': 'Carlos', | ||
'last name': 'Zafon' | ||
} | ||
} | ||
}); | ||
// book = '"Marina" was written by Carlos Zafon. It was published in 1999.' | ||
// If a property name contains a quote character or backslash, they need to be escaped. | ||
// Quotes are prepended by a backslash | ||
// Backslashes need to be doubled | ||
example = render('{data["\\\\"]}', { | ||
data: {'\\': 'backslash'} | ||
}); | ||
// example = 'backslash' | ||
example = render('{data["\\""]}', { | ||
data: {'"': 'quote'} | ||
}); | ||
// example = 'quote' | ||
``` | ||
## Installation | ||
Using NodeJS: | ||
```shell | ||
$ npm i --save ez-string | ||
``` | ||
```js | ||
const render = require('ez-string'); | ||
let book; | ||
// Format using variable's position | ||
book = render('One of the best books by {author} is "{title}".', { | ||
author: 'Stephen King', | ||
title: '11/22/63' | ||
}); | ||
// book = 'One of the best books by Stephen King is "11/22/63".' | ||
``` | ||
In a browser: | ||
```html | ||
<!-- Load library which is UMD packed --> | ||
<script src="ez-string.js"></script> | ||
<script> | ||
const render = require('ez-string'); | ||
let book; | ||
// Format using variable's position | ||
book = render('One of the best books by {author} is "{title}".', { | ||
author: 'Stephen King', | ||
title: '11/22/63' | ||
}); | ||
// book = 'One of the best books by Stephen King is "11/22/63".' | ||
</script> | ||
``` | ||
## Why ez-string | ||
The most important reason is that this library doesn't leak memory. | ||
Many of the existing template renderers perform a two-step process. They compile a string template into a JavaScript function and then execute it while passing context data. However, most users of such libraries rarely cache the resulting compiled function. Instead they may compile the same template again and again. Due to inticacies of NodeJS memory garbage collection. Such pattern usually results in a memory leak, as described by [Meteor developers.](https://blog.meteor.com/an-interesting-kind-of-javascript-memory-leak-8b47d2e7f156) | ||
Library documentation is [here.](https://kirusi.github.io/ez-string/) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
420624
54
10879
0
105
16
1
8
2