@jsonlang/object
v0.0.13
Published
JsonLang Extension for (Key-Value pair) Object/Map Operations
Downloads
81,398
Maintainers
Readme
👋 JsonLang/Object
It is JsonLang Plugin/Extension for Object operations.
⏬ Installation
npm install @jsonlang/core @jsonlang/object
🎉 Usage
import { JsonLang } from '@jsonlang/core';
import { ObjectRules } from '@jsonlang/object';
const jsonLang = new JsonLang();
jsonLang.import(ObjectRules);
⚒️ Rules
Get [In Progress]
- Input[]: Array (Size: 3) {path: string, defaultValue?: any, data:{}}.
- Output: Any.
- Description: It accepts two inputs, the 1st one (required) is a path to get the Data, and the 2nd one (optional) is a default value of the path is not found. the
path
must follow the dotted stylevar1.var2
for nested fields and brackets with number for arraysvar1.var2[3].var3
Set [In Progress]
- Input[]: Array (Size: 3) {path: string, value: any, data:{}}.
- Output: Any.
- Description: It accepts two inputs. The 1st one (required) is a path to update/mutate the Data, and the 2nd one is the value to set. the
path
must follow the dotted stylevar1.var2
for nested fields and brackets with number for arraysvar1.var2[3].var3
. If thepath
does not exist, theSet
Rule will create it.
Update [In Progress]
- Input[]: Array (Size: 3) {path: string, value: any, data:{}}.
- Output: Any.
- Description: It accepts two inputs. The 1st one (required) is a path to update/mutate the Data, and the 2nd one is the value to update. the
path
must follow the dotted stylevar1.var2
for nested fields and brackets with number for arraysvar1.var2[3].var3
. If thepath
does not exist, theUpdate
rule won't do anything.
Delete [In Progress]
- Input[]: Array (Size: 2) {path: string, data:{}}.
- Output: Any.
- Description: It accepts two inputs, a path to mutate the Data by deleting a field in the request path. the
path
must follow the dotted stylevar1.var2
for nested fields and brackets with number for arraysvar1.var2[3].var3
. If thepath
does not exist, theDelete
rule won't do anything.
💻Examples
import { JsonLang } from '@jsonlang/core';
import { ObjectRules } from '@jsonlang/object';
const jsonLang = new JsonLang();
jsonLang.import(ObjectRules);
jsonLang.execute(
{ $R: 'Get', $I: ['data.test', null, { $R: 'Data', $I: ['External'] }] },
{ data: { id: '1', test: 100 } },
{ sync: true }
); // 100
🔌 Compatibility
This library uses Array.map
and Array.reduce
, so it's not exactly Internet Explorer 8 friendly.
📜 License
JsonLang/Object is MIT licensed