configuration
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -23,3 +23,3 @@ "use strict"; | ||
this.handlers = []; | ||
this.isArray = Array.isArray(options.defaults); | ||
this.isArray = type_1.default.isArray(options.defaults); | ||
this.defaults = new memory_1.default({ scope: config_1.SCOPE_DEFAULTS }); | ||
@@ -108,3 +108,3 @@ this.defaults.writeSync(options.defaults ? path_prop_1.default.unflat(options.defaults) : {}, true); | ||
refresh() { | ||
const datas = this.providers.map(provider => provider.dataSchema).reverse(), datasFiltered = datas.filter(data => Array.isArray(data) === this.isArray); | ||
const datas = this.providers.map(provider => provider.dataSchema).reverse(), datasFiltered = datas.filter(data => type_1.default.isArray(data) === this.isArray); | ||
this.dataSchema = this.isArray ? Array.prototype.concat(...datasFiltered) : plain_object_merge_1.default(datasFiltered); | ||
@@ -118,3 +118,3 @@ this.triggerChange(); | ||
this.validator(clone); | ||
if (Array.isArray(clone)) | ||
if (type_1.default.isArray(clone)) | ||
return clone.filter(x => !type_1.default.isUndefined(x)); | ||
@@ -121,0 +121,0 @@ return clone; |
@@ -21,3 +21,13 @@ "use strict"; | ||
try { | ||
return JSON.stringify(data, undefined, this.indentation); | ||
if (!type_1.default.isArray(data)) | ||
return JSON.stringify(data, undefined, this.indentation); | ||
//TODO: Publish the following code as 2 separate packages | ||
const lines = data.map(item => JSON.stringify(item, undefined, ' ') | ||
.replace(/\[\s*?(?:\r?\n|\r)\s*/g, '[') | ||
.replace(/\s*?(?:\r?\n|\r)\s*]/g, ']') | ||
.replace(/{\s*?(?:\r?\n|\r)\s*/g, '{ ') | ||
.replace(/\s*?(?:\r?\n|\r)\s*}/g, ' }') | ||
.replace(/,\s*?(?:\r?\n|\r)\s*/g, ', ')); | ||
const indentation = type_1.default.isString(this.indentation) ? this.indentation : ' '.repeat(this.indentation || 0); | ||
return `[\n${indentation}${lines.join(`,\n${indentation}`)}\n]`; | ||
} | ||
@@ -24,0 +34,0 @@ catch (_a) { } |
import { ValueArray, ValueObject } from '../types'; | ||
declare const Type: { | ||
isNull(x: any): x is null; | ||
isArray(x: any): x is any[]; | ||
isObject(x: any): x is ValueArray | ValueObject; | ||
@@ -5,0 +6,0 @@ isString(x: any): x is string; |
@@ -10,2 +10,5 @@ "use strict"; | ||
}, | ||
isArray(x) { | ||
return Array.isArray(x); | ||
}, | ||
isObject(x) { | ||
@@ -12,0 +15,0 @@ return !isPrimitive(x); |
{ | ||
"name": "configuration", | ||
"description": "Performant and feature rich library for managing configurations/settings.", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/index.d.ts", |
@@ -43,3 +43,3 @@ | ||
this.isArray = Array.isArray ( options.defaults ); | ||
this.isArray = Type.isArray ( options.defaults ); | ||
@@ -196,3 +196,3 @@ this.defaults = new ProviderMemory ({ scope: SCOPE_DEFAULTS }); | ||
const datas = this.providers.map ( provider => provider.dataSchema ).reverse (), | ||
datasFiltered = datas.filter ( data => Array.isArray ( data ) === this.isArray ); | ||
datasFiltered = datas.filter ( data => Type.isArray ( data ) === this.isArray ); | ||
@@ -213,3 +213,3 @@ this.dataSchema = this.isArray ? Array.prototype.concat ( ...datasFiltered ) : merge ( datasFiltered ); | ||
if ( Array.isArray ( clone ) ) return clone.filter ( x => !Type.isUndefined ( x ) ); | ||
if ( Type.isArray ( clone ) ) return clone.filter ( x => !Type.isUndefined ( x ) ); | ||
@@ -216,0 +216,0 @@ return clone; |
@@ -36,4 +36,17 @@ | ||
return JSON.stringify ( data, undefined, this.indentation ); | ||
if ( !Type.isArray ( data ) ) return JSON.stringify ( data, undefined, this.indentation ); | ||
//TODO: Publish the following code as 2 separate packages | ||
const lines = data.map ( item => JSON.stringify ( item, undefined, ' ' ) | ||
.replace ( /\[\s*?(?:\r?\n|\r)\s*/g, '[' ) | ||
.replace ( /\s*?(?:\r?\n|\r)\s*]/g, ']' ) | ||
.replace ( /{\s*?(?:\r?\n|\r)\s*/g, '{ ' ) | ||
.replace ( /\s*?(?:\r?\n|\r)\s*}/g, ' }' ) | ||
.replace ( /,\s*?(?:\r?\n|\r)\s*/g, ', ' ) ); | ||
const indentation = Type.isString ( this.indentation ) ? this.indentation : ' '.repeat ( this.indentation || 0 ); | ||
return `[\n${indentation}${lines.join ( `,\n${indentation}` )}\n]`; | ||
} catch {} | ||
@@ -40,0 +53,0 @@ |
@@ -17,2 +17,8 @@ | ||
isArray ( x: any ): x is any[] { | ||
return Array.isArray ( x ); | ||
}, | ||
isObject ( x: any ): x is ValueArray | ValueObject { | ||
@@ -19,0 +25,0 @@ |
104340
2762