https://github.com/kyleect/ttk
Template Tool Kit -- String template literals plus.
https://github.com/kyleect/ttk
Last synced: about 1 year ago
JSON representation
Template Tool Kit -- String template literals plus.
- Host: GitHub
- URL: https://github.com/kyleect/ttk
- Owner: kyleect
- License: mit
- Created: 2016-06-10T01:16:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-17T20:39:16.000Z (almost 10 years ago)
- Last Synced: 2025-02-22T06:04:35.020Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/ttk
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/maexsoftware/ttk)
# TTK Template Tool Kit
String template literals plus.
## Installation
```sh
$ npm install --save ttk
```
## Basic Usage
```js
const ttk = require('ttk');
const t = ttk.factory();
const render = t`Hello, ${'@name'}!`;
render({ name: 'World' }); // Hello, World!
```
## Configuration
### keyPrefix [default: @]
String prefix to identify the context value placeholders in the template.
```js
const ttk = require('ttk');
const t = ttk.factory({
keyPrefix: '#'
});
const render = t`Hello, ${'#name'}!`;
render({ name: 'World' }); // Hello, World!
```
### mergeMiddleware [default: false]
Boolean to detirmine if middleware arrays should merge/concat from passed options or override.
### valueFns
Array of middleware functions that context values are processed through.
### renderFns
Array of middleware functions that the final render string is processed through.
## Examples
### SQL Queries with sqlValueWrapper
```js
const ttk = require('ttk');
const sql = ttk.factory({
valueFns: [ttk.middleware.value.sqlValueWrapper]
});
const render = sql`
SELECT firstname, lastname
FROM person
WHERE gender = ${'@gender'}
AND state IN ${'@states'}
AND age > ${'@age'}
`;
render({ age: 30, gender: 'male', states: ['NY', 'CA'] });
// SELECT firstname, lastname
// FROM person
// WHERE gender = 'male'
// AND state IN ('NY', 'CA')
// AND age > 30
```