Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mariuslundgard/segmented-property
A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.
https://github.com/mariuslundgard/segmented-property
Last synced: 2 days ago
JSON representation
A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.
- Host: GitHub
- URL: https://github.com/mariuslundgard/segmented-property
- Owner: mariuslundgard
- License: mit
- Created: 2017-04-24T21:15:11.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-10-27T22:10:37.000Z (about 1 year ago)
- Last Synced: 2024-09-25T15:58:40.384Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 568 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# segmented-property
A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.
```sh
npm install segmented-property
```[![npm version](https://img.shields.io/npm/v/segmented-property.svg?style=flat-square)](https://www.npmjs.com/package/segmented-property)
## Usage
```js
import {get, set} from 'segmented-property'const obj1 = {foo: {bar: 1}}
const obj2 = set(obj1, 'foo/bar', 2)console.log(get(obj1, 'foo/bar')) // 1
console.log(get(obj2, 'foo/bar')) // 2
```## API
#### `get(source, [key])`
Gets a value.
#### `set(source, [key], value)`
Sets a new value and returns a new object.