map.js 767 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var test = require('tape')
  2. var JSONStream = require('../')
  3. test('map function', function (t) {
  4. var actual = []
  5. stream = JSONStream.parse([true], function (e) { return e*10 })
  6. stream.on('data', function (v) { actual.push(v)})
  7. stream.on('end', function () {
  8. t.deepEqual(actual, [10,20,30,40,50,60])
  9. t.end()
  10. })
  11. stream.write(JSON.stringify([1,2,3,4,5,6], null, 2))
  12. stream.end()
  13. })
  14. test('filter function', function (t) {
  15. var actual = []
  16. stream = JSONStream
  17. .parse([true], function (e) { return e%2 ? e : null})
  18. .on('data', function (v) { actual.push(v)})
  19. .on('end', function () {
  20. t.deepEqual(actual, [1,3,5])
  21. t.end()
  22. })
  23. stream.write(JSON.stringify([1,2,3,4,5,6], null, 2))
  24. stream.end()
  25. })