
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
json-regulator
Advanced tools
Manages conditional configurations by promoting and/or eliminating specific keys of a JSON value object.
Manages conditional configurations by promoting and/or eliminating specific keys of a JSON value object.
npm install json-regulator
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.
Don't care.
valuesThe JSON value object needs to regulate.
promotionsKey or array of keys to promote.
eliminationsOptional. Key or array of keys to eliminate.
immutablesOptional. Key or array of keys that should never mutate.
optionsoptions.overwriteOptional. Overwrite existing values or not. Default is true.
A new regulated JSON value object.
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'
}
}}
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
$ npm test
FAQs
Manages conditional configurations by promoting and/or eliminating specific keys of a JSON value object.
We found that json-regulator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.