Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsonlang/array

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsonlang/array

JsonLang Extension for Array/Collection Operations

  • 0.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
decreased by-10.18%
Maintainers
1
Weekly downloads
 
Created
Source

👋 JsonLang/Array

JsonLang Logo




It is JsonLang Plugin/Extension for Array/Collection operations.

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





Installation

npm install @jsonlang/core @jsonlang/array

🎉 Usage

import { JsonLang } from '@jsonlang/core';
import { ArrayRules } from '@jsonlang/array';

const jsonLang = new JsonLang();

jsonLang.import(ArrayRules);



⚒️ Rules


For more Info and examples


  • All

    • Input[]: Array (Size: Unlimited).
    • Output: Array (Size: Unlimited).
    • Description: It takes an array of inputs and returns them again. It is used to run a list of nested Rules.
  • Filter

    • Input[]: Array (Size: 2) {elements: any[], rule: IJsonLangParams}.
    • Output: Any[].
    • Description: It accepts array of elements with any type to filter them using nested/inner rules, the filter rule will pass each elements as a Data with scope Internal, to access it by the inner rules, you will need to use Data Rule with scope local, check this example.
  • Map

    • Input[]: Array (Size: 2) {elements: any[], rule: IJsonLangParams}.
    • Output: Any[].
    • Description: It accepts array of elements with any type to map them using nested/inner rules, the filter rule will pass each elements as a Data with scope Internal, to access it by the inner rules, you will need to use Data Rule with scope local.
  • Foreach

    • Input[]: Array (Size: 2) {elements: any[], rule: IJsonLangParams}.
    • Output: true.
    • Description: It accepts array of elements with any type to iterate over them using nested/inner rules, the filter rule will pass each elements as a Data with scope Internal, to access it by the inner rules, you will need to use Data Rule with scope local.
  • Flatten

    • Input[]: Array (Size: 2) {elements: any[], level?: number}.
    • Output: true.
    • Description: It accepts array of elements with any type to flatten this array with any level.
  • More...


💻Examples


import { JsonLang } from '@jsonlang/core';
import { LogicRules } from '@jsonlang/logic';
import { ArrayRules } from '@jsonlang/array';
import { ObjectRules } from '@jsonlang/object';

const jsonLang = new JsonLang();

jsonLang.import(LogicRules, ArrayRules, ObjectRules);

const result = jsonLang.execute({ $R: 'All', $I: [
  { 
    $R: 'Filter',
    $I: [[1, 3, 5], { $R: '>', $I: [{ $R: 'Data', $I: ['Internal'] }, 2] }]
  },
  { 
    $R: 'Filter',
    $I: [
      { $R: 'Get', $I: ['data.test', null, { $R: 'Data', $I: ['External'] }] },
      { $R: '<', $I: [{ $R: 'Data', $I: ['Internal'] }, 500] }
    ]
  }
] }, { data: { id: 'test', test: [100, 300, 700] } }, { sync: true });

console.log(result);

// [ [ 3, 5 ], [ 100, 300 ] ]



🔌 Compatibility


This library uses Array.map and Array.reduce, so it's not exactly Internet Explorer 8 friendly.


📜 License


JsonLang/Array is MIT licensed

Keywords

FAQs

Package last updated on 18 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc