Comparing version 1.0.0 to 1.0.1
12
map.js
@@ -10,2 +10,6 @@ 'use strict' | ||
* Set to null to throw an error instead. | ||
* @param {bool} [options.detectPairs=true] | ||
* This option only applies if `thingToConvert` is an array. | ||
* If set to `true`, an array of two-element arrays (the kind that’s used | ||
* to construct a Map) will be treated as an array of key-value entries. | ||
* @param {bool} [options.mirror=false] | ||
@@ -18,3 +22,3 @@ * This option only applies if `thingToConvert` is an array. | ||
*/ | ||
module.exports = function (thingToConvert, {fallback = new Map(), mirror = false} = {}) { | ||
module.exports = function (thingToConvert, {fallback = new Map(), detectPairs = true, mirror = false} = {}) { | ||
if (thingToConvert instanceof Map) { | ||
@@ -25,6 +29,6 @@ return thingToConvert | ||
if (Array.isArray(thingToConvert)) { | ||
if (mirror) { | ||
if (detectPairs && thingToConvert.every(item => Array.isArray(item) && item.length === 2)) { | ||
return new Map(thingToConvert) | ||
} else if (mirror) { | ||
return new Map(thingToConvert.map(item => [item, item])) | ||
} else if (thingToConvert.every(item => Array.isArray(item) && item.length === 2)) { | ||
return new Map(thingToConvert) | ||
} else { | ||
@@ -31,0 +35,0 @@ return new Map(thingToConvert.map((item, index) => [index, item])) |
@@ -17,2 +17,4 @@ 'use strict' | ||
* If `false`, array indices (0 to n-1) are used as the object keys. | ||
* If some array values have types which are among those supported as | ||
* object keys (strings, numbers, and symbols), then mirroring will not happen. | ||
* @return {object} | ||
@@ -38,3 +40,3 @@ */ | ||
return object | ||
} else if (mirror && thingToConvert.every(value => typeof value === 'string')) { | ||
} else if (mirror && thingToConvert.every(value => ['string', 'number', 'symbol'].includes(typeof value))) { | ||
const object = {} | ||
@@ -41,0 +43,0 @@ for (const value of thingToConvert) { |
{ | ||
"name": "2", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "The Type Conversion Library. Numbers, Strings, Arrays, Maps, Objects, and Iterators.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -273,6 +273,7 @@ 'use strict' | ||
it('should only `mirror` values to keys if all values are strings', function () { | ||
const object = toObject(['100', 200], {mirror: true}) | ||
it('should only `mirror` values to keys if all values can be object keys', function () { | ||
const nonKeyable = {} | ||
const object = toObject(['100', nonKeyable], {mirror: true}) | ||
assert.strictEqual(object[0], '100') | ||
assert.strictEqual(object[1], 200) | ||
assert.strictEqual(object[1], nonKeyable) | ||
}) | ||
@@ -279,0 +280,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
30647
600
0