mergeon
Loading extendable JSON structures
Last updated 2 years ago by schapka .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mergeon 
SYNC missed versions from official npm registry.

npm Build Status Build status

Mergeon

Loading extendable JSON structures:

  • Load data from different JSON files
  • Use wildcards/globs
  • Override inherited values
  • Merge data
  • Customize merging

Contents

Installation

npm

npm i -S mergeon

yarn

yarn add mergeon

Examples

Simple use case

Load data from different JSON file and override values:

entry.json

{
  "_extends": "./default-data.json",
  "title": "New title",
  "image": {
    "alt": "New alt value"
  }
}

default-data.json

{
  "title": "Default title",
  "image": {
    "src": "path/to/default/image.jpg",
    "alt": "Default alt value"
  }
}

Result

{
  "title": "New title",
  "image": {
    "src": "path/to/default/image.jpg",
    "alt": "New alt value"
  }
}

Target path

Define a target path by using special syntax (<extendKey>:<targetPath>):

entry.json

{
  "_extends:target.path": "./default-data.json"
}

default-data.json

{
  "title": "Default title"
}

Result

{
  "target": {
    "path": {
      "title": "Default title"
    }
  }
}

Wildcards

Load multiple files by adding wildcards:

entry.json

{
  "_extends:buttons": "./buttons/*.json"
}

buttons/primary.json

{
  "type": "primary"
}

buttons/secondary.json

{
  "type": "secondary"
}

Result

{
  "buttons": {
    "primary": {
      "type": "primary"
    },
    "secondary": {
      "type": "secondary"
    }
  }
}

Additional examples

See test directory for additional examples, including wildcards, globstars, customized merging and many more.

Usage

JavaScript API

import mergeon from 'mergeon';

mergeon
  .load({
    entry: 'data/entry.json',
  })
  .then(result => {
    const jsonString = JSON.stringify(result.data, null, 2);
    /* ... */
  })
  .catch(error => {
    /* ... */
  });

CLI

mergeon data/entry.json > output.json

Options

entry

Type Default Required
string | object undefined yes

context

Type Default Required
string process.cwd() no

Note: This option is not available to CLI

extendKey

Type Default Required
string "_extends" no

mergeCustomizer

Type Default Required
function undefined no

This function will be passed as customizer to lodash’s _.mergeWith method.

Note: This option is not available to CLI

Current Tags

  • 0.4.2                                ...           latest (2 years ago)

29 Versions

  • 0.4.2                                ...           2 years ago
  • 0.4.1                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.16                                ...           2 years ago
  • 0.2.15                                ...           2 years ago
  • 0.2.14                                ...           2 years ago
  • 0.2.13                                ...           2 years ago
  • 0.2.12                                ...           2 years ago
  • 0.2.11                                ...           2 years ago
  • 0.2.10                                ...           2 years ago
  • 0.2.9                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.4                                ...           2 years ago
  • 0.2.5                                ...           2 years ago
  • 0.2.6                                ...           2 years ago
  • 0.2.7                                ...           2 years ago
  • 0.2.8                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.5                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 29
Dependencies (5)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |