https://github.com/hendrysadrak/crouch
Micro template filler for only filling in the values and nooooooooo logic 🖖
https://github.com/hendrysadrak/crouch
Last synced: 4 months ago
JSON representation
Micro template filler for only filling in the values and nooooooooo logic 🖖
- Host: GitHub
- URL: https://github.com/hendrysadrak/crouch
- Owner: hendrysadrak
- License: mit
- Created: 2016-08-30T09:05:13.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-08T14:10:43.000Z (about 7 years ago)
- Last Synced: 2025-02-23T12:51:45.478Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 71.3 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# crouch
[](https://nodei.co/npm/crouch/)
Crouch is a micro JS template engine. I created this because I had a need for supersmall and lightweight module which would replace some strings inside templates. Templates were as strings like `Hello, my name is {name}. I'm from {city}.` or as HTML like `
{paragraphContent}
`.So I created `crouch`. It can replace placeholders formated as `{number|string}` in example `{0}` `{1}` `{hello}` `{World}`.
## Installation
The module is intended to be used in browsers as well as in Node.js
Using npm:
```
npm install --save crouch
```In browser get the code https://github.com/hendrysadrak/crouch/tree/master/dist or:
```html```
## Try
You can try crouch in action [here on Tonicdev](https://tonicdev.com/hendrysadrak/crouch-example-01)
[Using Crouch with html templates](https://tonicdev.com/hendrysadrak/crouch-example-2)
## Usage
```javascript
'use strict';var crouch = require('crouch');
// or if es6
import crouch from 'crouch';
```Using values as array:
```javascript
var
template = 'Hello, my name is {0}. I\'m from {1}.',
values = [ 'James', 'Chicago' ];var output = crouch( template, values );
console.log( output );
// Hello, my name is James. I'm from Chicago.
```Using values as object:
```javascript
var
template = 'Hello, my name is {name}. I\'m from {city}.',
values = { name: 'James', city: 'Chicago' };var output = crouch( template, values );
console.log( output );
// Hello, my name is James. I'm from Chicago.
```## Developing
```bash
npm i
npm run build
```## Todo
* Add support for getter/setter functions
* Add support for loops
* Add support for if/elseif/else## License
[MIT](LICENSE)