Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdc

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdc - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

.npmignore

20

examples/simple.js

@@ -26,17 +26,9 @@ // (The MIT License)

var config = require('../').create([
{
"env": {
"dev": null,
"prod": null
}
}
]);
var cfg = require('../').create();
config.set({port: 8080}); // default
config.set({port: 3000}, {env: 'dev'});
config.set({port: 80}, {env: 'prod'});
cfg.set({
title: 'Github',
host: 'http://github.com'
});
console.log(config.get('port')); // default
console.log(config.get('port', {env: 'dev'}));
console.log(config.get('port', {env: 'prod'}));
console.log(cfg.get('title')); // Github

@@ -626,45 +626,46 @@ // (The MIT License)

* @public
* @param {array} dimensions
*/
ConfigStore = function (dimensions) {
ConfigStore = function () {
var bundle,
cache = {};
if (!dimensions) {
dimensions = [];
}
/*
* Create the main bundle using the given "dimensions"
* This method will set the bundle to the value of the inputs replacing
* any data already in the instance.
*
* If only the first argument is provided is will be treated as the
* complete bundle.
*
* @public
* @method setBundle
* @param {array} dimensions
* @param {array} settings
* @param {array} schema
* @return {ConfigStore}
*/
bundle = [{
dimensions: dimensions
}];
this.setBundle = function(dimensions, settings, schema) {
if (!dimensions) {
dimensions = [];
}
if (!settings) {
settings = [];
}
if (!schema) {
schema = null;
}
bundle = [{'dimensions': dimensions}].concat([{'schema': schema}]).concat(settings);
return this;
};
/*
* @public
* @method get
* @param {string} key
* @param {object} context
* @return {object}
* @method getBundle
* @return {array}
*/
this.get = function (key, context) {
var cacheKey;
if (!context) {
context = {};
}
cacheKey = JSON.stringify(context);
if (!cache[cacheKey]) {
cache[cacheKey] = parseBundleObject(bundle, context, true);
}
return extract(cache[cacheKey], key);
this.getBundle = function() {
return bundle;
};

@@ -677,6 +678,6 @@

* @param {object} context
* @param {object} schema
* @return {ConfigStore}
*/
this.set = function (object, context, schema) {
this.set = function(object, context) {

@@ -694,2 +695,4 @@ var groupId;

cache = {};
return this;
};

@@ -699,22 +702,23 @@

* @public
* @method getBundle
* @method get
* @param {string} key
* @param {object} context
* @return {object}
*/
this.getBundle = function () {
return bundle;
};
this.get = function(key, context) {
/*
* This method will set the bundle to the value of "bundleObj" replacing
* any data already in the instance.
*
* @public
* @method setBundle
* @param {object} bundleObj
* @return {object}
*/
var cacheKey;
this.setBundle = function (bundleObj) {
bundle = bundleObj;
if (!context) {
context = {};
}
cacheKey = JSON.stringify(context);
if (!cache[cacheKey]) {
cache[cacheKey] = parseBundleObject(bundle, context, true);
}
return extract(cache[cacheKey], key);
};

@@ -727,3 +731,3 @@ };

exports.version = '0.0.1';
exports.version = '0.0.3';

@@ -736,7 +740,11 @@ /*

* @param {array} dimensions
* @param {array} settings
* @param {array} schema
* @return ConfigStore
*/
exports.create = function (dimensions) {
return new ConfigStore(dimensions);
exports.create = function (dimensions, settings, schema) {
var cs = new ConfigStore();
cs.setBundle(dimensions, settings, schema);
return cs;
};
{
"name": "mdc",
"description": "Multi Dimensional Configuration",
"version": "0.0.2",
"version": "0.0.3",
"author": {

@@ -10,7 +10,10 @@ "name": "Richard S Allinson",

"main": "index",
"scripts": {
"test": "node ./tests/run.js"
},
"engines": {
"node": ">= 0.6.0 < 0.7.0"
"node": ">= 0.6.0"
},
"dependencies": {
"avrojs": "0.0.x"
"avrojs": "*"
},

@@ -17,0 +20,0 @@ "devDependencies": {

# Multi Dimensional Configuration
Words will be writen here.
Configuration is simple when you have it defined in a chunk of code.
var config = require('mdc').create([
var cfg = require('mdc').create();
cfg.set({
title: 'Github',
host: 'http://github.com'
});
cfg.get('title'); // Github
It gets a bit unwieldy but still usable when you introduce different dimensions to your configuration such as _development_ vs _production_.
var cfg = require('mdc').create([
{

@@ -14,10 +25,212 @@ "env": {

config.set({port: 8080}); // default
config.set({port: 3000}, {env: 'dev'});
config.set({port: 80}, {env: 'prod'});
cfg.set({port: 8080}); // default
cfg.set({port: 3000}, {env: 'dev'});
cfg.set({port: 80}, {env: 'prod'});
console.log(config.get('port')); // default
console.log(config.get('port', {env: 'dev'}));
console.log(config.get('port', {env: 'prod'}));
cfg.get('port'); // 8080
cfg.get('port', {env: 'dev'}); // 3000
cfg.get('port', {env: 'prod'}); // 80
More words will be writen here too.
Then there's a whole world of crazy when you start changing things based on _location_, _language_ or _device_ type!
/*
* Dimensions to work with
*/
var cfg = require('../').create([
{
"env": {
"dev": null,
"qa": null,
"prod": null
}
},
{
"device": {
"phone": {
"iphone": {
"itouch": null
},
"nexus": null
},
"desktop": {
"small": null,
"large": null
},
"tablet": {
"ipad": null,
"galaxy": null
}
}
},
{
"lang": {
"en": {
"en_US": {
"en_CA": null
},
"en_GB": null
}
}
}
]);
// Default values
cfg.set({
title: "Crazy World!",
more: "Show more",
source: "http://world.news.com/",
show: 10
});
// Special values
cfg.set({
title: "Crazy world, eh!"
}, {
lang: "en_CA"
});
cfg.set({
title: "It's a crazy world out there!"
}, {
lang: "en_GB"
});
cfg.set({
source: "http://localhost/test/news/"
}, {
env: "dev"
});
cfg.set({
source: "http://qa.my-company.com/news/fixtures/"
}, {
env: "qa"
});
cfg.set({
show: 5 // because it's smaller
}, {
device: "phone"
});
cfg.set({
show: 15 // because it's larger
}, {
device: "desktop"
});
cfg.set({
title: "It's crazy!" // because it's smaller
}, {
device: "phone",
lang: "en_GB"
});
cfg.get('source', {env: 'dev'}); // http://localhost/test/news/
cfg.get('title', {env: 'qa', lang: 'en_GB'}); // It's a crazy world out there!
cfg.get('show', {env: 'prod', lang: 'en_GB', device: 'itouch'}); // 5
cfg.get('title', {device: 'large', lang: 'en_CA'}); // Crazy world, eh!
# I believe I did, Bob.
## API
### create
Simple use;
var cfg = mdc.create();
Complex use;
var cfg = mdc.create(dimensions, settings, schema);
### set
Simple use;
mdc.set({key: 'value'});
Complex use;
mdc.set({path: {to: {key: 'value'}}}, {context: 'value'});
### get
Simple use;
mdc.get('key');
Complex use;
mdc.get('path.to.key', {context: 'value'});
### setBundle
mdc.setBundle(dimensions, settings, schema);
### getBundle
var bundle = mdc.getBundle();
# Data Structures
The following examples are shown in [YAML](http://www.yaml.org/).
## Reserved Words
The following words cannot be used as top level keys in any data structures.
* dimensions
* settings
* schema
## Bundle
A _bundle_ is an **array** of **maps** which collectively contain all the information required for the configuration.
- dimensions:
- settings:
- schema:
## Dimensions
The _dimensions_ are...
- dimensions:
- region:
us:
jp:
- site:
sports:
news:
## Settings
The _settings_ are...
- settings: [default]
data:
b: 5
y: 7
- settings: [context:key]
data:
b: 10
- settings: [context:key, context:key]
data:
y: 14
## Schema
The _schema_ uses [Avro](http://avro.apache.org/) and...
- schema:
- name: settings
type: record
fields:
- name: data
type: map
values: int

@@ -69,8 +69,6 @@ // (The MIT License)

'test if we can use a bundle config with dimensions last': function () {
'test if we can use a bundle config with dimensions first': function () {
var config = mdc.create();
var config = mdc.create(dim, cfg.bundle);
config.setBundle(cfg.bundle.concat([{'dimensions': dim}]));
// Y.log(JSON.stringify(config.getBundle(),null,4));

@@ -83,8 +81,6 @@

'test if we can use a bundle config with dimensions first': function () {
'test if we can use bundle settings with dimensions as first argument': function () {
var config = mdc.create();
var config = mdc.create(dim, cfg.bundle);
config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
// Y.log(JSON.stringify(config.getBundle(),null,4));

@@ -102,3 +98,3 @@

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -122,3 +118,3 @@ context = {

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -142,3 +138,3 @@ context = {

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -163,3 +159,3 @@ context = {

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -184,3 +180,3 @@ context = {

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -204,3 +200,3 @@ context = {

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -224,3 +220,3 @@ context = {

config.setBundle([{'dimensions': dim}].concat(cfg.bundle));
config.setBundle(dim, cfg.bundle);

@@ -241,7 +237,2 @@ context = {

Y.log('Starting');
Y.Test.Runner.add(testCase);
//run all tests
Y.Test.Runner.run();
module.exports = testCase;

@@ -24,2 +24,4 @@ // (The MIT License)

/*jslint nomen:true*/
"use strict";

@@ -44,3 +46,3 @@

},
'test simple schema success': function () {

@@ -50,5 +52,3 @@

config.setBundle([{'dimensions': dim}]
.concat([{'schema': cfg.simple_schema_good}])
.concat(cfg.bundle));
config.setBundle(dim, cfg.bundle, cfg.simple_schema_good);

@@ -64,5 +64,3 @@ // Y.log(JSON.stringify(config.get(),null,4));

config.setBundle([{'dimensions': dim}]
.concat([{'schema': cfg.simple_schema_bad}])
.concat(cfg.bundle));
config.setBundle(dim, cfg.bundle, cfg.simple_schema_bad);

@@ -75,7 +73,2 @@ // Y.log(JSON.stringify(config.get(),null,4));

Y.log('Starting');
Y.Test.Runner.add(testCase);
//run all tests
Y.Test.Runner.run();
module.exports = testCase;

@@ -142,7 +142,2 @@ // (The MIT License)

Y.log('Starting');
Y.Test.Runner.add(testCase);
//run all tests
Y.Test.Runner.run();
module.exports = testCase;

@@ -42,3 +42,5 @@ // (The MIT License)

{ "name": "logo", "type": "string" },
{ "name": "links", "type": {
{
"name": "links",
"type": {
"type": "record",

@@ -60,3 +62,5 @@ "fields": [

{ "name": "logo", "type": "string" },
{ "name": "links", "type": {
{
"name": "links",
"type": {
"type": "record",

@@ -63,0 +67,0 @@ "fields": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc