Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→object-all-values-equal-tonext

object-all-values-equal-to4.2.0

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

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • API — ALLEQ()
  • API — DEFAULTS
  • API — VERSION
  • OPTS — ARRAYSMUSTNO…
  • WHY WE NEED…
  • Changelog

Installation

Quick Take

Examples

  • Arrays containing the placeholder itself
  • Empty containers
  • Return false when one value differs from the reference
  • Check the values in nested objects and arrays

API — allEq()

The main function allEq() is imported like this:

It’s a function which takes three input arguments:

Input argumentTypeObligatoryDescription
input
Type: Any JSON-friendly data type
Obligatory: yes
inputAny JSON-friendly data typeyesInput data structure.
value
Type: Any JSON-friendly data type
Obligatory: yes
valueAny JSON-friendly data typeyesThe program checks, does input contain only value on every key.
opts
Type: Plain object
Obligatory: no
optsPlain objectnoOptional Options Object.

The Optional Options Object has the following shape:

KeyTypeDefaultDescription
arraysMustNotContainPlaceholders
Type: Boolean
Default: true
arraysMustNotContainPlaceholdersBooleantrueWhen set to true, value within array should not be present and will yield false result. Set this to false to allow one or more value’s within arrays in the input.

Here are all defaults in one place for copying:

The function will return a boolean.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

opts.arraysMustNotContainPlaceholders

When working with data structures, this library would be used to check, is the certain piece of JSON data (some key’s value, a nested object) is all blank, that is, contains only placeholders everywhere.

Now, with regards to arrays, default arrays should not contain placeholders directly. For example key b is customised, it’s not a placeholder:

{
  "a": false,
  "b": [false]
}

It should be instead:

{
  "a": false,
  "b": []
}

When checking against second argument false, this library will yield false for former and true for latter.

Now, this is relevant only when working with data structures. When dealing with all other kinds of nested objects and arrays, placeholders within arrays count as placeholders and should yield true.

For that, turn off the opts.arraysMustNotContainPlaceholders, set it to false.

Observe:

let res1 = allValuesEqualTo([null], null);
console.log(res1);
// => false

let res2 = allValuesEqualTo([null], null, {
  arraysMustNotContainPlaceholders: false,
});
console.log(res2);
// => true

Why we need this

For example, we were working on object-fill-missing-keys. The library takes an object, a reference object, and fills in missing keys according to the reference. We were implementing a feature, a options switch, which let to skip filling for chosen keys if they currently contain only placeholders.

You’ll need this library when you want to check, does the AST contain only certain value throughout the whole tree. Also, it can be a simple object, in which case you’d be checking, are all values of all keys equal to something.

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab