@particle/safe-add-prop

3.0.2 • Public • Published

@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

Param Type Description
obj object The object to modify
keypath string | array The 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

Param Type Description
obj object The object to query
keypath string | array The 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

Readme

Keywords

none

Package Sidebar

Install

npm i @particle/safe-add-prop

Weekly Downloads

252

Version

3.0.2

License

UNLICENSED

Unpacked Size

6.33 kB

Total Files

4

Last publish

Collaborators

  • jackson-particle
  • mike.grundy.npm
  • mohitparticle
  • eugene_particle
  • kmok23
  • karlag
  • cole-abbeduto-particle
  • pedrosordo
  • guohui
  • sbrust
  • particlebot
  • no1089
  • carlos.hdez
  • keeramis5
  • monkbroc
  • suda
  • mstan
  • sergeuz
  • debbie23
  • avtolstoy
  • mlauer
  • wraithan
  • azenk
  • bwalach
  • parteberseth
  • rickkas7
  • mrlambchop_particle
  • hugo.montero
  • mphsi