npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-merge-data

v0.4.5

Published

Grunt task for merging multiple data into a JSON file or Grunt config

Downloads

6

Readme

grunt-merge-data

NPM version Build Status Build status Dependency Status devDependency Status

Merge multiple data into a single JSON file or Grunt config, based on their basename

Installation

Use npm.

npm install --save-dev grunt-merge-data

Usage

The plugin may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-merge-data');

The merge_data task

In your project's Gruntfile, add a section named merge_data to the data object passed into grunt.initConfig().

grunt.initConfig({
  merge_data: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      src: ['path/to/src/*.{json,y{,a}ml}']
      dest: 'path/to/dest/all.json'
    }
  }
})

Running merge_data task task with grunt merge_data command will merge all data of specified JSON or YAML files into a single JavaScript object, and write it as a JSON file.

Each of the data will be formatted as {<basename of file>: <data of file>}. For example, when the source path of task target specifies two files, such as:

data1.json:

["Classic", "Jazz", "Rock"]

data2.yaml:

first_name: John
family_name: Smith

they will be merged into a JSON file like this:

{
  "data1": ["Classic", "Jazz", "Rock"],
  "data2": {
    "first_name": "John",
    "family_name": "Smith"
  }
}

Options

options.data

Type: Object|Function Default: null

This is an additional data that will be merged together with the sources files.

This option will overrides existing data of source files. For example, when option.data is {data1: 'something'}, the data of data1.json won't be reflected in the output.

This value also might be a function taking a data object of source files as the first argument and returns a data object.

options: {
  data: function (data) {
    return {
      next_year: data.year + 1,
      prev_year: data.year - 1
    };
  }
}

options.space

Type: Number|String Default: null

This option will be directly passed to the space argument of JSON.stringify. You can control indent style of output file with this option.

options.asConfig

Type: String|Array|Boolean Default: false

If you specified the project's Grunt configuration in this option, merge result will be assigned to it. See Accessing Config Data to use this option.

Or, if you set this option true, the context property of the task traget will be overwritten with the merge result.

For example, if the task is configured such as:

grunt.initConfig({
  merge_data: {
    target1: {
      options: {
        asConfig: true
      },
      src: ['path/to/src/*.{json,y{,a}ml}']
    }
  }
})

the merge result will be assigned to merge_data.target1.context.

When you use this option, you can also specify the destination path of task target but don't need to. If you do so, at the same time the Grunt configuration will be updated, the JSON file will be output. Both the configuration and the JSON file will have the same value.

Usage Examples

Default Options

grunt.initConfig({
  merge_data: {  
    files: {
      'dest/all.json': ['src/data1.json', 'src/data2.json'],
    }
  }
})

Updating Grunt configuration

grunt.initConfig({
  merge_data: {
    options: {
      asConfig: 'someConfig.data' 
    },
    src: ['src/data1.json', 'src/data2.json']
  }
  
  someConfig: {}
})

License

Copyright (c) 2013 - 2016 Shinnosuke Watanabe.

Licensed under the MIT license.