summaryrefslogtreecommitdiff
path: root/bin/fuzz-functions.js
blob: 26a079d6d8507594826880d90d1c0e19561d2b91 (plain)
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
#!/usr/bin/env node
'use strict';

var through = require('through2');
var fuzzer = require('fuzzer');
fuzzer.seed(0);

module.exports = function() {
  return through.obj(function(chunk, env, callback) {
    var json = JSON.parse(chunk.toString());

    json.constants = Object.keys(json.constants).reduce(function(obj, key, index) {
      var value = json.constants[key];
      if (typeof value === 'object' && value.hasOwnProperty('fn')) {
        var mutator = fuzzer.mutate.object(value);
        obj[key] = mutator();
      }
      return obj;
    }, {});

    var data = JSON.stringify(json);
    this.push(data);
    callback();
  });
};

if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout);