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

configuration

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configuration - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.github/FUNDING.yml

1

dist/index.d.ts

@@ -13,2 +13,3 @@ import { ValidateFunction } from 'ajv';

constructor(options: Partial<Options>);
_getTargetScopeForPath(path: Path): Scope;
init(): void;

@@ -15,0 +16,0 @@ dispose(): void;

@@ -14,2 +14,3 @@ "use strict";

class Configuration {
/* CONSTRUCTOR */
constructor(options) {

@@ -21,3 +22,3 @@ var _a, _b;

this.scopes = {};
this.scope = (_b = options.scope, (_b !== null && _b !== void 0 ? _b : this.providers[this.providers.length - 1].scope));
this.scope = (_b = options.scope) !== null && _b !== void 0 ? _b : this.providers[this.providers.length - 1].scope;
this.handlers = [];

@@ -38,2 +39,12 @@ this.defaults = new memory_1.default({ scope: config_1.SCOPE_DEFAULTS });

}
/* HELPERS */
_getTargetScopeForPath(path) {
for (let i = 0, l = this.providers.length - 1; i < l; i++) {
const { scope } = this.providers[i];
if (this.has(scope, path))
return scope;
}
return this.scope;
}
/* API */
init() {

@@ -149,3 +160,3 @@ this.providers.push(this.defaults);

if (type_1.default.isUndefined(value))
return this.set(this.scope, scope, path); // Path
return this.set(this._getTargetScopeForPath(scope), scope, path); // Path
if (!type_1.default.isString(path))

@@ -178,3 +189,3 @@ return; //TSC

if (type_1.default.isUndefined(path))
return this.remove(this.scope, scope); // Path
return this.remove(config_1.SCOPE_ALL, scope); // Path
if (scope === config_1.SCOPE_ALL) { // All

@@ -181,0 +192,0 @@ for (let scope in this.scopes) {

8

dist/providers/abstract.js

@@ -10,7 +10,7 @@ "use strict";

constructor(options) {
var _a, _b, _c, _d, _e;
if (((_a = options) === null || _a === void 0 ? void 0 : _a.scope) === config_1.SCOPE_ALL)
var _a, _b;
if ((options === null || options === void 0 ? void 0 : options.scope) === config_1.SCOPE_ALL)
throw new Error(`"${config_1.SCOPE_ALL}" is not a valid scope name for a provider`);
this.scope = (_c = (_b = options) === null || _b === void 0 ? void 0 : _b.scope, (_c !== null && _c !== void 0 ? _c : config_1.DEFAULTS.scope));
this.indentation = (_e = (_d = options) === null || _d === void 0 ? void 0 : _d.indentation, (_e !== null && _e !== void 0 ? _e : config_1.DEFAULTS.indentation));
this.scope = (_a = options === null || options === void 0 ? void 0 : options.scope) !== null && _a !== void 0 ? _a : config_1.DEFAULTS.scope;
this.indentation = (_b = options === null || options === void 0 ? void 0 : options.indentation) !== null && _b !== void 0 ? _b : config_1.DEFAULTS.indentation;
this.handlers = [];

@@ -17,0 +17,0 @@ this.init();

@@ -10,7 +10,7 @@ "use strict";

constructor(options) {
var _a, _b;
var _a;
super(options);
if (!options.storage)
throw new Error('You need to pass a storage instance');
this.id = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.id, (_b !== null && _b !== void 0 ? _b : config_1.DEFAULTS.id));
this.id = (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : config_1.DEFAULTS.id;
this.storage = options.storage;

@@ -17,0 +17,0 @@ }

{
"name": "configuration",
"description": "Performant and feature rich library for managing configurations/settings.",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/index.js",

@@ -49,6 +49,6 @@ "types": "dist/index.d.ts",

"dependencies": {
"ajv": "^6.10.2",
"ajv": "^6.12.0",
"ajv-filter": "^1.1.0",
"chokidar-watcher": "^1.1.0",
"graceful-fs": "^4.2.2",
"chokidar-watcher": "^1.1.2",
"graceful-fs": "^4.2.3",
"is-primitive": "^3.0.1",

@@ -59,4 +59,4 @@ "json5": "^2.1.1",

"plain-object-is-equal": "^1.0.0",
"plain-object-merge": "^1.0.0",
"write-file-atomic": "^3.0.0"
"plain-object-merge": "^1.0.1",
"write-file-atomic": "^3.0.3"
},

@@ -68,17 +68,17 @@ "peerDependencies": {

"@types/graceful-fs": "^4.1.3",
"@types/json-schema": "^7.0.3",
"@types/json-schema": "^7.0.4",
"@types/json5": "0.0.30",
"@types/node": "^12.7.11",
"@types/write-file-atomic": "^2.1.2",
"@types/node": "^13.9.0",
"@types/write-file-atomic": "^3.0.0",
"ava": "^2.4.0",
"ava-spec": "^1.1.1",
"benchloop": "^1.2.0",
"benchloop": "^1.3.1",
"delay": "^4.3.0",
"lodash": "^4.17.15",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"tempy": "^0.3.0",
"typescript": "^3.7.0-beta",
"nyc": "^15.0.0",
"rimraf": "^3.0.2",
"tempy": "^0.4.0",
"typescript": "^3.8.3",
"typescript-transform-export-interop": "^1.0.2"
}
}

@@ -13,3 +13,3 @@ # Configuration

- **Scopes**: a single configuration instance can have multiple providers, so for example a `global + local` setup can be implemented easily.
- **Schema**: an optional [JSON schema](https://json-schema.org) can be used, and individual entries will get ignored automatically if they don't match the schema.
- **Schema**: an optional [JSON schema](https://json-schema.org) can be used, and individual entries will be ignored automatically if they don't match the schema.
- **Path props**: path props (`foo.bar`) are supported for retrieving/setting/deleting entries.

@@ -26,3 +26,3 @@ - **Flat objects**: flat objects (`{ 'foo.bar': true, 'foo.baz': false }`) are supported transparently too.

For now you'll have to browse the [test suite](https://github.com/fabiospampinato/configuration/test) to check out exactly how to use this library.
For now you'll have to browse the [test suite](https://github.com/fabiospampinato/configuration/blob/master/test/index.js) to check out exactly how to use this library.

@@ -29,0 +29,0 @@ //TODO: Write some actual usage instructions

@@ -20,2 +20,4 @@

/* VARIABLES */
providers: Provider[];

@@ -30,2 +32,4 @@ scopes: Scopes;

/* CONSTRUCTOR */
constructor ( options: Partial<Options> ) {

@@ -67,2 +71,20 @@

/* HELPERS */
_getTargetScopeForPath ( path: Path ): Scope {
for ( let i = 0, l = this.providers.length - 1; i < l; i++ ) {
const {scope} = this.providers[i];
if ( this.has ( scope, path ) ) return scope;
}
return this.scope;
}
/* API */
init (): void {

@@ -268,3 +290,3 @@

if ( Type.isUndefined ( value ) ) return this.set ( this.scope, scope, path ); // Path
if ( Type.isUndefined ( value ) ) return this.set ( this._getTargetScopeForPath ( scope ), scope, path ); // Path

@@ -312,3 +334,3 @@ if ( !Type.isString ( path ) ) return; //TSC

if ( Type.isUndefined ( path ) ) return this.remove ( this.scope, scope ); // Path
if ( Type.isUndefined ( path ) ) return this.remove ( SCOPE_ALL, scope ); // Path

@@ -315,0 +337,0 @@ if ( scope === SCOPE_ALL ) { // All

@@ -38,34 +38,38 @@

benchmark ({
name: 'constructor:basic',
iterations: 1,
fn: () => {
new Configuration ({
providers: [
new ProviderMemory ({ scope: 'foo' })
]
});
}
});
benchmark.group ( 'constructor', () => {
benchmark ({
name: 'constructor:advanced',
iterations: 1,
fn: () => {
new Configuration ({
providers: [
new ProviderMemory ({ scope: 'foo' })
],
defaults: Fixtures.defaults,
schema: Fixtures.schema
});
}
});
benchmark ({
name: 'basic',
iterations: 1,
fn: () => {
new Configuration ({
providers: [
new ProviderMemory ({ scope: 'foo' })
]
});
}
});
benchmark ({
name: 'constructor:json',
iterations: 1,
fn: ctx => {
ctx.conf = new Configuration ( Fixtures.options );
}
benchmark ({
name: 'advanced',
iterations: 1,
fn: () => {
new Configuration ({
providers: [
new ProviderMemory ({ scope: 'foo' })
],
defaults: Fixtures.defaults,
schema: Fixtures.schema
});
}
});
benchmark ({
name: 'json',
iterations: 1,
fn: ctx => {
ctx.conf = new Configuration ( Fixtures.options );
}
});
});

@@ -113,158 +117,175 @@

benchmark ({
name: 'get:all',
fn: ctx => {
ctx.conf.get ();
}
});
benchmark.group ( 'get', () => {
benchmark ({
name: 'get:*',
fn: ctx => {
ctx.conf.get ( '*' );
}
});
benchmark ({
name: 'all',
fn: ctx => {
ctx.conf.get ();
}
});
benchmark ({
name: 'get:*:path',
fn: ctx => {
ctx.conf.get ( '*', 'core.foo' );
}
});
benchmark ({
name: '*',
fn: ctx => {
ctx.conf.get ( '*' );
}
});
benchmark ({
name: 'get:scope:path',
fn: ctx => {
ctx.conf.get ( 'global', 'core.foo' );
}
});
benchmark ({
name: '*:path',
fn: ctx => {
ctx.conf.get ( '*', 'core.foo' );
}
});
benchmark ({
name: 'get:path',
fn: ctx => {
ctx.conf.get ( 'core.foo' );
}
});
benchmark ({
name: 'scope:path',
fn: ctx => {
ctx.conf.get ( 'global', 'core.foo' );
}
});
benchmark ({
name: 'has:*:path',
fn: ctx => {
ctx.conf.has ( '*', 'core.foo' );
}
});
benchmark ({
name: 'path',
fn: ctx => {
ctx.conf.get ( 'core.foo' );
}
});
benchmark ({
name: 'has:scope:path',
fn: ctx => {
ctx.conf.has ( 'global', 'core.foo' );
}
});
benchmark ({
name: 'has:path',
fn: ctx => {
ctx.conf.has ( 'core.foo' );
}
});
benchmark.group ( 'has', () => {
benchmark ({
name: 'set:*:path',
fn: ctx => {
ctx.conf.set ( '*', 'core.foo', 'test' );
ctx.conf.set ( '*', 'core.foo', 'test' );
}
});
benchmark ({
name: '*:path',
fn: ctx => {
ctx.conf.has ( '*', 'core.foo' );
}
});
benchmark ({
name: 'set:scope:path',
fn: ctx => {
ctx.conf.set ( 'global', 'core.foo', 'test' );
ctx.conf.set ( 'global', 'core.foo', 'test' );
}
});
benchmark ({
name: 'scope:path',
fn: ctx => {
ctx.conf.has ( 'global', 'core.foo' );
}
});
benchmark ({
name: 'set:path',
fn: ctx => {
ctx.conf.set ( 'core.foo', 'test' );
ctx.conf.set ( 'core.foo', 'test' );
}
});
benchmark ({
name: 'path',
fn: ctx => {
ctx.conf.has ( 'core.foo' );
}
});
benchmark ({
name: 'remove:*:path',
fn: ctx => {
ctx.conf.remove ( '*', 'core.foo' );
ctx.conf.remove ( '*', 'core.foo' );
}
});
benchmark ({
name: 'remove:scope:path',
fn: ctx => {
ctx.conf.remove ( 'global', 'core.foo' );
ctx.conf.remove ( 'global', 'core.foo' );
}
});
benchmark.group ( 'set', () => {
benchmark ({
name: 'remove:*:path',
fn: ctx => {
ctx.conf.remove ( 'core.foo' );
ctx.conf.remove ( 'core.foo' );
}
});
benchmark ({
name: '*:path',
fn: ctx => {
ctx.conf.set ( '*', 'core.foo', 'test' );
ctx.conf.set ( '*', 'core.foo', 'test' );
}
});
benchmark ({
name: 'update:*',
fn: ctx => {
ctx.conf.update ( '*', {} );
}
});
benchmark ({
name: 'scope:path',
fn: ctx => {
ctx.conf.set ( 'global', 'core.foo', 'test' );
ctx.conf.set ( 'global', 'core.foo', 'test' );
}
});
benchmark ({
name: 'update:scope:obj',
fn: ctx => {
ctx.conf.update ( 'global', {} );
ctx.conf.update ( 'global', {} );
}
});
benchmark ({
name: 'path',
fn: ctx => {
ctx.conf.set ( 'core.foo', 'test' );
ctx.conf.set ( 'core.foo', 'test' );
}
});
benchmark ({
name: 'update:obj',
fn: ctx => {
ctx.conf.update ({});
ctx.conf.update ({});
}
});
benchmark ({
name: 'update:str',
fn: ctx => {
ctx.conf.update ( '{}' );
ctx.conf.update ( '{}' );
ctx.conf.update ( '{ /* foo */ }' );
ctx.conf.update ( '{ /* foo */ }' );
}
});
benchmark.group ( 'remove', () => {
benchmark ({
name: 'reset:*',
fn: ctx => {
ctx.conf.reset ( '*' );
}
benchmark ({
name: '*:path',
fn: ctx => {
ctx.conf.remove ( '*', 'core.foo' );
ctx.conf.remove ( '*', 'core.foo' );
}
});
benchmark ({
name: 'scope:path',
fn: ctx => {
ctx.conf.remove ( 'global', 'core.foo' );
ctx.conf.remove ( 'global', 'core.foo' );
}
});
benchmark ({
name: '*:path',
fn: ctx => {
ctx.conf.remove ( 'core.foo' );
ctx.conf.remove ( 'core.foo' );
}
});
});
benchmark ({
name: 'reset:*',
fn: ctx => {
ctx.conf.reset ( '*' );
}
benchmark.group ( 'update', () => {
benchmark ({
name: '*',
fn: ctx => {
ctx.conf.update ( '*', {} );
}
});
benchmark ({
name: 'scope:obj',
fn: ctx => {
ctx.conf.update ( 'global', {} );
ctx.conf.update ( 'global', {} );
}
});
benchmark ({
name: 'obj',
fn: ctx => {
ctx.conf.update ({});
ctx.conf.update ({});
}
});
benchmark ({
name: 'str',
fn: ctx => {
ctx.conf.update ( '{}' );
ctx.conf.update ( '{}' );
ctx.conf.update ( '{ /* foo */ }' );
ctx.conf.update ( '{ /* foo */ }' );
}
});
});
benchmark ({
name: 'reset:scope',
fn: ctx => {
ctx.conf.reset ( 'global' );
}
benchmark.group ( 'reset', () => {
benchmark ({
name: '*',
fn: ctx => {
ctx.conf.reset ( '*' );
}
});
benchmark ({
name: 'scope',
fn: ctx => {
ctx.conf.reset ( 'global' );
}
});
});

@@ -293,1 +314,3 @@

});
benchmark.summary ();

@@ -490,9 +490,29 @@

t.is ( conf.get ( 'global', 'core.test' ), 0 );
t.is ( conf.get ( 'local', 'core.test' ), undefined );
t.is ( conf.get ( 'core.test' ), 0 );
});
it ( 'can set in the first appropriate scope', t => {
const conf = new Configuration ( Fixtures.options );
conf.set ( 'core.foo', 'test' );
t.is ( conf.get ( 'global', 'core.foo' ), 'test' );
t.is ( conf.get ( 'core.foo' ), 'local' );
t.is ( conf.get ( 'global', 'core.foo' ), 'global' );
t.is ( conf.get ( 'local', 'core.foo' ), 'test' );
t.is ( conf.get ( 'core.foo' ), 'test' );
conf.set ( 'core.bar', 'test' );
t.is ( conf.get ( 'global', 'core.bar' ), 'test' );
t.is ( conf.get ( 'local', 'core.bar' ), undefined );
t.is ( conf.get ( 'core.bar' ), 'test' );
conf.set ( 'core.qux', 'test' );
t.is ( conf.get ( 'global', 'core.qux' ), 'test' );
t.is ( conf.get ( 'local', 'core.qux' ), undefined );
t.is ( conf.get ( 'core.qux' ), 'test' );
});

@@ -554,3 +574,3 @@

it ( 'can remove in the default scope', t => {
it ( 'will remove in all scopes by default', async t => {

@@ -562,4 +582,17 @@ const conf = new Configuration ( Fixtures.options );

t.is ( conf.get ( 'global', 'core.foo' ), undefined );
t.is ( conf.get ( 'core.foo' ), 'local' );
t.is ( conf.get ( 'local', 'core.foo' ), undefined );
t.is ( conf.get ( 'core.foo' ), 'defaults' );
conf.remove ( 'core.bar' );
t.is ( conf.get ( 'global', 'core.bar' ), undefined );
t.is ( conf.get ( 'local', 'core.bar' ), undefined );
t.is ( conf.get ( 'core.bar' ), 'defaults' );
conf.remove ( 'core.qux' );
t.is ( conf.get ( 'global', 'core.qux' ), undefined );
t.is ( conf.get ( 'local', 'core.qux' ), undefined );
t.is ( conf.get ( 'core.qux' ), 'defaults' );
});

@@ -566,0 +599,0 @@

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