Code Monkey home page Code Monkey logo

aurora-deep-slice-merge's Introduction

Aurora Deep Slice, Merge and Append

Tool for slicing, merging and appending to Aurora configuration objects.

Example

const util = require('util')
const { slice, merge } = require('aurora-deep-slice-merge');

let configPage1 = { meta: { title: 'Blabla' },
  app:
   { type: 'awesome-app', options:
      { modules:
         [ { type: 'awesome-module', options: { a: 5 } },
           { type: 'awesome-module', options: { b: 10 } },
           { type: 'awesome-hom', options: {
             modules:
              [ { type: 'awesome-module', options: { c: 15 } } ] } } ] } } }

let configPage2 = { meta: { title: 'Blabla' },
  app:
   { type: 'awesome-app', options:
      { modules:
         [ null,
           null,
           { type: 'awesome-hom', options:
             { modules:
              [ null,
                { type: 'awesome-module', options: { d: 20 } },
                { type: 'awesome-hom', options: {
                  modules:
                   [ { type: 'awesome-module', options: { e: 25 } },
                     { type: 'awesome-module', options: { f: 30 } } ] } } ] } } ] } } }

console.log(util.inspect(merge(configPage1, configPage2)));

output:

{ meta: { title: 'Blabla' },
  app:
   { type: 'awesome-app', options:
      { modules:
         [ { type: 'awesome-module', options: { a: 5 } },
           { type: 'awesome-module', options: { b: 10 } },
           { type: 'awesome-hom', options:
              { modules:
                 [ { type: 'awesome-module', options: { c: 15 } },
                   { type: 'awesome-module', options: { d: 20 } },
                   { type: 'awesome-hom', options:
                      { modules:
                         [ { type: 'awesome-module', options: { e: 25 } },
                           { type: 'awesome-module', options: { f: 30 } } ] } } ] } } ] } } }

Append a list of modules to an Aurora configs (shallow).

Example

const util = require('util')
const { append } = require('aurora-deep-slice-merge');

let config = { meta: { title: 'Blabla' },
  app:
   { type: 'awesome-app', options:
      { modules:
         [ { type: 'awesome-module', options: { a: 5 } },
           { type: 'awesome-module', options: { b: 10 } } ] } } }

let modulesToAppend = [
  { type: 'awesome-hom', options:
    { modules:
      [ { type: 'awesome-module', options: { c: 15 } },
        { type: 'awesome-module', options: { d: 20 } },
        { type: 'awesome-hom', options:
          { modules:
            [ { type: 'awesome-module', options: { e: 25 } },
              { type: 'awesome-module', options: { f: 30 } } ] } } ] } } ]

console.log(util.inspect(append(config, modulesToAppend)));
{ meta: { title: 'Blabla' },
  app:
   { type: 'awesome-app', options:
      { modules:
         [ { type: 'awesome-module', options: { a: 5 } },
           { type: 'awesome-module', options: { b: 10 } },
           { type: 'awesome-hom', options:
              { modules:
                 [ { type: 'awesome-module', options: { c: 15 } },
                   { type: 'awesome-module', options: { d: 20 } },
                   { type: 'awesome-hom', options:
                      { modules:
                         [ { type: 'awesome-module', options: { e: 25 } },
                           { type: 'awesome-module', options: { f: 30 } } ] } } ] } } ] } } }

Methods

const { slice, merge, append } = require('aurora-deep-slice-merge');

/**
 * Slice a config x from startIndex with a specified amount of elements
 */
slice(x, startIndex, amount)

/**
 * Merge config x and y
 */
merge(x, y)

/**
 * Append list of modules to config x
 */
append(x, list)

Install

With npm/github do:

npm install soldotno/aurora-deep-slice-merge

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.