o.set
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

o.set

fast { property: 'setter' }

How fast is it

Well, I didn't do any extensive testing on all available browsers, but since it uses only builtin functions it should be quite fast. According to this little benchmark it is currently faster than lodash.set on the current LTS version of node.js.

What this is not

This will never be some kind of "wannabe" lodash killer library. It's just what you see - a simple object property setter.

Usage

import oset from 'o.set';

const obj = {
  uno: 1,
  due: {
    a: ['abracadabra'],
    b: [ [ [ 'wow' ] ] ]
  },
  tre: 3
};

oset(obj, 'due.a.0', 'yay'); // obj.due.a = [ 'yay' ]
oset(obj, 'due.a.1', 'horray'); // obj.due.a = [ 'yay', 'horray' ]

oset(obj, 'due.b[0][0][0]', 'super'); // obj.due.b = [ [ [ 'super' ] ] ]
oset(obj, 'due.b[0][0][1]', 'cool'); // obj.due.b = [ [ [ 'super', 'cool' ] ] ]

oset(obj, 'uno.na.not.existent', 'define me!'); // obj.uno = { na: { not: { existent: 'define me!' } } }

Install (NPM)

$ npm install --save o.set

Test

$ npm install && npm test

Package Sidebar

Install

npm i o.set

Weekly Downloads

2

Version

1.1.1

License

BSD-2-Clause

Unpacked Size

4.26 kB

Total Files

6

Last publish

Collaborators

  • zewish