├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | tmp/ 4 | npm-debug.log* 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - "0.12" 3 | - "4" 4 | sudo: false 5 | language: node_js 6 | script: "npm run test:cov" 7 | after_script: "npm i -g codecov.io && cat ./coverage/lcov.info | codecov" 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Yoshua Wuyts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # maxstache-stream 2 | [![NPM version][npm-image]][npm-url] 3 | [![build status][travis-image]][travis-url] 4 | [![Test coverage][codecov-image]][codecov-url] 5 | [![Downloads][downloads-image]][downloads-url] 6 | [![js-standard-style][standard-image]][standard-url] 7 | 8 | [maxstache][0] transform stream. Faster and simpler than `{mu,min}stache`. 9 | 10 | ## Installation 11 | ```sh 12 | $ npm install maxstache-stream 13 | ``` 14 | 15 | ## Usage 16 | ```js 17 | const maxstache = require('maxstache-stream') 18 | const fs = require('fs') 19 | 20 | fs.createReadStream('./foobar.txt') 21 | .pipe(maxstache({ name: 'jjjohnny', occupation: 'wizard' })) 22 | .pipe(process.stdout) 23 | ``` 24 | 25 | ## API 26 | ### transformStream = maxstache(vars) 27 | Create a maxstache transform stream that injects an object of variables. Uses 28 | the `{{varName}}` syntax to mark variables in templates. 29 | 30 | ## See Also 31 | - [maxstache][0] 32 | 33 | ## License 34 | [MIT](https://tldrlegal.com/license/mit-license) 35 | 36 | [npm-image]: https://img.shields.io/npm/v/maxstache-stream.svg?style=flat-square 37 | [npm-url]: https://npmjs.org/package/maxstache-stream 38 | [travis-image]: https://img.shields.io/travis/yoshuawuyts/maxstache-stream/master.svg?style=flat-square 39 | [travis-url]: https://travis-ci.org/yoshuawuyts/maxstache-stream 40 | [codecov-image]: https://img.shields.io/codecov/c/github/yoshuawuyts/maxstache-stream/master.svg?style=flat-square 41 | [codecov-url]: https://codecov.io/github/yoshuawuyts/maxstache-stream 42 | [downloads-image]: http://img.shields.io/npm/dm/maxstache-stream.svg?style=flat-square 43 | [downloads-url]: https://npmjs.org/package/maxstache-stream 44 | [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 45 | [standard-url]: https://github.com/feross/standard 46 | 47 | [0]: https://github.com/yoshuawuyts/maxstache 48 | [1]: https://github.com/yoshuawuyts/maxstache-stream 49 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const maxstache = require('maxstache') 2 | const through = require('through2') 3 | const assert = require('assert') 4 | const split = require('split2') 5 | const pump = require('pump') 6 | 7 | module.exports = maxstacheStream 8 | 9 | // split by newline and parse 10 | // obj? -> stream 11 | function maxstacheStream (args) { 12 | args = args || {} 13 | assert.equal(typeof args, 'object') 14 | return pump(split(), parse(args)) 15 | } 16 | 17 | // Maxstache transform stream 18 | // obj? -> stream 19 | function parse (args) { 20 | return through(function (chunk, enc, cb) { 21 | const str = String(chunk) 22 | cb(null, maxstache(str, args)) 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "maxstache-stream", 3 | "version": "1.0.4", 4 | "description": "Maxstache transform stream", 5 | "main": "index.js", 6 | "scripts": { 7 | "deps": "dependency-check . && dependency-check . --extra --no-dev", 8 | "test": "standard && npm run deps && NODE_ENV=test node test", 9 | "test:cov": "standard && npm run deps && NODE_ENV=test istanbul cover test.js" 10 | }, 11 | "repository": "yoshuawuyts/maxstache-stream", 12 | "keywords": [ 13 | "maxstache", 14 | "variable", 15 | "stream", 16 | "inject", 17 | "template" 18 | ], 19 | "license": "MIT", 20 | "dependencies": { 21 | "maxstache": "^1.0.0", 22 | "pump": "^1.0.0", 23 | "split2": "^1.0.0", 24 | "through2": "^2.0.0" 25 | }, 26 | "devDependencies": { 27 | "concat-stream": "^1.5.0", 28 | "dependency-check": "^2.5.1", 29 | "from2-string": "^1.1.0", 30 | "istanbul": "^0.3.21", 31 | "standard": "^5.0.0", 32 | "tape": "^4.2.0" 33 | }, 34 | "files": [ 35 | "index.js", 36 | "bin/*" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const fromString = require('from2-string') 2 | const concat = require('concat-stream') 3 | const test = require('tape') 4 | 5 | const maxstache = require('./') 6 | 7 | test('should assert input types', function (t) { 8 | t.plan(1) 9 | t.throws(maxstache.bind(null, 'foo')) 10 | }) 11 | 12 | test('should transform a bunch of text', function (t) { 13 | t.plan(1) 14 | const template = [ 15 | 'hello {{name}}', 16 | 'how is your {{person}}' 17 | ].join('\n') 18 | 19 | fromString(template) 20 | .pipe(maxstache({ name: 'foo', person: 'bar' })) 21 | .pipe(concat(sink)) 22 | 23 | function sink (str) { 24 | str = String(str) 25 | const comp = [ 26 | 'hello foo', 27 | 'how is your bar' 28 | ].join('\n') 29 | t.equal(str, comp) 30 | } 31 | }) 32 | 33 | test('should pipe through a bunch of text', function (t) { 34 | t.plan(1) 35 | const template = [ 36 | 'hello beep', 37 | 'how is your boop' 38 | ].join('\n') 39 | 40 | fromString(template) 41 | .pipe(maxstache()) 42 | .pipe(concat(sink)) 43 | 44 | function sink (str) { 45 | str = String(str) 46 | const comp = [ 47 | 'hello beep', 48 | 'how is your boop' 49 | ].join('\n') 50 | t.equal(str, comp) 51 | } 52 | }) 53 | --------------------------------------------------------------------------------