+38
| 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)); | ||
| } |
+29
| 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"; |
+38
| 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", |
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
21780
15.38%9
80%235
64.34%0
-100%