Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

libtuple

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libtuple - npm Package Compare versions

Comparing version
0.0.4
to
0.0.5
+1
-1
package.json
{
"name": "libtuple",
"version": "0.0.4",
"version": "0.0.5",
"author": "Sean Morris",

@@ -5,0 +5,0 @@ "description": "Memory-efficient tuple implementation.",

@@ -81,3 +81,3 @@ # libtuple.js

* ~~The library cannot tell the difference between `null` and `undefined`~~.
* Purely scalar-based tuples are represented by strings, not objects.
* ~~Purely scalar-based tuples are represented by strings, not objects.~~

@@ -84,0 +84,0 @@ ## Building

+30
-15
const refTree = new WeakMap;
const scalarMap = new Map;
const terminator = Object.create(null);
const baseTuple = Object.create(null);
baseTuple.toString = () => '[Object Tuple]';
baseTuple[Symbol.toStringTag] = 'Tuple';
baseTuple.toString = Object.prototype.toString;
Object.freeze(terminator);
Object.freeze(baseTuple);
module.exports = function Tuple(...args)
{
const registry = new FinalizationRegistry(held => scalarMap.delete(held));
module.exports = function Tuple(...args){
if(new.target)

@@ -16,7 +20,2 @@ {

if(!args.length)
{
return '[]';
}
let prefix = null;

@@ -46,9 +45,8 @@ let mode = null;

}
else if(canMap)
{
prefix = JSON.stringify(part.map(p => `${typeof p}::${p}`))
}
else
{
if(canMap)
{
prefix = JSON.stringify(part.map(p => `${typeof p}::${p}`))
}
part = [arg];

@@ -71,3 +69,3 @@ }

map = maps.map;
if(prefix)

@@ -95,3 +93,16 @@ {

{
return part;
const result = Object.create(baseTuple);
Object.assign(result, {length:args.length, ...args});
Object.freeze(result);
if(!scalarMap.has(part))
{
registry.register(result, part);
scalarMap.set(part, new WeakRef(result));
return result;
}
else
{
return scalarMap.get(part).deref();
}
}

@@ -102,2 +113,3 @@

const result = Object.create(baseTuple);
Object.assign(result, {length:args.length, ...args});
Object.freeze(result);

@@ -114,2 +126,3 @@

const result = Object.create(baseTuple);
Object.assign(result, {length:args.length, ...args});
Object.freeze(result);

@@ -122,1 +135,3 @@

}
Object.defineProperty(module.exports, 'scalarsCached', {get: () => scalarMap.size});