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 3.1.1 to 3.1.2

17

dist/index.js

@@ -232,7 +232,12 @@ /* IMPORT */

const value = data.getter();
if (isEqual(data.value, value))
continue;
const clone = Type.isPrimitive(value) ? value : cloneDeep(value);
data.callback(clone, data.value);
data.value = clone;
if (Type.isNullary(data.callback)) { //TODO: This is not exactly correct, something might have been changed while the flattened configuration could still be the same, but it's much faster
data.callback();
}
else {
if (isEqual(data.value, value))
continue;
const clone = Type.isPrimitive(value) ? value : cloneDeep(value);
data.callback(clone, data.value);
data.value = clone;
}
}

@@ -247,3 +252,3 @@ }

const valueRaw = getter();
const value = Type.isPrimitive(valueRaw) ? valueRaw : cloneDeep(valueRaw);
const value = !Type.isNullary(callback) ? (Type.isPrimitive(valueRaw) ? valueRaw : cloneDeep(valueRaw)) : undefined;
const data = { callback, getter, value };

@@ -250,0 +255,0 @@ handlers[handlers.length] = data;

@@ -33,3 +33,3 @@ import type { WriteOptions } from 'atomically/dist/types';

};
type ChangeHandler = (value: Value | undefined, valuePrev: Value | undefined) => void;
type ChangeHandler = ((value: Value | undefined, valuePrev: Value | undefined) => void) | (() => void);
type ChangeHandlerData = {

@@ -36,0 +36,0 @@ callback: ChangeHandler;

@@ -1,2 +0,2 @@

import { readFile, readFileSync, writeFile } from 'atomically';
import { readFile, readFileSync, writeFile, writeFileSync } from 'atomically';
import type { FSWatcher } from '../types';

@@ -7,5 +7,5 @@ declare const File: {

write: typeof writeFile;
writeSync: (filePath: string, data: import("atomically/dist/types").Data, options?: import("atomically/dist/types").WriteOptions | import("atomically/dist/types").Encoding | undefined) => void;
writeSync: typeof writeFileSync;
watch(filePath: string, callback: Function): FSWatcher;
};
export default File;
import type { ValueArray, ValueObject } from '../types';
declare const Type: {
isArray(value: unknown): value is unknown[];
isNull(value: unknown): value is null;
isArray(value: unknown): value is unknown[];
isObject(x: unknown): x is ValueArray | ValueObject;
isNullary(value: unknown): value is () => unknown;
isObject(value: unknown): value is ValueArray | ValueObject;
isPrimitive: (value: unknown) => value is string | number | bigint | boolean | symbol | null | undefined;
isString(x: unknown): x is string;
isUndefined(x: unknown): x is undefined;
isString(value: unknown): value is string;
isUndefined(value: unknown): value is undefined;
};
export default Type;

@@ -5,10 +5,13 @@ /* IMPORT */

/* API */
isArray(value) {
return Array.isArray(value);
},
isNull(value) {
return value === null;
},
isArray(value) {
return Array.isArray(value);
isNullary(value) {
return typeof value === 'function' && value.length === 0;
},
isObject(x) {
return !Type.isPrimitive(x);
isObject(value) {
return !Type.isPrimitive(value);
},

@@ -21,7 +24,7 @@ isPrimitive: (value) => {

},
isString(x) {
return typeof x === 'string';
isString(value) {
return typeof value === 'string';
},
isUndefined(x) {
return typeof x === 'undefined';
isUndefined(value) {
return typeof value === 'undefined';
}

@@ -28,0 +31,0 @@ };

@@ -5,3 +5,3 @@ {

"description": "Performant and feature rich library for managing configurations/settings.",
"version": "3.1.1",
"version": "3.1.2",
"type": "module",

@@ -101,3 +101,3 @@ "sideEffects": false,

"dependencies": {
"atomically": "^2.0.0",
"atomically": "^2.0.1",
"jsonc-simple-parser": "^3.0.0",

@@ -108,16 +108,16 @@ "path-prop": "^2.0.0",

"plain-object-merge": "^2.0.0",
"watcher": "^2.2.0"
"watcher": "^2.2.2"
},
"devDependencies": {
"@types/json-schema": "^7.0.11",
"@types/node": "^18.11.9",
"@types/node": "^18.16.0",
"ajv": "^6.12.2",
"ajv-filter": "^1.1.1",
"benchloop": "^2.0.0",
"fava": "^0.0.7",
"benchloop": "^2.1.0",
"fava": "^0.2.0",
"lodash": "^4.17.21",
"tempy": "^0.5.0",
"tsex": "^1.1.4",
"typescript": "^4.9.3"
"tsex": "^2.2.4",
"typescript": "^4.9.5"
}
}

@@ -403,10 +403,18 @@

if ( isEqual ( data.value, value ) ) continue;
if ( Type.isNullary ( data.callback ) ) { //TODO: This is not exactly correct, something might have been changed while the flattened configuration could still be the same, but it's much faster
const clone = Type.isPrimitive ( value ) ? value : cloneDeep ( value );
data.callback ();
data.callback ( clone, data.value );
} else {
data.value = clone;
if ( isEqual ( data.value, value ) ) continue;
const clone = Type.isPrimitive ( value ) ? value : cloneDeep ( value );
data.callback ( clone, data.value );
data.value = clone;
}
}

@@ -429,3 +437,3 @@

const valueRaw = getter ();
const value = Type.isPrimitive ( valueRaw ) ? valueRaw : cloneDeep ( valueRaw );
const value = !Type.isNullary ( callback ) ? ( Type.isPrimitive ( valueRaw ) ? valueRaw : cloneDeep ( valueRaw ) ) : undefined;
const data: ChangeHandlerData = {callback, getter, value};

@@ -432,0 +440,0 @@

@@ -48,3 +48,3 @@

type ChangeHandler = ( value: Value | undefined, valuePrev: Value | undefined ) => void;
type ChangeHandler = (( value: Value | undefined, valuePrev: Value | undefined ) => void) | (() => void);
type ChangeHandlerData = {

@@ -51,0 +51,0 @@ callback: ChangeHandler,

@@ -12,2 +12,8 @@

isArray ( value: unknown ): value is unknown[] {
return Array.isArray ( value );
},
isNull ( value: unknown ): value is null {

@@ -19,11 +25,11 @@

isArray ( value: unknown ): value is unknown[] {
isNullary ( value: unknown ): value is (() => unknown) {
return Array.isArray ( value );
return typeof value === 'function' && value.length === 0;
},
isObject ( x: unknown ): x is ValueArray | ValueObject {
isObject ( value: unknown ): value is ValueArray | ValueObject {
return !Type.isPrimitive ( x );
return !Type.isPrimitive ( value );

@@ -42,11 +48,11 @@ },

isString ( x: unknown ): x is string {
isString ( value: unknown ): value is string {
return typeof x === 'string';
return typeof value === 'string';
},
isUndefined ( x: unknown ): x is undefined {
isUndefined ( value: unknown ): value is undefined {
return typeof x === 'undefined';
return typeof value === 'undefined';

@@ -53,0 +59,0 @@ }

@@ -26,5 +26,4 @@

benchmark.defaultOptions = Object.assign ( benchmark.defaultOptions, {
iterations: 5000,
log: 'compact',
benchmark.config ({
iterations: 5_000,
beforeEach: ctx => {

@@ -31,0 +30,0 @@ ctx.conf = getConf ();

@@ -898,2 +898,23 @@

it ( 'calls a function when anything changes', t => {
let tests = 0;
const conf = new Configuration ( Fixtures.options () );
conf.onChange ( () => {
tests++;
});
t.is ( conf.handlers.length, 1 );
conf.set ( 'local', 'core.foo', 'test' );
conf.set ( 'local', 'core.foo', 'test' );
conf.set ( 'global', 'core.foo', 'test' );
conf.set ( 'global', 'conf', _.cloneDeep ( conf.get ( 'global', 'core' ) ) );
t.is ( tests, 3 );
});
it ( 'returns a disposer', t => {

@@ -900,0 +921,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