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

json-regulator-with-regexp

v0.1.15

Published

Manages conditional configurations by promoting and/or eliminating specific keys of a JSON value object.

Downloads

8

Readme

json-regulator

Manages conditional configurations by promoting and/or eliminating specific keys of a JSON value object.

MIT npm version David Dependency Badge

NPM NPM

Install

npm install json-regulator

API

regulate(values, promotions, eliminations, immutables, options)

For given JSON value object values, returns a new JSON value object, that promotes keys in promotions array one level up, and eliminats keys in both promotions and eliminations arrays.

Context

Don't care.

Parameters

values

The JSON value object needs to regulate.

promotions

Key or array of keys to promote.

eliminations

Optional. Key or array of keys to eliminate.

immutables

Optional. Key or array of keys that should never mutate.

options
options.overwrite

Optional. Overwrite existing values or not. Default is true.

Returns

A new regulated JSON value object.

Example

var regulate = require('json-regulator');

var production = ['production', 'prod'];
var development = ['development', 'dev'];
var config = {
    development: {
        description: 'development build',
        release: false,
        src: 'src/',
        dest: 'build/'
    },
    production: {
        description: 'production build',
        release: true,
        src: 'src/',
        dest: 'dist/',
        sourcemaps: {
            dest: 'maps/'
        }
    },
    scripts: {
        src: '**/*.js',
        prod: {
            bundle: 'bundle.js'
        },
        options: {
            debug: false,
            dev: {
                debug: true
            }
        }
    },
    deploy: {
        development: {
            settings: {
                'log-level': 'info'
            }
        },
        dev: {
            settings: {
                overwrite: 'force'
            }
        },
        production: {
            settings: {
                'log-level': 'warning'
            }
        },
        prod: {
            settings: {
                overwrite: 'auto'
            }
        }
    }
};

With the call:

config = regulate(config, production, development);

Generates:

{
    description: 'production build',
    release: true,
    src: 'src/',
    dest: 'dist/',
    sourcemaps: {
        dest: 'maps/'
    },
    scripts: {
        src: '**/*.js',
        bundle: 'bundle.js',
        options: {
            debug: false
        }
    },
    deploy: {
        settings: {
            'log-level': 'warning',
            overwrite: 'auto'
        }
    }
}

And with the call:

config = regulate(config, development, production);

Generates:

{
    description: 'development build',
    release: false
    src: 'src/',
    dest: 'build/',
    scripts: {
        src: '**/*.js',
        options: {
            debug: true
        }
    },
    deploy: {
        settings: {
            'log-level': 'info',
            overwrite: 'force'
        }
    }}

Sample Usage

If you are using gulp, you can enable conditional build with conditional configurations.

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    doif = require('gulp-if'),
    sourcemaps = require('gulp-sourcemaps'),
    uglify = require('gulp-uglify'),
    util = require('gulp-util');

var production = ['production', 'prod'],
    development = ['development', 'dev'],
    config = {
        // ...
    };

if (util.env.dev) {
    config = regulate(config, development, production);
} else {
    config = regulate(config, production, development);
}

gulp.task('scripts', function () {
    return gulp.src(config.src + config.scripts.src)
        .pipe(doif(config.sourcemaps, sourcemaps.init()))
        .pipe(doif(config.release, uglify()))
        .pipe(doif(config.release, concat(config.scripts.bundle)))
        .pipe(doif(config.sourcemaps, sourcemaps.write(config.dest + config.sourcemaps.dest)))
        .pipe(gulp.dest(config.dest));
});

Run gulp:

$ gulp --dev scripts

Test

$ npm test

Change Log

  • 2016/01/09 - 0.1.15

    • Feature: add immutables parameter. See test for examples.
  • 2016/01/02 - 0.1.14

    • Feature: add overwrite option.
    • Bug Fix: process normal properies before promotions properties to ensure overwrite option.
  • 2015/12/24 - 0.1.10

    • NPM: Update npm settings.
  • 2015/12/18 - 0.1.9

    • Feature: also process objects inside array values recursively.
    • Feature: parameter promotions and eliminations now can be string or array of strings.
    • Enhance: returns a new JSON value object, the input values is immutable now.
  • 2015/12/15 - 0.1.0

    • First release.

Related

License

MIT

Author

Amobiz