0.0.13 • Published 2 years ago
@jsonlang/object v0.0.13
👋 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
pathmust follow the dotted stylevar1.var2for 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
pathmust follow the dotted stylevar1.var2for nested fields and brackets with number for arraysvar1.var2[3].var3. If thepathdoes not exist, theSetRule 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
pathmust follow the dotted stylevar1.var2for nested fields and brackets with number for arraysvar1.var2[3].var3. If thepathdoes not exist, theUpdaterule 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
pathmust follow the dotted stylevar1.var2for nested fields and brackets with number for arraysvar1.var2[3].var3. If thepathdoes not exist, theDeleterule 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