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

gulp-json-config-noexploits

v2.0.3

Published

A plugin for Gulp to combine JSON config files into combined files based on rule-set and modification function - modified to not included exploit version of event-stream

Downloads

2

Readme

gulp-json-config

NPM version Build Status Dependency Status Code Climate

A plugin for Gulp to combine JSON config files into combined files based on rule-set and modification function

Gulp-json-config parses JSON files, combines them into single file or when rule set provided into several combined files based on rules. See Basic usage and Advanced usage below.

Note: NodeJs v4 or above and Gulp are required. Warning: Version v2.x.x is not backwards compatible with version 1.0.1.

Installation

Install gulp-json-config as a development dependency:

npm install --save-dev gulp-json-config

Basic usage

Gulp-json-config combines contents of input JSON files and saves them into single file.

gulpfile.js

var gulp = require('gulp');
var jsonConfig = require('gulp-json-config');

gulp.task('index', function () {
  return gulp.src(['path/to/*.json'])
           .pipe(jsonConfig())
           .pipe(gulp.dest('dest/path'));
});

inputA.json

{
  "key1": "value1"
}

inputB.json

{
  "key2": "value2"
}

Will result in config.json:

{
  "inputA": { 
    "key1": "value1" 
  },
  "inputB": { 
    "key2": "value2" 
  }  
}

Advanced usage

When provided rule set it will parse the content and apply rule filtering to combine appropriate content in resulting files. Intended usage or this rule set is to provide easy mechanism for different configs for different deployment environments.

gulpfile.js

var gulp = require('gulp');
var jsonConfig = require('gulp-json-config');

gulp.task('index', function () {
  return gulp.src(['path/to/*.json'])
           .pipe(jsonConfig({
             fileName: 'configName.json',
             modify: function(jsonObj) {
               Object.keys(jsonObj).forEach(function(key) {
                 jsonObj[key + '_env'] = jsonObj[key];
                 delete jsonObj[key];
               });
             },
             rules: {
                "prod_env": ["prod_env"],
                "dev_env": ["dev_env", "prod_env"]
             }
           }))
           .pipe(gulp.dest('dest/path'));
});

Plugin will generate separate file for each rule-set group by applying priority described in group definition. In this file it means that for dev file it will take all keys from dev and merge them into prod overriding all the existing fields.

inputA.json

{
  "dev": {
    "onlyInDev": "value1",
    "shared": "value2"
  }, 
  "prod": {
    "shared": "value3",
    "onlyInProd": "value4"
  }
}

inputB.json

{
  "dev": {
    "onlyInDev": "valueA",
    "shared": "valueB"
  }, 
  "prod": {
    "shared": "valueC",
    "onlyInProd": "valueD"
  }
}

Will result in two files: configName.prod_env.json

{
  "inputA": { 
    "shared": "value3",
    "onlyInProd": "value4"
  },
  "inputB": { 
    "shared": "valueC",
    "onlyInProd": "valueD"
  }
}

configName.dev_env.json

{
  "inputA": { 
    "onlyInDev": "value1",
    "shared": "value2",
    "onlyInProd": "value4"
  },
  "inputB": { 
    "onlyInDev": "valueA",
    "shared": "valueB",
    "onlyInProd": "valueD"
  }
}

All the combinations are possible.

Local overrides

Local overrides are possible with use of prefix .local in file naming e.g. my-config.local.json. Those files will override all fields of parent configs and will follow the same rule set as their parents.

my-config.json

{
  "user": {
    "firstname": "John",
    "lastname": "Doe"
  }
}

my-config.local.json

{
  "user": {
    "firstname": "Jane",
    "middle": "Marry"
  }
}

Will result in following config:

{
  "my-config": {
    "user": {
      "firstname": "Jane",
      "middle": "Marry",
      "lastname": "Doe"
    }  
  }
}

Normally, *.local.json is easy to be added to .gitignore so your local experiments/overrides do not pollute code base.

API

gulp-inject-partial(options)

options.fileName

Type: String Param: optional Default: config.json Example:

my-config.json

Filename of resulting config file

options.rules

Type: [key: string]: string[] Param: optional Default: null Example:

  {
    "prod": ["prod"],
    "staging": ["staging", "prod"],
    "dev": ["dev", "staging", "prod"]
  }

Rule dictionary for parsing and combining between different rule groups.

options.modify

Type: (json: Object): Object Param: optional Default: function(json) { return json; } Example:

function(jsonObj) {
   Object.keys(jsonObj).forEach(function(key) {
     jsonObj[key + '_env'] = jsonObj[key];
     delete jsonObj[key];
   });
}

Custom function to modify file contents (parsed JSON objects) before merging them together.

License

MIT © Miroslav Jonas