parsejson.js 546 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. sometimes jsonparse changes numbers slightly.
  3. */
  4. var r = Math.random()
  5. , Parser = require('jsonparse')
  6. , p = new Parser()
  7. , assert = require('assert')
  8. , times = 20
  9. , bufferFrom = Buffer.from && Buffer.from !== Uint8Array.from
  10. , str
  11. while (times --) {
  12. assert.equal(JSON.parse(JSON.stringify(r)), r, 'core JSON')
  13. p.onValue = function (v) {
  14. console.error('parsed', v)
  15. assert.equal(v,r)
  16. }
  17. console.error('correct', r)
  18. str = JSON.stringify([r])
  19. p.write (bufferFrom ? Buffer.from(str) : new Buffer(str))
  20. }