Package Exports
- object-set-all-values-to
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-set-all-values-to) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
object-set-all-values-to
Recursively walk the input and set all found values in plain objects to something
Table of Contents
Install
npm i object-set-all-values-to// consume as a CommonJS require:
const setAllValuesTo = require('object-set-all-values-to')
// or as an ES Module:
import setAllValuesTo from 'object-set-all-values-to'Here's what you'll get:
| Type | Key in package.json |
Path | Size |
|---|---|---|---|
Main export - CommonJS version, transpiled to ES5, contains require and module.exports |
main |
dist/object-set-all-values-to.cjs.js |
2 KB |
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. |
module |
dist/object-set-all-values-to.esm.js |
1 KB |
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in |
browser |
dist/object-set-all-values-to.umd.js |
12 KB |
Purpose
Take any input: nested array, nested plain object or whatever really, no matter how deeply nested. Walk through it recursively and if you find any plain objects, assign all their keys to a given second input's argument OR default, false.
It does not mutate the input arguments. Operations are done on a cloned input.
I needed this library to overwrite all values to be false on JSON schema objects, so that later when I copy from key/value pairs from schema, values are equal to false and I don't need to prep them further.
This library is well-tested and is being used in commercial projects.
Use
const setAllValuesTo = require('object-set-all-values-to')
console.log(setAllValuesTo({a: 'b', c: 'd'}))
// => {a: false, c: false}
console.log(setAllValuesTo({a: 'b', c: 'd'}, 'x'))
// => {a: 'x', c: 'x'}
console.log(setAllValuesTo({a: 'b', c: 'd'}, ['x']))
// => {a: ['x'], c: ['x']}API
setAllValuesTo(input, value)API - Input
| Input argument | Type | Obligatory? | Default | Description |
|---|---|---|---|---|
input |
Whatever | yes | undefined |
AST tree, or object or array or whatever. Can be deeply-nested. Hopefully contains some plain objects. |
value |
Whatever | no | false |
Assign all the found plain object values to this |
API - Output
Same thing that you gave in the first argument, except with values overwritten (where applicable).
Contributing
If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.
If you tried to use this library but it misbehaves, or you need an advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.
If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Code style is
airbnb-base, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.
Licence
MIT License (MIT)
Copyright © 2018 Codsen Ltd, Roy Revelt