possible-objects

given a simple Object schema, return all possible Objects

Usage no npm install needed!

<script type="module">
  import possibleObjects from 'https://cdn.skypack.dev/possible-objects';
</script>

README

var possible = require('possible-objects')

The package exports a single function. That function takes a single argument: An Object schema whose property values are all Arrays of possible object property values.

The function returns an Array of all the Objects whose properties have values permitted by the schema.

var assert = require('assert')
assert.deepEqual(
  possible({
      a: [1, 2],
      b: [3, 4] }),
  [ { a: 1, b: 3 },
    { a: 1, b: 4 },
    { a: 2, b: 3 },
    { a: 2, b: 4 } ])