https://github.com/react-earth/object-standard-path
Typed get/set deep nested properties with standard path.
https://github.com/react-earth/object-standard-path
access array change deep dot get nested notation object path property set standard type typescript update value
Last synced: 10 months ago
JSON representation
Typed get/set deep nested properties with standard path.
- Host: GitHub
- URL: https://github.com/react-earth/object-standard-path
- Owner: react-earth
- License: mit
- Created: 2023-05-23T10:19:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-07T06:19:19.000Z (over 1 year ago)
- Last Synced: 2025-04-07T03:35:17.853Z (10 months ago)
- Topics: access, array, change, deep, dot, get, nested, notation, object, path, property, set, standard, type, typescript, update, value
- Language: TypeScript
- Homepage:
- Size: 1.59 MB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

## Quick Features 🥳
- Standard path, e.g. `a.b.c[0].d`.
- Provider types & utils: Path, PathValue, pathGet, pathSet, pathSetImmutable.
- Built with typescript, provide type protection, code autocompletion, make your app robust.
- No dependencies, less than 1kB page size.
## How to use 📖
### Install package
```shell
npm install object-standard-path
```
### Use types: Path, PathValue
```typescript
import { Path, PathValue } from 'object-standard-path';
type Test = {
value: string;
array: {
value: string;
}[];
};
type TestPath = Path;
// result: "value" | "array" | `array[${number}]` | `array[${number}].value`
type TestPathValue = PathValue;
// result: { value: string }
```
### Use utils: pathGet, pathSet, pathSetImmutable
```typescript
import { pathGet, pathSet, pathSetImmutable } from 'object-standard-path';
const object = {
array: [
{
value: 1,
},
],
};
const result = pathGet(object, 'array[0].value');
// result: 1
pathSet(object, 'array[0].value', 2);
// object: { array: [{ value: 2 }] }
const result = pathSetImmutable(object, 'array[0].value', 2);
// result: { array: [{ value: 2 }] }
```
**Notes: please don't include the characters `.[]` in the key of the object, as they may affect parsing.**