3.0.2 • Published 2 years ago

@particle/safe-add-prop v3.0.2

Weekly downloads
53
License
UNLICENSED
Repository
-
Last release
2 years ago

@particle/safe-add-prop

safely set and get properties on foriegn objects

Installation

npm install @particle/safe-add-prop --save

API

@particle/safe-add-prop


safeAddProp.setProp(obj, keypath, value) ⇒ object

Add a property to a foreign object without exposing data to other consumers

Kind: static method of @particle/safe-add-prop
Returns: object - The internal object which received your property

ParamTypeDescription
objobjectThe object to modify
keypathstring | arrayThe key path of the property to set
value*The value to set

Example

// basic

const other = require('other').create();
const keypath = 'foo.bar'; // or use an array: `['foo', 'bar'];`
const value = true;
setProp(other, keypath, value);
module.exports = other;

// in middleware

module.exports = (req, res, next) => {
  setProp(req, 'start', Date.now());
  next();
}

safeAddProp.getProp(obj, keypath) ⇒ *

Get a property on a foreign object which you set previously

Kind: static method of @particle/safe-add-prop
Returns: * - The resolved value

ParamTypeDescription
objobjectThe object to query
keypathstring | arrayThe key path of the property to get

Example

const other = require('./my-customized-other');
const keypath = 'foo.bar'; // or use an array: `['foo', 'bar'];`
const value = getProp(other, keypath);

NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago