node-containerpattern
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -12,2 +12,10 @@ | ||
function _isPlainObject(obj) { | ||
return (obj && "object" == typeof obj && Object == obj.constructor); | ||
} | ||
function _isArray(obj) { | ||
return (obj && "object" == typeof obj && obj instanceof Array); | ||
} | ||
function _checkData(that, key, value) { | ||
@@ -31,3 +39,3 @@ | ||
if (!(value instanceof Object)) { | ||
if (!_isPlainObject(value)) { | ||
@@ -49,3 +57,3 @@ if ("string" !== typeof value) { | ||
if (!(value instanceof Array)) { | ||
if (!_isArray(value)) { | ||
@@ -132,3 +140,3 @@ if ("string" !== typeof value) { | ||
if ("object" === typeof value[i] && !(value[i] instanceof Array)) { | ||
if (_isPlainObject(value[i])) { | ||
value[i] = _checkDataRecursive(that, key + that.recursionSeparator + i, value[i]); | ||
@@ -162,3 +170,3 @@ } | ||
if (!(object instanceof Array) && !(object instanceof Map)) { | ||
if (_isPlainObject(object)) { | ||
@@ -178,5 +186,5 @@ for(var key in object) { | ||
if (value instanceof Array) { | ||
if (_isArray(value)) { | ||
result[key].type = "array"; | ||
result[key].content = (0 === value.length) ? [] : _extractDocumentation(that, fullKey, value); | ||
result[key].content = (0 === value.length) ? [] : value; | ||
} | ||
@@ -206,3 +214,3 @@ else { | ||
} | ||
else { | ||
else if (that === object || _isArray(object)) { | ||
@@ -221,5 +229,5 @@ object.forEach((value, key) => { | ||
if (value instanceof Array) { | ||
if (_isArray(value)) { | ||
result[key].type = "array"; | ||
result[key].content = (0 === value.length) ? [] : _extractDocumentation(that, fullKey, value); | ||
result[key].content = (0 === value.length) ? [] : value; | ||
} | ||
@@ -434,3 +442,3 @@ else { | ||
if (!(limit instanceof Array)) { | ||
if (!_isArray(limit)) { | ||
throw new Error("The \"" + key + "\" data has an invalid \"limit\" attribute"); | ||
@@ -457,3 +465,3 @@ } | ||
// if no more constraints, set | ||
if ("object" !== typeof value || value instanceof Array || 1 > Object.keys(value).length) { | ||
if ("object" !== typeof value || _isArray(value) || 1 > Object.keys(value).length) { | ||
@@ -488,3 +496,3 @@ let firstKey = keys.shift(); | ||
if ("object" !== typeof value || value instanceof Array) { | ||
if ("object" !== typeof value || _isArray(value)) { | ||
super.set(key, value); | ||
@@ -491,0 +499,0 @@ } |
{ | ||
"name": "node-containerpattern", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A 'Container pattern' object for a clean global use of data.", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
@@ -166,8 +166,9 @@ "use strict"; | ||
assert.deepStrictEqual({ fullkey: "testemptyarray", type: "array", documentation: "This is an empty array", content: [] }, container.documentation().testemptyarray, "normal running has invalid return for \"testemptyarray\""); | ||
assert.strictEqual("testnotemptyarray", container.documentation().testnotemptyarray.fullkey, "normal running has invalid fullkey for \"testnotemptyarray\""); | ||
assert.strictEqual("array", container.documentation().testnotemptyarray.type, "normal running has invalid type for \"testnotemptyarray\""); | ||
assert.strictEqual("", container.documentation().testnotemptyarray.documentation, "normal running has invalid documentation for \"testnotemptyarray\""); | ||
assert.deepStrictEqual([ "test", "test" ], container.documentation().testnotemptyarray.content, "normal running has invalid content for \"testnotemptyarray\""); | ||
assert.deepStrictEqual({ fullkey: "testnotemptyarray", type: "array", documentation: "", content: [ "test", "test" ] }, container.documentation().testnotemptyarray, "normal running has invalid return for \"testnotemptyarray\""); | ||
assert.strictEqual("array", container.documentation().testnotemptyarray.type, "normal running has invalid return for \"testnotemptyarray\""); | ||
assert.strictEqual("", container.documentation().testnotemptyarray.documentation, "normal running has invalid return for \"testnotemptyarray\""); | ||
assert.strictEqual(2, Object.keys(container.documentation().testnotemptyarray.content).length, "normal running has invalid return for \"testnotemptyarray\""); | ||
assert.deepStrictEqual({ fullkey: "testnotemptyarray.0", type: "string", documentation: "" }, container.documentation().testnotemptyarray.content[0], "normal running has invalid return for \"testnotemptyarray\""); | ||
// object | ||
@@ -177,5 +178,6 @@ | ||
assert.strictEqual("object", container.documentation().testnotemptyobject.type, "normal running has invalid return for \"testnotemptyobject\""); | ||
assert.strictEqual("", container.documentation().testnotemptyobject.documentation, "normal running has invalid return for \"testnotemptyobject\""); | ||
assert.strictEqual("object", container.documentation().testnotemptyobject.type, "normal running has invalid type for \"testnotemptyobject\""); | ||
assert.strictEqual("", container.documentation().testnotemptyobject.documentation, "normal running has invalid documentation for \"testnotemptyobject\""); | ||
assert.strictEqual(1, Object.keys(container.documentation().testnotemptyobject.content).length, "normal running has invalid return for \"testnotemptyobject\""); | ||
assert.strictEqual("testnotemptyobject", container.documentation().testnotemptyobject.fullkey, "normal running has invalid fullkey for \"testnotemptyobject\""); | ||
assert.deepStrictEqual({ fullkey: "testnotemptyobject.test", type: "string", documentation: "" }, container.documentation().testnotemptyobject.content.test, "normal running has invalid return for \"testnotemptyobject\""); | ||
@@ -519,2 +521,3 @@ assert.deepStrictEqual({ fullkey: "testnotinstanciedobject", type: "function", documentation: "" }, container.documentation().testnotinstanciedobject, "normal running has invalid return for \"testnotinstanciedobject\""); | ||
assert.doesNotThrow(() => { container.set("testskeletonarray", []); }, Error, "normal running with array skeleton throws an error"); | ||
assert.doesNotThrow(() => { container.set("testskeletonarray", [ "test", "test" ]); }, Error, "normal running with array skeleton throws an error"); | ||
assert.doesNotThrow(() => { container.set("testskeletonarray", "[\"test\", \"test2\"]"); }, Error, "normal running with array skeleton throws an error"); | ||
@@ -537,3 +540,4 @@ | ||
assert.doesNotThrow(() => { container.set("testskeletonobject", []); }, Error, "normal running with object skeleton throws an error"); | ||
assert.doesNotThrow(() => { container.set("testskeletonobject", {}); }, Error, "normal running with object skeleton throws an error"); | ||
assert.doesNotThrow(() => { container.set("testskeletonobject", { "test": "test" }); }, Error, "normal running with object skeleton throws an error"); | ||
assert.doesNotThrow(() => { container.set("testskeletonobject", "{ \"test\": \"test\"}"); }, Error, "normal running with object skeleton throws an error"); | ||
@@ -540,0 +544,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50091
769