0.0.13 • Published 8 months ago

@jsonlang/object v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

👋 JsonLang/Object

It is JsonLang Plugin/Extension for Object operations.

npm version install size npm downloads Vulnerabilities Maintenance Build Programming Language License FOSSA Status Github Sponsor

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

For more Info and examples

  • 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 style var1.var2 for nested fields and brackets with number for arrays var1.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 style var1.var2 for nested fields and brackets with number for arrays var1.var2[3].var3. If the path does not exist, the Set 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 style var1.var2 for nested fields and brackets with number for arrays var1.var2[3].var3. If the path does not exist, the Update 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 style var1.var2 for nested fields and brackets with number for arrays var1.var2[3].var3. If the path does not exist, the Delete rule won't do anything.
  • More...

💻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