diff --git a/.eslintignore b/.eslintignore index 588f0767..3401c82b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -test/*.ts +test/exports/dist/ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d0db6e51..ff78870e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 05dff76a..a39213e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.40.0 (provisional) + +* Adding ESM named exports support (@jerome-benoit). +* Fixing `Set` operations CommonJS named export collision by renaming it to `set` (@jerome-benoit). +* Fixing missing `Uint8Vector`, `Uint8ClampedVector`, `Int8Vector`, `Uint16Vector`, `Int16Vector`, `Uint32Vector`, `Int32Vector`, `Float32Vector`, `Float64Vector`, `PointerVector` CommonJS named exports (@jerome-benoit). +* Fixing missing `PointerVector` TS exports (@jerome-benoit). + ## 0.39.8 * Fixing `Float64Vector` TS exports (@atombrenner). diff --git a/benchmark/interval-tree/performance.js b/benchmark/interval-tree/performance.js index 6f0e0c53..e6acb89f 100644 --- a/benchmark/interval-tree/performance.js +++ b/benchmark/interval-tree/performance.js @@ -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); diff --git a/benchmark/misc/dynamic-arrays.js b/benchmark/misc/dynamic-arrays.js index 5e554827..2c40263c 100644 --- a/benchmark/misc/dynamic-arrays.js +++ b/benchmark/misc/dynamic-arrays.js @@ -1,4 +1,4 @@ -var SIZE = 100000 +var SIZE = 100000; function Wrapper() { this.array = new Float64Array(SIZE); diff --git a/benchmark/misc/hashmap.js b/benchmark/misc/hashmap.js index fa2c0772..271dce58 100644 --- a/benchmark/misc/hashmap.js +++ b/benchmark/misc/hashmap.js @@ -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; @@ -104,7 +104,7 @@ function optimized(array, value, lo, hi) { } return -1; -}; +} function better(array, key) { var mid = -1; @@ -123,7 +123,7 @@ function better(array, key) { else if (key > current) lo = mid + 1; else - return mid + return mid; } return -1; @@ -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)); @@ -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++) @@ -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); } @@ -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'); @@ -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'); diff --git a/bi-map.d.ts b/bi-map.d.ts index a25246a2..6bc974c0 100644 --- a/bi-map.d.ts +++ b/bi-map.d.ts @@ -8,6 +8,9 @@ export class InverseMap implements Iterable<[K, V]> { size: number; inverse: BiMap; + // Constructor + constructor(original: BiMap); + // Methods clear(): void; set(key: K, value: V): this; diff --git a/experiments/critbit.js b/experiments/critbit.js index a5c57659..bee61f06 100644 --- a/experiments/critbit.js +++ b/experiments/critbit.js @@ -102,7 +102,7 @@ function criticalGt(a, b) { } function InternalNode(critical) { - this.critical = critical + this.critical = critical; this.left = null; this.right = null; } @@ -270,7 +270,7 @@ CritBitTree.prototype.delete = function(key) { var node = this.root, parent = null, - wentRightForParent = false + wentRightForParent = false; grandparent = null, wentRightForGranparent = false; @@ -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)); } diff --git a/fibonacci-heap.js b/fibonacci-heap.js index f41334f8..012151f8 100644 --- a/fibonacci-heap.js +++ b/fibonacci-heap.js @@ -317,4 +317,5 @@ MaxFibonacciHeap.from = function(iterable, comparator) { */ FibonacciHeap.MinFibonacciHeap = FibonacciHeap; FibonacciHeap.MaxFibonacciHeap = MaxFibonacciHeap; + module.exports = FibonacciHeap; diff --git a/index.d.ts b/index.d.ts index 57654a60..075fefc1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -44,5 +44,5 @@ export {default as SuffixArray, GeneralizedSuffixArray} from './suffix-array'; export {default as SymSpell} from './symspell'; export {default as Trie} from './trie'; export {default as TrieMap} from './trie-map'; -export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector} from './vector'; +export {default as Vector, Uint8Vector, Uint8ClampedVector, Int8Vector, Uint16Vector, Int16Vector, Uint32Vector, Int32Vector, Float32Vector, Float64Vector, PointerVector} from './vector'; export {default as VPTree} from './vp-tree'; diff --git a/index.js b/index.js index 75bf74e9..5eadce71 100644 --- a/index.js +++ b/index.js @@ -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'), @@ -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') }; diff --git a/index.mjs b/index.mjs new file mode 100644 index 00000000..5febfcfd --- /dev/null +++ b/index.mjs @@ -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'; diff --git a/package-lock.json b/package-lock.json index f964d65a..3af43532 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,12 @@ "version": "0.39.8", "license": "MIT", "dependencies": { - "obliterator": "^2.0.1" + "obliterator": "^2.0.4" }, "devDependencies": { "@yomguithereal/eslint-config": "^4.4.0", "asciitree": "^1.0.2", - "damerau-levenshtein": "^1.0.7", + "damerau-levenshtein": "^1.0.8", "eslint": "^8.2.0", "leven": "^3.1.0", "lodash": "^4.17.21", @@ -22,8 +22,7 @@ "mocha": "^9.1.3", "pandemonium": "^2.0.0", "seedrandom": "^3.0.5", - "static-kdtree": "^1.0.2", - "typescript": "^4.5.2" + "static-kdtree": "^1.0.2" } }, "node_modules/@eslint/eslintrc": { @@ -191,7 +190,7 @@ "node_modules/bit-twiddle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-1.0.2.tgz", - "integrity": "sha1-DGwfq+KyPRcXPZpht7cJPrnhdp4=", + "integrity": "sha512-B9UhK0DKFZhoTFcfvAzhqsjStvGJp9vYWf3+6SNTtdSQnvIgfkHbgHrg/e4+TH71N2GDu8tpmCVoyfrL1d7ntA==", "dev": true }, "node_modules/brace-expansion": { @@ -351,9 +350,9 @@ } }, "node_modules/damerau-levenshtein": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.7.tgz", - "integrity": "sha512-VvdQIPGdWP0SqFXghj79Wf/5LArmreyMsGLa6FG6iC4t3j7j5s71TrwWmT/4akbDQIqjfACkLZmjXhA7g2oUZw==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", + "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, "node_modules/debug": { @@ -578,12 +577,15 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz", - "integrity": "sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, "node_modules/espree": { @@ -899,7 +901,7 @@ "node_modules/inorder-tree-layout/node_modules/bit-twiddle": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-0.0.2.tgz", - "integrity": "sha1-wurruVKjuUrMFASX4c3NLxoz9Y4=", + "integrity": "sha512-76iFAOrkcuw5UPA30Pt32XaytMHXz/04JembgIwsQAp7ImHYSWNq1shBbrlWf6CUvh1+amQ81LI8hNhqQgsBEw==", "dev": true }, "node_modules/iota-array": { @@ -1266,9 +1268,9 @@ } }, "node_modules/obliterator": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.1.tgz", - "integrity": "sha512-XnkiCrrBcIZQitJPAI36mrrpEUvatbte8hLcTcQwKA1v9NkCKasSi+UAguLsLDs/out7MoRzAlmz7VXvY6ph6w==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz", + "integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==" }, "node_modules/once": { "version": "1.4.0", @@ -1674,19 +1676,6 @@ "dup": "^1.0.0" } }, - "node_modules/typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, "node_modules/uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", @@ -1970,7 +1959,7 @@ "bit-twiddle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-1.0.2.tgz", - "integrity": "sha1-DGwfq+KyPRcXPZpht7cJPrnhdp4=", + "integrity": "sha512-B9UhK0DKFZhoTFcfvAzhqsjStvGJp9vYWf3+6SNTtdSQnvIgfkHbgHrg/e4+TH71N2GDu8tpmCVoyfrL1d7ntA==", "dev": true }, "brace-expansion": { @@ -2100,9 +2089,9 @@ } }, "damerau-levenshtein": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.7.tgz", - "integrity": "sha512-VvdQIPGdWP0SqFXghj79Wf/5LArmreyMsGLa6FG6iC4t3j7j5s71TrwWmT/4akbDQIqjfACkLZmjXhA7g2oUZw==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz", + "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, "debug": { @@ -2266,9 +2255,9 @@ } }, "eslint-visitor-keys": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz", - "integrity": "sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true }, "espree": { @@ -2505,7 +2494,7 @@ "bit-twiddle": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/bit-twiddle/-/bit-twiddle-0.0.2.tgz", - "integrity": "sha1-wurruVKjuUrMFASX4c3NLxoz9Y4=", + "integrity": "sha512-76iFAOrkcuw5UPA30Pt32XaytMHXz/04JembgIwsQAp7ImHYSWNq1shBbrlWf6CUvh1+amQ81LI8hNhqQgsBEw==", "dev": true } } @@ -2792,9 +2781,9 @@ "dev": true }, "obliterator": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.1.tgz", - "integrity": "sha512-XnkiCrrBcIZQitJPAI36mrrpEUvatbte8hLcTcQwKA1v9NkCKasSi+UAguLsLDs/out7MoRzAlmz7VXvY6ph6w==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz", + "integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==" }, "once": { "version": "1.4.0", @@ -3081,12 +3070,6 @@ "dup": "^1.0.0" } }, - "typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", - "dev": true - }, "uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", diff --git a/package.json b/package.json index 82cd44f4..3429787c 100644 --- a/package.json +++ b/package.json @@ -3,19 +3,36 @@ "version": "0.39.8", "description": "Curated collection of data structures for the JavaScript/TypeScript.", "scripts": { - "lint": "eslint --cache ./*.js ./utils ./test", - "lint:fix": "eslint --cache --fix ./*.js ./utils ./test", - "prepublishOnly": "npm run lint && npm test && npm run test:types", + "lint": "eslint --cache --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", + "lint:fix": "eslint --cache --fix --ext .js,.mjs ./*.js ./*.mjs ./utils ./test", + "prepublishOnly": "npm run lint && npm test && npm run test:exports", "test": "mocha", - "test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts" + "test:exports": "cd test/exports && npm i && npm run test" }, "main": "./index.js", + "module": "./index.mjs", "types": "./index.d.ts", + "exports": { + ".": { + "types": "./index.d.ts", + "require": "./index.js", + "import": "./index.mjs" + }, + "./*": { + "types": "./*.d.ts", + "require": "./*.js" + }, + "./*.js": { + "types": "./*.d.ts", + "require": "./*.js" + } + }, "files": [ "sort", "utils", "*.d.ts", - "*.js" + "*.js", + "*.mjs" ], "repository": { "type": "git", @@ -73,12 +90,12 @@ }, "homepage": "https://github.com/yomguithereal/mnemonist#readme", "dependencies": { - "obliterator": "^2.0.1" + "obliterator": "^2.0.4" }, "devDependencies": { "@yomguithereal/eslint-config": "^4.4.0", "asciitree": "^1.0.2", - "damerau-levenshtein": "^1.0.7", + "damerau-levenshtein": "^1.0.8", "eslint": "^8.2.0", "leven": "^3.1.0", "lodash": "^4.17.21", @@ -86,8 +103,7 @@ "mocha": "^9.1.3", "pandemonium": "^2.0.0", "seedrandom": "^3.0.5", - "static-kdtree": "^1.0.2", - "typescript": "^4.5.2" + "static-kdtree": "^1.0.2" }, "eslintConfig": { "extends": "@yomguithereal/eslint-config", @@ -95,7 +111,8 @@ "ecmaVersion": 6, "ecmaFeatures": { "forOf": true - } + }, + "sourceType": "module" }, "rules": { "no-new": 0 diff --git a/suffix-array.js b/suffix-array.js index 61632d69..abda47ee 100644 --- a/suffix-array.js +++ b/suffix-array.js @@ -349,4 +349,5 @@ if (typeof Symbol !== 'undefined') * Exporting. */ SuffixArray.GeneralizedSuffixArray = GeneralizedSuffixArray; + module.exports = SuffixArray; diff --git a/test/exports/.gitignore b/test/exports/.gitignore new file mode 100644 index 00000000..849ddff3 --- /dev/null +++ b/test/exports/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/test/exports/exports-default-test.cjs b/test/exports/exports-default-test.cjs new file mode 100644 index 00000000..f4d42470 --- /dev/null +++ b/test/exports/exports-default-test.cjs @@ -0,0 +1,328 @@ +/* eslint-disable no-empty */ +/* eslint-disable no-unused-vars */ +/** + * Mnemonist CommonJS Default Exports Testing + * =========================================== + */ +const BiMap = require('mnemonist/bi-map'); +const BitSet = require('mnemonist/bit-set'); +const BitVector = require('mnemonist/bit-vector'); +const BKTree = require('mnemonist/bk-tree'); +const BloomFilter = require('mnemonist/bloom-filter'); +const CircularBuffer = require('mnemonist/circular-buffer'); +const DefaultMap = require('mnemonist/default-map'); +const FibonacciHeap = require('mnemonist/fibonacci-heap'); +const FixedReverseHeap = require('mnemonist/fixed-reverse-heap'); +const FixedStack = require('mnemonist/fixed-stack'); +const FuzzyMap = require('mnemonist/fuzzy-map'); +const FuzzyMultiMap = require('mnemonist/fuzzy-multi-map'); +const HashedArrayTree = require('mnemonist/hashed-array-tree'); +const Heap = require('mnemonist/heap'); +const InvertedIndex = require('mnemonist/inverted-index'); +const LinkedList = require('mnemonist/linked-list'); +const LRUCache = require('mnemonist/lru-cache'); +const LRUCacheWithDelete = require('mnemonist/lru-cache-with-delete'); +const LRUMap = require('mnemonist/lru-map'); +const LRUMapWithDelete = require('mnemonist/lru-map-with-delete'); +const MultiMap = require('mnemonist/multi-map'); +const MultiSet = require('mnemonist/multi-set'); +const PassjoinIndex = require('mnemonist/passjoin-index'); +const Queue = require('mnemonist/queue'); +const set = require('mnemonist/set'); +const SparseSet = require('mnemonist/sparse-set'); +const Stack = require('mnemonist/stack'); +const StaticDisjointSet = require('mnemonist/static-disjoint-set'); +const StaticIntervalTree = require('mnemonist/static-interval-tree'); +const SuffixArray = require('mnemonist/suffix-array'); +const SymSpell = require('mnemonist/symspell'); +const Trie = require('mnemonist/trie'); +const TrieMap = require('mnemonist/trie-map'); +const Vector = require('mnemonist/vector'); +const VPTree = require('mnemonist/vp-tree'); + +/** + * BiMap. + */ +let bimap = new BiMap(); +bimap.set('one', 1); +let inversemap = bimap.inverse; +inversemap.get(1); + +/** + * BitSet. + */ +let bitset = new BitSet(4); +bitset.set(3); + +/** + * BitVector. + */ +let bitvector = new BitVector({initialCapacity: 34}); +bitvector.set(3); + +/** + * BKTree. + */ +let bktree = BKTree.from(['one', 'two'], (a, b) => 4.0); +bktree.search(2, 'three'); + +/** + * BloomFilter. + */ +let bloomfilter = new BloomFilter(45); +bloomfilter.add('hello'); + +/** + * CircularBuffer. + */ +let circularbuffer = new CircularBuffer(Array, 4); +circularbuffer.push('test'); + +/** + * DefaultMap. + */ +let defaultMap = new DefaultMap(() => []); +defaultMap.get('one').push(1); + +/** + * FibonacciHeap. + */ +let fibonacciHeap = new FibonacciHeap(); +fibonacciHeap.push('hello'); +fibonacciHeap.pop(); +let minFibonacciHeap = new FibonacciHeap.MinFibonacciHeap(); +minFibonacciHeap.push('hello'); +minFibonacciHeap.pop(); +let maxFibonacciHeap = new FibonacciHeap.MaxFibonacciHeap(); +maxFibonacciHeap.push('hello'); +maxFibonacciHeap.pop(); + + +/** + * FixedReverseHeap. + */ +let fixedReverseHeap = new FixedReverseHeap(Uint16Array, 3); +fixedReverseHeap.push(34); + +/** + * FixedStack. + */ +let fixedStack = new FixedStack(Uint8Array, 4); +fixedStack.push(4); +fixedStack.pop(); + +/** + * FuzzyMap. + */ +let fuzzymap = new FuzzyMap(o => o.title); +fuzzymap.set({title: 'Hello'}, 45); +let fuzzymapadd = new FuzzyMap(o => o.n); +fuzzymapadd.add({title: 'Hello', n: 45}); + +/** + * FuzzyMultiMap. + */ +let fuzzymultimap = new FuzzyMultiMap(o => o.title); +fuzzymultimap.set({title: 'Hello'}, 45); +let fuzzymultimapadd = new FuzzyMultiMap(o => o.n); +fuzzymultimapadd.add({title: 'Hello', n: 45}); + +/** + * HashedArrayTree. + */ +let hashedArrayTree = new HashedArrayTree(Int8Array, 34); +hashedArrayTree.push(1); +hashedArrayTree.set(0, 4); + +/** + * Heap. + */ +let heap = new Heap((a, b) => +a - +b); +heap.push('hello'); +heap.pop(); + +let maxHeap = new Heap.MaxHeap(); +maxHeap.push(45); + +/** + * InvertedIndex. + */ +let invertedIndex = new InvertedIndex(n => ['one', 'two']); +invertedIndex.add(45); + +/** + * LinkedList. + */ +let linkedlist = new LinkedList(); +linkedlist.push(true); +let linkedlistItem = linkedlist.shift(); + +/** + * LRUCache. + */ +let lrucache = new LRUCache(10); +lrucache.set('one', 34); +let lrucacheItem = lrucache.get('one'); + +/** + * LRUCacheWithDelete + */ +let lrucwd = new LRUCacheWithDelete(10); +lrucwd.set('one', 'uno'); +let lrucwdItem = lrucwd.get('one'); +lrucwdItem = lrucwd.remove('one'); +let lrucwdDead = lrucwd.remove('one', null); +let lrucwdWasRemoved = lrucwd.delete('one'); + +/** + * LRUMap. + */ +let lrumap = new LRUMap(10); +lrumap.set('one', 34); +let lrumapItem = lrumap.get('one'); + +/** + * LRUMapWithDelete + */ +let lrumwd = new LRUMapWithDelete(10); +lrumwd.set('one', 'uno'); +let lrumwdItem = lrumwd.get('one'); +lrumwdItem = lrumwd.remove('one'); +let lrumwdDead = lrumwd.remove('one', null); +let lrumwdWasRemoved = lrumwd.delete('one'); + +/** + * MultiSet. + */ +let multiset = new MultiSet(); +multiset.add(45); +multiset = MultiSet.from([1, 2, 3]); +multiset = MultiSet.from({one: 1}); + +/** + * MultiMap. + */ +let multimap = new MultiMap(Set); +multimap.set(45, 'test'); +multimap.get(45).has('test'); +let stringMultimap = MultiMap.from({one: 1}); +stringMultimap.get('one').indexOf(1); +for (const _ of multimap) { } +for (const _ of multimap.keys()) { } +for (const _ of multimap.values()) { } +for (const _ of multimap.entries()) { } +for (const _ of multimap.containers()) { } +for (const _ of multimap.associations()) { } + +/** + * PassjoinIndex. + */ +const passjoinIndex = new PassjoinIndex((a, b) => 0, 1); + +let passjoinResults = passjoinIndex.search('hello'); + +/** + * Queue. + */ +let queue = new Queue(); + +queue.enqueue(45); +let queueitem = queue.dequeue(); + +queue.enqueue(45); +queue.enqueue(34); + +queue = Queue.from([1, 2, 3]); +queue = Queue.from({0: 1}); + +let queueIterator = queue.values(); + +/** + * set. + */ +let setA = new Set([1, 2, 3]); +let setB = new Set([3, 4, 5]); +let unionOfSets = set.union(setA, setB); + +/** + * SparseSet. + */ +let sparseSet = new SparseSet(45); +sparseSet.add(3); + +/** + * Stack. + */ +let stack = new Stack(); + +stack.push(45); +let stackitem = stack.pop(); + +stack.push(45); +stack.push(34); + +stack = Stack.from([1, 2, 3]); +stack = Stack.from({0: 1}); + +let stackIterator = stack.values(); + +/** + * StaticDisjointSet. + */ +let disjointSet = new StaticDisjointSet(45); +disjointSet.union(3, 5); + +/** + * StaticIntervalTree. + */ +let intervalTree = StaticIntervalTree.from([[0, 1], [3, 4]]); + +/** + * SuffixArray. + */ +let suffixArray = new SuffixArray('test'); +let generalizedSuffixArray = new SuffixArray.GeneralizedSuffixArray(['test', 'hello']); +let suffixArrayLCS = generalizedSuffixArray.longestCommonSubsequence(); + +/** + * SymSpell. + */ +let symspell = SymSpell.from(['one', 'two'], {verbosity: 2}); +let symspellMatches = symspell.search('three'); + +/** + * Trie. + */ +let trie = new Trie(); +trie.add('roman'); + +let trieMatches = trie.find('rom'); + +/** + * TrieMap. + */ +let trieMap = new TrieMap(); +trieMap.set('roman', 45); + +let trieMapMatches = trieMap.find('rom'); + +trieMap = TrieMap.from(new Map([['roman', 45]])); +trieMap = TrieMap.from({roman: 45}); + +let arrayTrieMap = new TrieMap(Array); +arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); + +/** + * Vector. + */ +let vector = new Vector(Uint32Array, 10); +vector.push(1); +vector.set(0, 2); + +let uint16vector = Vector.Uint16Vector.from([1, 2, 3]); +uint16vector.pop(); + +/** + * VPTree. + */ +let vptree = VPTree.from(['hello'], (a, b) => 1); diff --git a/test/types.ts b/test/exports/exports-named-test.ts similarity index 90% rename from test/types.ts rename to test/exports/exports-named-test.ts index bb9db9ea..e50a4fa4 100644 --- a/test/types.ts +++ b/test/exports/exports-named-test.ts @@ -1,6 +1,6 @@ /** - * Mnemonist Types Testing - * ======================== + * Mnemonist Types and Named Exports Testing + * ========================================== */ import { BiMap, InverseMap, @@ -38,7 +38,7 @@ import { TrieMap, Vector, Uint16Vector, VPTree -} from '../index'; +} from 'mnemonist'; /** * BiMap. @@ -46,7 +46,6 @@ import { let bimap = new BiMap(); bimap.set('one', 1); let inversemap: InverseMap = bimap.inverse; - inversemap.get(1); /** @@ -88,9 +87,12 @@ defaultMap.get('one').push(1); /** * FibonacciHeap. */ -let fibonacciHeap: FibonacciHeap = new FibonacciHeap(); +let fibonacciHeap: FibonacciHeap | MinFibonacciHeap = new FibonacciHeap(); fibonacciHeap.push('hello'); fibonacciHeap.pop(); +let maxFibonacciHeap: MaxFibonacciHeap = new MaxFibonacciHeap(); +maxFibonacciHeap.push('hello'); +maxFibonacciHeap.pop(); /** * FixedReverseHeap. @@ -125,16 +127,17 @@ fuzzymultimapadd.add({title: 'Hello', n: 45}); * HashedArrayTree. */ let hashedArrayTree: HashedArrayTree = new HashedArrayTree(Int8Array, 34); -hashedArrayTree.set(3, 4); +hashedArrayTree.push(1); +hashedArrayTree.set(0, 4); /** * Heap. */ -let heap: Heap = new Heap((a: string, b: string) => +a - +b); +let heap: Heap | MaxHeap = new Heap((a: string, b: string) => +a - +b); heap.push('hello'); heap.pop(); -let maxHeap: MaxHeap = new Heap(); +let maxHeap: MaxHeap = new MaxHeap(); maxHeap.push(45); /** @@ -274,7 +277,8 @@ let intervalTree: StaticIntervalTree = StaticIntervalTree.from([[0, 1] /** * SuffixArray. */ -let generalizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); +let suffixArray: SuffixArray = new SuffixArray('test'); +let generalizedSuffixArray: GeneralizedSuffixArray = new GeneralizedSuffixArray(['test', 'hello']); let suffixArrayLCS: string = generalizedSuffixArray.longestCommonSubsequence() as string; /** @@ -309,7 +313,8 @@ arrayTrieMap.set(['the', 'cat', 'eats', 'the', 'mouse'], 45); * Vector. */ let vector = new Vector(Uint32Array, 10); -vector.set(45, 2); +vector.push(1); +vector.set(0, 2); let uint16vector = Uint16Vector.from([1, 2, 3]); uint16vector.pop(); diff --git a/test/exports/package-lock.json b/test/exports/package-lock.json new file mode 100644 index 00000000..7f581a89 --- /dev/null +++ b/test/exports/package-lock.json @@ -0,0 +1,71 @@ +{ + "name": "exports", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "version": "0.1.0", + "dependencies": { + "mnemonist": "file:../.." + }, + "devDependencies": { + "@types/node": "^20.11.4", + "typescript": "^5.3.3" + } + }, + "../..": { + "name": "mnemonist", + "version": "0.39.7", + "license": "MIT", + "dependencies": { + "obliterator": "^2.0.4" + }, + "devDependencies": { + "@yomguithereal/eslint-config": "^4.4.0", + "asciitree": "^1.0.2", + "damerau-levenshtein": "^1.0.8", + "eslint": "^8.2.0", + "leven": "^3.1.0", + "lodash": "^4.17.21", + "matcha": "^0.7.0", + "mocha": "^9.1.3", + "pandemonium": "^2.0.0", + "seedrandom": "^3.0.5", + "static-kdtree": "^1.0.2" + } + }, + "node_modules/@types/node": { + "version": "20.11.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.4.tgz", + "integrity": "sha512-6I0fMH8Aoy2lOejL3s4LhyIYX34DPwY8bl5xlNjBvUEk8OHrcuzsFt+Ied4LvJihbtXPM+8zUqdydfIti86v9g==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/mnemonist": { + "resolved": "../..", + "link": true + }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + } + } +} diff --git a/test/exports/package.json b/test/exports/package.json new file mode 100644 index 00000000..102b29e0 --- /dev/null +++ b/test/exports/package.json @@ -0,0 +1,19 @@ +{ + "name": "", + "description": "", + "type": "module", + "version": "0.1.0", + "scripts": { + "build:cjs": "tsc --target es2022 --module commonjs --noImplicitAny --noImplicitReturns --outDir dist/cjs exports-named-test.ts && mv dist/cjs/exports-named-test.js dist/cjs/exports-named-test.cjs", + "build:esm": "tsc --target es2022 --module node16 --noImplicitAny --noImplicitReturns --outDir dist/esm exports-named-test.ts", + "build": "npm run build:cjs && npm run build:esm", + "test": "npm run build && node dist/cjs/exports-named-test.cjs && node dist/esm/exports-named-test.js && node exports-default-test.cjs" + }, + "dependencies": { + "mnemonist": "file:../.." + }, + "devDependencies": { + "@types/node": "^20.11.4", + "typescript": "^5.3.3" + } +} diff --git a/vector.d.ts b/vector.d.ts index a6c1c6a3..1a56e276 100644 --- a/vector.d.ts +++ b/vector.d.ts @@ -2,7 +2,7 @@ * Mnemonist Vector Typings * ========================= */ -import { IArrayLikeConstructor } from './utils/types'; +import {IArrayLikeConstructor} from './utils/types'; type VectorOptions = { initialLength?: number; @@ -79,3 +79,4 @@ export class Int32Vector extends TypedVector {} export class Uint32Vector extends TypedVector {} export class Float32Vector extends TypedVector {} export class Float64Vector extends TypedVector {} +export class PointerVector extends TypedVector {}