JSPM

  • Created
  • Published
  • Downloads 48
  • Score
    100M100P100Q102393F
  • License MIT

Recursively walk the input and set all found values in plain objects to something

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

Standard JavaScript

Recursively walk the input and set all found values in plain objects to something

Build Status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies Coverage Status Downloads/Month

Table of Contents

Install

$ npm install --save object-set-all-values-to

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.

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

var 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 found plain object values to this

Testing

$ npm test

For unit tests we use AVA, Istanbul CLI and JS Standard notation.

Contributing

All contributions are welcome. Please stick to Standard JavaScript notation and supplement the test.js with new unit tests covering your feature(s).

If you see anything incorrect whatsoever, do raise an issue. If you file a pull request, I'll do my best to help you to get it merged in a timely manner. If you have any comments on the code, including ideas how to improve things, don't hesitate to contact me by email.

Licence

MIT License (MIT)

Copyright (c) 2017 Codsen Ltd, Roy Reveltas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.