‘liusuyi’
2023-08-09 161b9318e345c8a0c9cdc133b33a1c759495f323
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
 
var assert = require('assert');
var stream = require('stream');
var hash = require('../index');
 
describe('replacer option', function() {
  it('should emit information about an object to a stream', function() {
    var strm = new stream.PassThrough();
    
    var replacer = function(value) {
      try {
        return JSON.stringify(value);
      } catch (e) {
        return value;
      }
    };
    
    var obj = {foo: 'bar'};
    hash.writeToStream(obj, {replacer: replacer}, strm);
    var result = strm.read().toString();
    assert.strictEqual(typeof result, 'string');
    assert.notStrictEqual(result.indexOf(JSON.stringify(obj)), -1);
  });
 
  it('should not reach property values when excludeValues = true', function() {
    var strm = new stream.PassThrough();
    
    var replacer = function(k) {
      assert.notStrictEqual(k, 'bar');
      return k;
    };
    
    hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
  });
});