object-deep-from-entries
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "object-deep-from-entries", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Make an object or collection from entries deeply.", | ||
"main": "object-deep-from-entries.js", | ||
"main": "objectDeepFromEntries.js", | ||
"repository": "octet-stream/object-deep-from-entries", | ||
"author": "Nick K. <nick.kruchinin@gmail.com>", | ||
"license": "MIT", | ||
"types": "object-deep-from-entries.d.ts", | ||
"types": "objectDeepFromEntries.d.ts", | ||
"keywords": [ | ||
"object", | ||
"deep", | ||
"entries", | ||
"from-entries", | ||
"object-from-entries", | ||
"convert", | ||
"collection" | ||
], | ||
"scripts": { | ||
@@ -11,0 +20,0 @@ "test": "node_modules/.bin/ava test.js", |
73
test.js
@@ -181,3 +181,3 @@ const test = require("ava") | ||
test("Should return a flat collection", t => { | ||
test("Should return a collection", t => { | ||
t.plan(1) | ||
@@ -274,1 +274,72 @@ | ||
}) | ||
test("Should create flat array from entries", t => { | ||
t.plan(1) | ||
const expected = ["Zero", "One", "Two", "Three"] | ||
const actual = objectDeepFromEntries([ | ||
[0, "Zero"], | ||
[1, "One"], | ||
[2, "Two"], | ||
[3, "Three"] | ||
]) | ||
t.deepEqual(actual, expected) | ||
}) | ||
test("Should create flat array with mixed values", t => { | ||
t.plan(1) | ||
const expected = [42, {number: 42}, "Some string"] | ||
const actual = objectDeepFromEntries([ | ||
[0, 42], | ||
["number", 42], | ||
[2, "Some string"] | ||
]) | ||
t.deepEqual(actual, expected) | ||
}) | ||
test("Should create deep array with mixed values", t => { | ||
t.plan(1) | ||
const expected = [42, {person: {name: "John Doe"}}, "Some string"] | ||
const actual = objectDeepFromEntries([ | ||
[ | ||
0, 42 | ||
], | ||
[ | ||
["person", "name"], "John Doe" | ||
], | ||
[ | ||
2, "Some string" | ||
] | ||
]) | ||
t.deepEqual(actual, expected) | ||
}) | ||
test("Should throw a TypeError when invoked without any arguments", t => { | ||
t.plan(3) | ||
const trap = () => objectDeepFromEntries() | ||
const err = t.throws(trap) | ||
t.true(err instanceof TypeError) | ||
t.is(err.message, "Expected an array of entries. Received undefined") | ||
}) | ||
test("Should throw an error when entries are not an array", t => { | ||
t.plan(3) | ||
const trap = () => objectDeepFromEntries({}) | ||
const err = t.throws(trap) | ||
t.true(err instanceof TypeError) | ||
t.is(err.message, "Expected an array of entries. Received object") | ||
}) |
13563
12
444