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.7-alpha-1
to
0.0.7-alpha-2
+38
Dict.mjs
import Tuple from "./Tuple.mjs";
import { size, keys } from "./Tuple.mjs";
const base = Object.create(null);
base.toString = Object.prototype.toString;
base[Symbol.toStringTag] = 'Dict';
base[Symbol.iterator] = function() {
let index = 0;
return { next: () => {
const iteration = index++;
if(this[size] < index)
{
return { done: true };
}
return {value: [this[keys][iteration], this[this[keys][iteration]]], done: false };
}};
};
export default function Dict(obj = {})
{
if(new.target)
{
throw new Error('"Dict" is not a constructor. Create a Record by invoking the function directly.');
}
if(!obj || typeof obj !== 'object')
{
throw new Error('Parameter must be an object.');
}
const keys = Object.keys(obj);
const values = Object.values(obj);
const tagged = Tuple.bind({args: obj, base, length: keys.length, keys});
return tagged('dict', Tuple(...keys), Tuple(...values));
}
import Tuple from "./Tuple.mjs";
import { _index, size } from "./Tuple.mjs";
const base = Object.create(null);
base.toString = Object.prototype.toString;
base[Symbol.toStringTag] = 'Group';
base[Symbol.iterator] = function() {
let index = 0;
return { next: () => {
const iteration = index++;
if(this[size] < index)
{
return { done: true };
}
return { value: this[iteration], done: false };
}};
};
export default function Group(...args)
{
if(new.target)
{
throw new Error('"Group" is not a constructor. Create a Group by invoking the function directly.');
}
const tuples = args.map(a => Tuple(a)).sort((a, b) => a[_index] < b[_index] ? -1 : 1);
const tagged = Tuple.bind({args: tuples.map(t => t[0]), base});
return tagged(...tuples, 'group');
}
export { default as Tuple } from "./Tuple";
export { default as Group } from "./Group";
export { default as Record } from "./Record";
import Tuple from "./Tuple.mjs";
import { size, keys } from "./Tuple.mjs";
const base = Object.create(null);
base.toString = Object.prototype.toString;
base[Symbol.toStringTag] = 'Record';
base[Symbol.iterator] = function() {
let index = 0;
return { next: () => {
const iteration = index++;
if(this[size] < index)
{
return { done: true };
}
return {value: [this[keys][iteration], this[this[keys][iteration]]], done: false };
}};
};
export default function Record(obj = {})
{
if(new.target)
{
throw new Error('"Record" is not a constructor. Create a Record by invoking the function directly.');
}
if(!obj || typeof obj !== 'object')
{
throw new Error('Parameter must be an object.');
}
const entries = Object.fromEntries(Object.entries(obj).sort((a, b) => a[0] < b[0] ? -1 : 1));
const keys = Object.keys(entries);
const values = Object.values(entries);
const tagged = Tuple.bind({args: obj, base, length: keys.length, keys});
return tagged(Tuple(...keys), Tuple(...values), 'record');
}
+6
-2
{
"name": "libtuple",
"version": "0.0.7-alpha-1",
"version": "0.0.7-alpha-2",
"author": "Sean Morris",
"description": "Memory-efficient tuple implementation.",
"repository": "https://github.com/seanmorris/libtuple",
"main": "Tuple.mjs",
"main": "index.mjs",
"keywords":["tuples"],

@@ -15,2 +15,6 @@ "scripts": {

"Tuple.mjs",
"Group.mjs",
"Record.mjs",
"Dict.mjs",
"index.mjs",
"README.md",

@@ -17,0 +21,0 @@ "LICENSE",