JSPM

  • Created
  • Published
  • Downloads 117
  • Score
    100M100P100Q84080F
  • License MIT

Does the AST/nested-plain-object/array/whatever contain only one kind of value?

Package Exports

  • object-all-values-equal-to

Readme

object-all-values-equal-to

Does the AST/nested-plain-object/array/whatever contain only one kind of value?

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:

npm i object-all-values-equal-to

If you need a legacy version which works with require, use version 2.1.0

Quick Take

import { strict as assert } from "assert";
import { allEq } from "object-all-values-equal-to";

// are all values equal to null:
assert.equal(allEq({ a: null, c: null }, null), true);
// yes

// are all values equal to "false":
assert.equal(allEq({ a: false, c: "zzz" }, false), false);
// no

// are all values equal to "false"?
assert.equal(
  allEq(
    {
      a: {
        b: false,
        c: [
          {
            d: false,
            e: false,
          },
          {
            g: false,
          },
        ],
      },
      c: false,
    },
    false // reference value to check
  ),
  true // answer is, yes
);

Documentation

Please visit codsen.com for a full description of the API and examples.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License

Copyright (c) 2010-2021 Roy Revelt and other contributors

ok codsen star