UNPKG

713 BJavaScriptView Raw
1"use strict";
2
3var environment = require("./environment.js");
4var record = require("./record.js");
5var typify = require("./typify.js");
6var utils = require("./utils.js");
7
8/**
9 ### Arbitrary records
10
11 - `record(spec: { key: arbitrary a... }, userenv: env?): arbitrary { key: a... }`
12
13 Generates a javascript object with given record spec.
14*/
15function recordWithEnv(spec, userenv) {
16 var env = userenv ? utils.merge(environment, userenv) : environment;
17
18 var parsedSpec = {};
19 Object.keys(spec).forEach(function (k) {
20 var arb = spec[k];
21 parsedSpec[k] = typeof arb === "string" ? typify.parseTypify(env, arb) : arb;
22 });
23
24 return record.arbitrary(parsedSpec);
25}
26
27module.exports = recordWithEnv;