https://github.com/galvez/fast-path-set
A fast drop-in replacement for lodash.set
https://github.com/galvez/fast-path-set
Last synced: 4 months ago
JSON representation
A fast drop-in replacement for lodash.set
- Host: GitHub
- URL: https://github.com/galvez/fast-path-set
- Owner: galvez
- Created: 2021-04-24T22:43:36.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-27T06:47:39.000Z (almost 5 years ago)
- Last Synced: 2025-04-16T10:11:42.344Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 59.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - fast-path-set - in replacement for lodash.set | galvez | 5 | (JavaScript)
README
# fast-path-set
A fast drop-in replacement for [`lodash.set`](https://www.npmjs.com/package/lodash.set).
## Install
```
$ npm i fast-path-set --save
```
## Usage
```js
const set = require('fast-path-set')
const obj = {}
set(obj, 'a.b.c', 1)
console.log(obj.a.b.c)
```
Check [`test.js`](https://github.com/galvez/fast-path-set/blob/main/test.js) for more detailed usage examples. There is one **key** difference to `lodash.set`, which is the fact `fast-path-set` will **prioritise safety** and abort attempts to overwrite non-object values. It also correctly prevents prototype pollution attacks.
## Benchmark
```
$ npm i lodash.set
$ node bench.js lodash.set
85422.0864751339
$ npm i dset
$ node bench.js dset
65307.5742549896
$ node bench.js fast-path-set
63214.1385409832
```
## Acknowledgements
Thanks to
[Luke Edwards](https://github.com/lukeed),
[James M Snell](https://github.com/jasnell) and
[Simone Sanfratello](https://github.com/simone-sanfratello)
for helping polishing this to perfection.
## License
MIT