Skip to content

Commit f23da93

Browse files
feat: add ESM support for named exports
* fix variety of missing imports in both TS and CJS endpoints * add exports testing * renaming `Set` to `set` to avoid conflicts in CSJ endpoint and harmonize with other endpoints Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 346ff4a commit f23da93

21 files changed

+614
-99
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test/*.ts
1+
test/exports/dist/

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ jobs:
1010
# npm will not run under 10.x or earlier and so they cannot be tested
1111
node-version:
1212
- 12.x
13-
- 13.x
1413
- 14.x
15-
- 15.x
1614
- 16.x
1715
- 18.x
16+
- 20.x
1817
- latest
1918

2019
runs-on: ubuntu-latest
2120

2221
steps:
23-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2423

2524
- name: Set up Node.js ${{ matrix.node-version }}
26-
uses: actions/setup-node@v3
25+
uses: actions/setup-node@v4
2726
with:
2827
node-version: ${{ matrix.node-version }}
2928

@@ -32,4 +31,5 @@ jobs:
3231
npm i
3332
npm run lint
3433
npm test
35-
npm run test:types
34+
# Typescript does not work with node 12.x
35+
[[ "${{ matrix.node-version }}" != "12.x" ]] && npm run test:exports || true

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.40.0 (provisional)
4+
5+
* Adding ESM named exports support (@jerome-benoit).
6+
* Fixing `Set` operations CommonJS named export collision by renaming it to `set` (@jerome-benoit).
7+
* Fixing missing `Uint8Vector`, `Uint8ClampedVector`, `Int8Vector`, `Uint16Vector`, `Int16Vector`, `Uint32Vector`, `Int32Vector`, `Float32Vector`, `Float64Vector`, `PointerVector` CommonJS named exports (@jerome-benoit).
8+
* Fixing missing `PointerVector` TS exports (@jerome-benoit).
9+
310
## 0.39.8
411

512
* Fixing `Float64Vector` TS exports (@atombrenner).

benchmark/interval-tree/performance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ console.log('Intervals:', SIZE);
2222
console.time('StaticIntervalTree.from');
2323
var tree = StaticIntervalTree.from(INTERVALS);
2424
console.timeEnd('StaticIntervalTree.from');
25-
console.log('Tree height: ' + tree.height)
25+
console.log('Tree height: ' + tree.height);
2626

2727
p = random(0, MAX);
2828

benchmark/misc/dynamic-arrays.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var SIZE = 100000
1+
var SIZE = 100000;
22

33
function Wrapper() {
44
this.array = new Float64Array(SIZE);

benchmark/misc/hashmap.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ function exponentialSearch(array, key) {
5555
return -1;
5656
}
5757

58-
function interpolationSearch(arrayToSearch, valueToSearch){
58+
function interpolationSearch(arrayToSearch, valueToSearch) {
5959
var length = arrayToSearch.length;
6060
var low = 0;
61-
var high = length-1;
61+
var high = length - 1;
6262
var position = -1;
6363
var delta = -1;
64-
while(low <= high
64+
while (low <= high
6565
&& valueToSearch >= arrayToSearch[low]
66-
&& valueToSearch <= arrayToSearch[high]){
67-
delta = (valueToSearch-arrayToSearch[low])/(arrayToSearch[high]-arrayToSearch[low]);
68-
position = low + Math.floor((high-low)*delta);
69-
if (arrayToSearch[position] == valueToSearch){
66+
&& valueToSearch <= arrayToSearch[high]) {
67+
delta = (valueToSearch - arrayToSearch[low]) / (arrayToSearch[high] - arrayToSearch[low]);
68+
position = low + Math.floor((high - low) * delta);
69+
if (arrayToSearch[position] == valueToSearch) {
7070
return position;
7171
}
72-
if (arrayToSearch[position] < valueToSearch){
72+
if (arrayToSearch[position] < valueToSearch) {
7373
low = position + 1;
7474
} else {
7575
high = position - 1;
@@ -104,7 +104,7 @@ function optimized(array, value, lo, hi) {
104104
}
105105

106106
return -1;
107-
};
107+
}
108108

109109
function better(array, key) {
110110
var mid = -1;
@@ -123,7 +123,7 @@ function better(array, key) {
123123
else if (key > current)
124124
lo = mid + 1;
125125
else
126-
return mid
126+
return mid;
127127
}
128128

129129
return -1;
@@ -145,7 +145,7 @@ function PerfectMap(strings) {
145145
PerfectMap.prototype.set = function(key, value) {
146146
var index = binarySearch(this.hashes, fnv32a(key));
147147
this.values[index] = value;
148-
}
148+
};
149149

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

161161
perfect.set('hello', 36);
162-
console.log(perfect.get('hello'))
162+
console.log(perfect.get('hello'));
163163

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

219219
var h = 5381,
220-
i = str.length;
220+
i = str.length;
221221

222-
while(i) {
222+
while (i) {
223223
h *= 33;
224224
h ^= str.charCodeAt(--i);
225225
}
@@ -298,7 +298,7 @@ console.timeEnd('Get');
298298

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

304304
console.time('GetMap');
@@ -313,7 +313,7 @@ console.timeEnd('GetMap');
313313

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

319319
console.time('MissesMap');

bi-map.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export class InverseMap<K, V> implements Iterable<[K, V]> {
88
size: number;
99
inverse: BiMap<V, K>;
1010

11+
// Constructor
12+
constructor(original: BiMap<K, V>);
13+
1114
// Methods
1215
clear(): void;
1316
set(key: K, value: V): this;

experiments/critbit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function criticalGt(a, b) {
102102
}
103103

104104
function InternalNode(critical) {
105-
this.critical = critical
105+
this.critical = critical;
106106
this.left = null;
107107
this.right = null;
108108
}
@@ -270,7 +270,7 @@ CritBitTree.prototype.delete = function(key) {
270270

271271
var node = this.root,
272272
parent = null,
273-
wentRightForParent = false
273+
wentRightForParent = false;
274274
grandparent = null,
275275
wentRightForGranparent = false;
276276

@@ -358,7 +358,7 @@ function log(tree) {
358358

359359
const title = printNode;
360360

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

363363
console.log(asciitree(tree.root, title, children));
364364
}

fibonacci-heap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,5 @@ MaxFibonacciHeap.from = function(iterable, comparator) {
317317
*/
318318
FibonacciHeap.MinFibonacciHeap = FibonacciHeap;
319319
FibonacciHeap.MaxFibonacciHeap = MaxFibonacciHeap;
320+
320321
module.exports = FibonacciHeap;

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array';
4444
export {default as SymSpell} from './symspell';
4545
export {default as Trie} from './trie';
4646
export {default as TrieMap} from './trie-map';
47-
export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector} from './vector';
47+
export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector} from './vector';
4848
export {default as VPTree} from './vp-tree';

0 commit comments

Comments
 (0)