Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

2

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

2 - npm Package Compare versions

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 @@

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