Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/2] feat: ESM support: consolidate exports tests #219

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
64faf18
feat: add ESM support for default exports
Jan 2, 2024
7f1890a
fix: fix set ops exports
Jan 2, 2024
0dcfb1d
fix: add missing export
Jan 2, 2024
90213ff
fix: add missing module field in package.json
Jan 3, 2024
2e442de
test: add initial ESM and CommonJS import infrastructure
Jan 8, 2024
3ca8235
test: make named require test works
Jan 8, 2024
6e2a9f6
Merge branch 'master' of https://github.com/Yomguithereal/mnemonist i…
Jan 8, 2024
9103a18
build(ci): disable some eslint rules in import test files
Jan 8, 2024
7fc278e
test: make CommonJS import works
Jan 8, 2024
78a942c
refactor: code cleanup
Jan 8, 2024
815e0bb
test: add module import tests to CI
Jan 8, 2024
837ae22
refactor: code cleanups
Jan 9, 2024
76179e8
build(ci): remove non LTS node release
Jan 9, 2024
fbdaaa2
refactor: cleanup exports in package.json by using wildcards
Jan 9, 2024
e69fbe4
fix: add missing constructor to InverseMap type
Jan 9, 2024
d4ecdb9
test: improve a bit Heap coverage
Jan 9, 2024
4f8d31d
refactor: import cleanup
Jan 9, 2024
2888ac3
Merge branch 'master' of https://github.com/Yomguithereal/mnemonist i…
Jan 10, 2024
d3e9f6b
fix: use named CJS exports to improve tree shaking
Jan 10, 2024
c178c41
refactor: consistent coding style
Jan 10, 2024
5c8a49f
refactor: cleanup named exports mixed usage
Jan 15, 2024
4a7d98e
test: cleanup default require test
Jan 15, 2024
b6a96d9
refactor: indentation cleanup
Jan 15, 2024
95da864
test: consodidate exports testing code
Jan 15, 2024
89bd465
build(deps-dev): remove unneeded typescript dependencies
Jan 15, 2024
019592a
build(ci): avoid exports testing on node 12.x
Jan 15, 2024
c0c8f82
build(ci): avoid error > 0 with node 12.x
Jan 15, 2024
aba2f6b
refactor: trivial code cleanup
Jan 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ jobs:
# npm will not run under 10.x or earlier and so they cannot be tested
node-version:
- 12.x
- 13.x
- 14.x
- 15.x
- 16.x
- 18.x
- 20.x
- latest

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -32,4 +31,5 @@ jobs:
npm i
npm run lint
npm test
npm run test:types
# Typescript does not work with node 12.x
[[ "${{ matrix.node-version }}" != "12.x" ]] && npm run test:exports || true
2 changes: 1 addition & 1 deletion benchmark/interval-tree/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ console.log('Intervals:', SIZE);
console.time('StaticIntervalTree.from');
var tree = StaticIntervalTree.from(INTERVALS);
console.timeEnd('StaticIntervalTree.from');
console.log('Tree height: ' + tree.height)
console.log('Tree height: ' + tree.height);

p = random(0, MAX);

Expand Down
2 changes: 1 addition & 1 deletion benchmark/misc/dynamic-arrays.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var SIZE = 100000
var SIZE = 100000;

function Wrapper() {
this.array = new Float64Array(SIZE);
Expand Down
32 changes: 16 additions & 16 deletions benchmark/misc/hashmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ function exponentialSearch(array, key) {
return -1;
}

function interpolationSearch(arrayToSearch, valueToSearch){
function interpolationSearch(arrayToSearch, valueToSearch) {
var length = arrayToSearch.length;
var low = 0;
var high = length-1;
var high = length - 1;
var position = -1;
var delta = -1;
while(low <= high
while (low <= high
&& valueToSearch >= arrayToSearch[low]
&& valueToSearch <= arrayToSearch[high]){
delta = (valueToSearch-arrayToSearch[low])/(arrayToSearch[high]-arrayToSearch[low]);
position = low + Math.floor((high-low)*delta);
if (arrayToSearch[position] == valueToSearch){
&& valueToSearch <= arrayToSearch[high]) {
delta = (valueToSearch - arrayToSearch[low]) / (arrayToSearch[high] - arrayToSearch[low]);
position = low + Math.floor((high - low) * delta);
if (arrayToSearch[position] == valueToSearch) {
return position;
}
if (arrayToSearch[position] < valueToSearch){
if (arrayToSearch[position] < valueToSearch) {
low = position + 1;
} else {
high = position - 1;
Expand Down Expand Up @@ -104,7 +104,7 @@ function optimized(array, value, lo, hi) {
}

return -1;
};
}

function better(array, key) {
var mid = -1;
Expand All @@ -123,7 +123,7 @@ function better(array, key) {
else if (key > current)
lo = mid + 1;
else
return mid
return mid;
}

return -1;
Expand All @@ -145,7 +145,7 @@ function PerfectMap(strings) {
PerfectMap.prototype.set = function(key, value) {
var index = binarySearch(this.hashes, fnv32a(key));
this.values[index] = value;
}
};

PerfectMap.prototype.get = function(key, value) {
var index = binarySearch(this.hashes, fnv32a(key));
Expand All @@ -159,7 +159,7 @@ var map = new Map();
var sorted = words.slice().sort();

perfect.set('hello', 36);
console.log(perfect.get('hello'))
console.log(perfect.get('hello'));

console.time('Perfect set');
for (var i = 0; i < words.length; i++)
Expand Down Expand Up @@ -217,9 +217,9 @@ function hash(str) {
'use asm';

var h = 5381,
i = str.length;
i = str.length;

while(i) {
while (i) {
h *= 33;
h ^= str.charCodeAt(--i);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ console.timeEnd('Get');

console.time('GetObject');
for (var w = 0, y = words.length; w < y; w++)
v = ob[words[w]]
v = ob[words[w]];
console.timeEnd('GetObject');

console.time('GetMap');
Expand All @@ -313,7 +313,7 @@ console.timeEnd('GetMap');

console.time('MissesObject');
for (var w = 0, y = words.length; w < y; w++)
v = ob[randomString(4, 10)]
v = ob[randomString(4, 10)];
console.timeEnd('MissesObject');

console.time('MissesMap');
Expand Down
3 changes: 3 additions & 0 deletions bi-map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export class InverseMap<K, V> implements Iterable<[K, V]> {
size: number;
inverse: BiMap<V, K>;

// Constructor
constructor(original: BiMap<K, V>);

// Methods
clear(): void;
set(key: K, value: V): this;
Expand Down
6 changes: 3 additions & 3 deletions experiments/critbit.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function criticalGt(a, b) {
}

function InternalNode(critical) {
this.critical = critical
this.critical = critical;
this.left = null;
this.right = null;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ CritBitTree.prototype.delete = function(key) {

var node = this.root,
parent = null,
wentRightForParent = false
wentRightForParent = false;
grandparent = null,
wentRightForGranparent = false;

Expand Down Expand Up @@ -358,7 +358,7 @@ function log(tree) {

const title = printNode;

const children = node => (node instanceof ExternalNode ? null : [node.left , node.right]);
const children = node => (node instanceof ExternalNode ? null : [node.left, node.right]);

console.log(asciitree(tree.root, title, children));
}
Expand Down
1 change: 1 addition & 0 deletions fibonacci-heap.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,5 @@ MaxFibonacciHeap.from = function(iterable, comparator) {
*/
FibonacciHeap.MinFibonacciHeap = FibonacciHeap;
FibonacciHeap.MaxFibonacciHeap = MaxFibonacciHeap;

module.exports = FibonacciHeap;
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* Mnemonist Library Endpoint
* ===========================
* Mnemonist Library Endpoint (CommonJS)
* ======================================
*
* Exporting every data structure through a unified endpoint. Consumers
* of this library should prefer the modular access though.
*/
var Heap = require('./heap.js'),
FibonacciHeap = require('./fibonacci-heap.js'),
SuffixArray = require('./suffix-array.js');
SuffixArray = require('./suffix-array.js'),
Vector = require('./vector.js');

module.exports = {
BiMap: require('./bi-map.js'),
Expand Down Expand Up @@ -46,13 +47,23 @@ module.exports = {
Stack: require('./stack.js'),
SuffixArray: SuffixArray,
GeneralizedSuffixArray: SuffixArray.GeneralizedSuffixArray,
Set: require('./set.js'),
set: require('./set.js'),
SparseQueueSet: require('./sparse-queue-set.js'),
SparseMap: require('./sparse-map.js'),
SparseSet: require('./sparse-set.js'),
SymSpell: require('./symspell.js'),
Trie: require('./trie.js'),
TrieMap: require('./trie-map.js'),
Vector: require('./vector.js'),
Vector: Vector,
Uint8Vector: Vector.Uint8Vector,
Uint8ClampedVector: Vector.Uint8ClampedVector,
Int8Vector: Vector.Int8Vector,
Uint16Vector: Vector.Uint16Vector,
Int16Vector: Vector.Int16Vector,
Uint32Vector: Vector.Uint32Vector,
Int32Vector: Vector.Int32Vector,
Float32Vector: Vector.Float32Vector,
Float64Vector: Vector.Float64Vector,
PointerVector: Vector.PointerVector,
VPTree: require('./vp-tree.js')
};
67 changes: 67 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Mnemonist Library Endpoint (ESM)
* =================================
*
* Exporting every data structure through a unified endpoint.
*/
import * as set from './set.js';
import {default as FibonacciHeap} from './fibonacci-heap.js';
const MinFibonacciHeap = FibonacciHeap.MinFibonacciHeap;
const MaxFibonacciHeap = FibonacciHeap.MaxFibonacciHeap;
import {default as Heap} from './heap.js';
const MinHeap = Heap.MinHeap;
const MaxHeap = Heap.MaxHeap;
import {default as SuffixArray} from './suffix-array.js';
const GeneralizedSuffixArray = SuffixArray.GeneralizedSuffixArray;
import {default as Vector} from './vector.js';
const Uint8Vector = Vector.Uint8Vector;
const Uint8ClampedVector = Vector.Uint8ClampedVector;
const Int8Vector = Vector.Int8Vector;
const Uint16Vector = Vector.Uint16Vector;
const Int16Vector = Vector.Int16Vector;
const Uint32Vector = Vector.Uint32Vector;
const Int32Vector = Vector.Int32Vector;
const Float32Vector = Vector.Float32Vector;
const Float64Vector = Vector.Float64Vector;
const PointerVector = Vector.PointerVector;

export {default as BiMap} from './bi-map.js';
export {default as BitSet} from './bit-set.js';
export {default as BitVector} from './bit-vector.js';
export {default as BloomFilter} from './bloom-filter.js';
export {default as BKTree} from './bk-tree.js';
export {default as CircularBuffer} from './circular-buffer.js';
export {default as DefaultMap} from './default-map.js';
export {default as DefaultWeakMap} from './default-weak-map.js';
export {default as FixedDeque} from './fixed-deque.js';
export {default as StaticDisjointSet} from './static-disjoint-set.js';
export {FibonacciHeap, MinFibonacciHeap, MaxFibonacciHeap};
export {default as FixedReverseHeap} from './fixed-reverse-heap.js';
export {default as FuzzyMap} from './fuzzy-map.js';
export {default as FuzzyMultiMap} from './fuzzy-multi-map.js';
export {default as HashedArrayTree} from './hashed-array-tree.js';
export {Heap, MinHeap, MaxHeap};
export {default as StaticIntervalTree} from './static-interval-tree.js';
export {default as InvertedIndex} from './inverted-index.js';
export {default as KDTree} from './kd-tree.js';
export {default as LinkedList} from './linked-list.js';
export {default as LRUCache} from './lru-cache.js';
export {default as LRUCacheWithDelete} from './lru-cache-with-delete.js';
export {default as LRUMap} from './lru-map.js';
export {default as LRUMapWithDelete} from './lru-map-with-delete.js';
export {default as MultiMap} from './multi-map.js';
export {default as MultiSet} from './multi-set.js';
export {default as PassjoinIndex} from './passjoin-index.js';
export {default as Queue} from './queue.js';
export {default as FixedStack} from './fixed-stack.js';
export {default as Stack} from './stack.js';
export {SuffixArray, GeneralizedSuffixArray};
export {set};
export {default as SparseQueueSet} from './sparse-queue-set.js';
export {default as SparseMap} from './sparse-map.js';
export {default as SparseSet} from './sparse-set.js';
export {default as SymSpell} from './symspell.js';
export {default as Trie} from './trie.js';
export {default as TrieMap} from './trie-map.js';
export {Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector};
export {default as VPTree} from './vp-tree.js';
Loading