Comparing version 1.0.1 to 1.1.0
@@ -6,2 +6,3 @@ /** | ||
var concat = require('lineup-stream') | ||
var through = require('through') | ||
@@ -18,2 +19,7 @@ | ||
module.exports = function(arr, ...args) { | ||
if (typeof arr === 'function') { | ||
return through(function (data) { | ||
concat(arr(data)).on('data', (chunk) => this.emit('data', chunk)) | ||
}) | ||
} | ||
var cp = [] | ||
@@ -23,5 +29,5 @@ arr.map((item, idx) => { | ||
cp.push(item) | ||
if(value) cp.push(value instanceof Array ? concat(...value) : value) | ||
if(value != null) cp.push(value instanceof Array ? concat(...value) : value) | ||
}) | ||
return concat(...cp) | ||
} |
{ | ||
"name": "steroid", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A template engine on steroid.", | ||
@@ -28,4 +28,3 @@ "main": "index.js", | ||
"promises-a": "^2.3.0", | ||
"tape": "^4.6.0", | ||
"through": "^2.3.8" | ||
"tape": "^4.6.0" | ||
}, | ||
@@ -32,0 +31,0 @@ "dependencies": { |
@@ -22,12 +22,18 @@ # Steroid | ||
```javascript | ||
var html = require('steroid') | ||
var country = 'France' | ||
const html = require('steroid') | ||
const http = require('http') | ||
html` | ||
<article> | ||
<h2>Hello ${country}</h2> | ||
${fetch('/api/weather?' + country).then(weather)} | ||
</article> | ||
`.pipe(dest) | ||
http.createServer((req, res) => { | ||
const country = 'France' | ||
// steroid returns a stream | ||
html` | ||
<article> | ||
<h2>Hello ${country}</h2> | ||
${fetch('/api/weather?' + country).then(weather)} | ||
</article> | ||
`.pipe(res) | ||
}).listen(3000) | ||
function weather(forecast) { | ||
@@ -37,8 +43,10 @@ return html` | ||
Weather is ${forecast.result} | ||
<ul>forecast.cities.map(city => { | ||
return html`<li>${city}</li>` | ||
})</ul> | ||
<ul>${forecast.cities.map(city)}</ul> | ||
</div> | ||
` | ||
} | ||
function city(name) { | ||
return html`<li>${name}</li>` | ||
} | ||
``` | ||
@@ -45,0 +53,0 @@ |
@@ -5,2 +5,3 @@ /** | ||
var Readable = require('stream').Readable | ||
var stream = require('..') | ||
@@ -18,3 +19,3 @@ var through = require('through') | ||
test('should substitute simple string', (assert) => { | ||
test('should substitute string', (assert) => { | ||
assert.plan(1) | ||
@@ -26,2 +27,23 @@ var name = 'olivier' | ||
test('should substitute number', (assert) => { | ||
assert.plan(1) | ||
var id = 0 | ||
stream`<button>hello ${id}!</button>` | ||
.pipe(writer( result => assert.equal(result, '<button>hello 0!</button>'))) | ||
}) | ||
test('should substitute boolean', (assert) => { | ||
assert.plan(1) | ||
var bool = true | ||
stream`<button>Is it ${bool}?</button>` | ||
.pipe(writer( result => assert.equal(result, '<button>Is it true?</button>'))) | ||
}) | ||
test('should substitute undefined value with empty strings', (assert) => { | ||
assert.plan(1) | ||
var val = undefined | ||
stream`<button>${val}</button>` | ||
.pipe(writer( result => assert.equal(result, '<button></button>'))) | ||
}) | ||
test('should substitute multiple strings', (assert) => { | ||
@@ -68,3 +90,29 @@ assert.plan(1) | ||
test('should return a duplex stream', assert => { | ||
assert.plan(1) | ||
reader() | ||
.pipe(stream(data => { | ||
return stream`<li>${data}</li>` | ||
})) | ||
.pipe(writer(result => assert.equal(result, '<li>hello</li><li>world</li>'))) | ||
}) | ||
/** | ||
* Create readable stream. | ||
*/ | ||
function reader () { | ||
var readable = new Readable | ||
readable._read = function () {} | ||
readable.push('hello') | ||
setTimeout(function () { | ||
readable.push('world') | ||
readable.push(null) | ||
}, 300) | ||
return readable | ||
} | ||
/** | ||
* Create writable stream. | ||
@@ -71,0 +119,0 @@ */ |
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
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
23406
2
219
97