data-structure-typed 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +4 -0
- package/dist/cjs/index.cjs +1153 -563
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +13623 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1153 -563
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +13545 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +65 -3
- package/dist/umd/data-structure-typed.js +594 -33
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +20 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +115 -11
- package/src/data-structures/binary-tree/avl-tree.ts +105 -14
- package/src/data-structures/binary-tree/bst.ts +102 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +108 -18
- package/src/data-structures/binary-tree/tree-counter.ts +101 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +122 -11
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +4 -4
- package/tsup.node.config.js +40 -6
|
@@ -6,7 +6,15 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
BTNOptKeyOrNull,
|
|
11
|
+
ElemOf,
|
|
12
|
+
EntryCallback,
|
|
13
|
+
FamilyPosition,
|
|
14
|
+
RBTNColor,
|
|
15
|
+
RedBlackTreeOptions,
|
|
16
|
+
TreeMultiMapOptions
|
|
17
|
+
} from '../../types';
|
|
10
18
|
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
11
19
|
import { IBinaryTree } from '../../interfaces';
|
|
12
20
|
|
|
@@ -16,8 +24,10 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
16
24
|
* @template K
|
|
17
25
|
* @template V
|
|
18
26
|
*/
|
|
19
|
-
export class TreeMultiMapNode<K = any, V = any>
|
|
20
|
-
|
|
27
|
+
export class TreeMultiMapNode<K = any, V = any> {
|
|
28
|
+
key: K;
|
|
29
|
+
value?: V[];
|
|
30
|
+
parent?: TreeMultiMapNode<K, V> = undefined;
|
|
21
31
|
|
|
22
32
|
/**
|
|
23
33
|
* Create a TreeMultiMap node with an optional value bucket.
|
|
@@ -26,18 +36,20 @@ export class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]>
|
|
|
26
36
|
* @param [value] - Initial array of values.
|
|
27
37
|
* @returns New TreeMultiMapNode instance.
|
|
28
38
|
*/
|
|
29
|
-
constructor(key: K, value
|
|
30
|
-
|
|
39
|
+
constructor(key: K, value: V[] = [], color: RBTNColor = 'BLACK') {
|
|
40
|
+
this.key = key;
|
|
41
|
+
this.value = value;
|
|
42
|
+
this.color = color;
|
|
31
43
|
}
|
|
32
44
|
|
|
33
|
-
|
|
45
|
+
_left?: TreeMultiMapNode<K, V> | null | undefined = undefined;
|
|
34
46
|
|
|
35
47
|
/**
|
|
36
48
|
* Get the left child pointer.
|
|
37
49
|
* @remarks Time O(1), Space O(1)
|
|
38
50
|
* @returns Left child node, or null/undefined.
|
|
39
51
|
*/
|
|
40
|
-
|
|
52
|
+
get left(): TreeMultiMapNode<K, V> | null | undefined {
|
|
41
53
|
return this._left;
|
|
42
54
|
}
|
|
43
55
|
|
|
@@ -47,21 +59,21 @@ export class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]>
|
|
|
47
59
|
* @param v - New left child node, or null/undefined.
|
|
48
60
|
* @returns void
|
|
49
61
|
*/
|
|
50
|
-
|
|
62
|
+
set left(v: TreeMultiMapNode<K, V> | null | undefined) {
|
|
51
63
|
if (v) {
|
|
52
64
|
v.parent = this;
|
|
53
65
|
}
|
|
54
66
|
this._left = v;
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
|
|
69
|
+
_right?: TreeMultiMapNode<K, V> | null | undefined = undefined;
|
|
58
70
|
|
|
59
71
|
/**
|
|
60
72
|
* Get the right child pointer.
|
|
61
73
|
* @remarks Time O(1), Space O(1)
|
|
62
74
|
* @returns Right child node, or null/undefined.
|
|
63
75
|
*/
|
|
64
|
-
|
|
76
|
+
get right(): TreeMultiMapNode<K, V> | null | undefined {
|
|
65
77
|
return this._right;
|
|
66
78
|
}
|
|
67
79
|
|
|
@@ -71,12 +83,98 @@ export class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]>
|
|
|
71
83
|
* @param v - New right child node, or null/undefined.
|
|
72
84
|
* @returns void
|
|
73
85
|
*/
|
|
74
|
-
|
|
86
|
+
set right(v: TreeMultiMapNode<K, V> | null | undefined) {
|
|
75
87
|
if (v) {
|
|
76
88
|
v.parent = this;
|
|
77
89
|
}
|
|
78
90
|
this._right = v;
|
|
79
91
|
}
|
|
92
|
+
|
|
93
|
+
_height: number = 0;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
97
|
+
* @remarks Time O(1), Space O(1)
|
|
98
|
+
*
|
|
99
|
+
* @returns The height.
|
|
100
|
+
*/
|
|
101
|
+
get height(): number {
|
|
102
|
+
return this._height;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sets the height of the node.
|
|
107
|
+
* @remarks Time O(1), Space O(1)
|
|
108
|
+
*
|
|
109
|
+
* @param value - The new height.
|
|
110
|
+
*/
|
|
111
|
+
set height(value: number) {
|
|
112
|
+
this._height = value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_color: RBTNColor = 'BLACK';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
119
|
+
* @remarks Time O(1), Space O(1)
|
|
120
|
+
*
|
|
121
|
+
* @returns The node's color.
|
|
122
|
+
*/
|
|
123
|
+
get color(): RBTNColor {
|
|
124
|
+
return this._color;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sets the color of the node.
|
|
129
|
+
* @remarks Time O(1), Space O(1)
|
|
130
|
+
*
|
|
131
|
+
* @param value - The new color.
|
|
132
|
+
*/
|
|
133
|
+
set color(value: RBTNColor) {
|
|
134
|
+
this._color = value;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_count: number = 1;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
141
|
+
* @remarks Time O(1), Space O(1)
|
|
142
|
+
*
|
|
143
|
+
* @returns The subtree node count.
|
|
144
|
+
*/
|
|
145
|
+
get count(): number {
|
|
146
|
+
return this._count;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Sets the count of nodes in the subtree.
|
|
151
|
+
* @remarks Time O(1), Space O(1)
|
|
152
|
+
*
|
|
153
|
+
* @param value - The new count.
|
|
154
|
+
*/
|
|
155
|
+
set count(value: number) {
|
|
156
|
+
this._count = value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gets the position of the node relative to its parent.
|
|
161
|
+
* @remarks Time O(1), Space O(1)
|
|
162
|
+
*
|
|
163
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
164
|
+
*/
|
|
165
|
+
get familyPosition(): FamilyPosition {
|
|
166
|
+
if (!this.parent) {
|
|
167
|
+
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (this.parent.left === this) {
|
|
171
|
+
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
172
|
+
} else if (this.parent.right === this) {
|
|
173
|
+
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return 'MAL_NODE';
|
|
177
|
+
}
|
|
80
178
|
}
|
|
81
179
|
|
|
82
180
|
/**
|
|
@@ -274,6 +372,19 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
|
|
|
274
372
|
return new TreeMultiMapNode<K, V>(key, this._isMapMode ? [] : value);
|
|
275
373
|
}
|
|
276
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Checks if the given item is a `TreeMultiMapNode` instance.
|
|
377
|
+
* @remarks Time O(1), Space O(1)
|
|
378
|
+
*
|
|
379
|
+
* @param keyNodeOrEntry - The item to check.
|
|
380
|
+
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
381
|
+
*/
|
|
382
|
+
override isNode(
|
|
383
|
+
keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
384
|
+
): keyNodeOrEntry is TreeMultiMapNode<K, V> {
|
|
385
|
+
return keyNodeOrEntry instanceof TreeMultiMapNode;
|
|
386
|
+
}
|
|
387
|
+
|
|
277
388
|
override add(
|
|
278
389
|
keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
279
390
|
): boolean;
|
|
@@ -50,11 +50,11 @@ export abstract class AbstractEdge<E = any> {
|
|
|
50
50
|
* @example examples will be generated by unit test
|
|
51
51
|
*/
|
|
52
52
|
export abstract class AbstractGraph<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
V = any,
|
|
54
|
+
E = any,
|
|
55
|
+
VO extends AbstractVertex<V> = AbstractVertex<V>,
|
|
56
|
+
EO extends AbstractEdge<E> = AbstractEdge<E>
|
|
57
|
+
>
|
|
58
58
|
extends IterableEntryBase<VertexKey, V | undefined>
|
|
59
59
|
implements IGraph<V, E, VO, EO>
|
|
60
60
|
{
|
|
@@ -38,11 +38,11 @@ export class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
|
38
38
|
* @example examples will be generated by unit test
|
|
39
39
|
*/
|
|
40
40
|
export class DirectedGraph<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
V = any,
|
|
42
|
+
E = any,
|
|
43
|
+
VO extends DirectedVertex<V> = DirectedVertex<V>,
|
|
44
|
+
EO extends DirectedEdge<E> = DirectedEdge<E>
|
|
45
|
+
>
|
|
46
46
|
extends AbstractGraph<V, E, VO, EO>
|
|
47
47
|
implements IGraph<V, E, VO, EO>
|
|
48
48
|
{
|
|
@@ -36,11 +36,11 @@ export class UndirectedEdge<E = number> extends AbstractEdge<E> {
|
|
|
36
36
|
* @example examples will be generated by unit test
|
|
37
37
|
*/
|
|
38
38
|
export class UndirectedGraph<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
V = any,
|
|
40
|
+
E = any,
|
|
41
|
+
VO extends UndirectedVertex<V> = UndirectedVertex<V>,
|
|
42
|
+
EO extends UndirectedEdge<E> = UndirectedEdge<E>
|
|
43
|
+
>
|
|
44
44
|
extends AbstractGraph<V, E, VO, EO>
|
|
45
45
|
implements IGraph<V, E, VO, EO>
|
|
46
46
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AVLTreeCounter, AVLTreeCounterNode,
|
|
1
|
+
import { AVLTreeCounter, AVLTreeCounterNode, IBinaryTree } from '../../../../src';
|
|
2
2
|
import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
@@ -619,9 +619,10 @@ describe('AVLTreeCounter iterative methods test', () => {
|
|
|
619
619
|
|
|
620
620
|
it('The node obtained by get Node should match the node type', () => {
|
|
621
621
|
const node3 = avlCounter.getNode(3);
|
|
622
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
623
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
624
|
-
expect(node3).toBeInstanceOf(AVLTreeNode);
|
|
622
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
623
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
624
|
+
// expect(node3).toBeInstanceOf(AVLTreeNode);
|
|
625
|
+
expect(node3).toBeInstanceOf(AVLTreeCounterNode);
|
|
625
626
|
});
|
|
626
627
|
|
|
627
628
|
it('forEach should iterate over all elements', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AVLTree, AVLTreeNode,
|
|
1
|
+
import { AVLTree, AVLTreeNode, IBinaryTree } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('AVL Tree Test', () => {
|
|
4
4
|
it('should perform various operations on a AVL Tree', () => {
|
|
@@ -379,8 +379,8 @@ describe('AVLTree iterative methods test', () => {
|
|
|
379
379
|
|
|
380
380
|
it('The node obtained by get Node should match the node type', () => {
|
|
381
381
|
const node3 = avlTree.getNode(3);
|
|
382
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
383
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
382
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
383
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
384
384
|
expect(node3).toBeInstanceOf(AVLTreeNode);
|
|
385
385
|
});
|
|
386
386
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BST, BSTNode, IBinaryTree, Range } from '../../../../src';
|
|
2
2
|
import { isDebugTest, isTestStackOverflow, SYSTEM_MAX_CALL_STACK } from '../../../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
@@ -1103,7 +1103,7 @@ describe('BST iterative methods test', () => {
|
|
|
1103
1103
|
|
|
1104
1104
|
it('The node obtained by get Node should match the node type', () => {
|
|
1105
1105
|
const node3 = bst.getNode(3);
|
|
1106
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
1106
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
1107
1107
|
expect(node3).toBeInstanceOf(BSTNode);
|
|
1108
1108
|
});
|
|
1109
1109
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBinaryTree, RedBlackTree, RedBlackTreeNode } from '../../../../src';
|
|
2
2
|
import { getRandomInt, getRandomIntArray, magnitude } from '../../../utils';
|
|
3
3
|
import { OrderedMap } from 'js-sdsl';
|
|
4
4
|
|
|
@@ -641,8 +641,8 @@ describe('RedBlackTree 2', () => {
|
|
|
641
641
|
|
|
642
642
|
it('The node obtained by get Node should match the node type', () => {
|
|
643
643
|
const node3 = rbTree.getNode(3);
|
|
644
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
645
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
644
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
645
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
646
646
|
expect(node3).toBeInstanceOf(RedBlackTreeNode);
|
|
647
647
|
});
|
|
648
648
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBinaryTree, TreeCounter, TreeCounterNode } from '../../../../src';
|
|
2
2
|
import { isDebugTest } from '../../../config';
|
|
3
3
|
import { getRandomInt } from '../../../utils';
|
|
4
4
|
|
|
@@ -757,9 +757,10 @@ describe('TreeCounter iterative methods test', () => {
|
|
|
757
757
|
|
|
758
758
|
it('The node obtained by get Node should match the node type', () => {
|
|
759
759
|
const node3 = treeCounter.getNode(3);
|
|
760
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
761
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
762
|
-
expect(node3).toBeInstanceOf(RedBlackTreeNode);
|
|
760
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
761
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
762
|
+
// expect(node3).toBeInstanceOf(RedBlackTreeNode);
|
|
763
|
+
expect(node3).toBeInstanceOf(TreeCounterNode);
|
|
763
764
|
});
|
|
764
765
|
|
|
765
766
|
it('forEach should iterate over all elements', () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBinaryTree, Range, TreeMultiMap, TreeMultiMapNode } from '../../../../src';
|
|
2
2
|
import { getRandomInt } from '../../../utils';
|
|
3
|
-
import { Range } from '../../../../src';
|
|
4
3
|
import { isDebugTest } from '../../../config';
|
|
5
4
|
import { costOfLiving } from './data/cost-of-living-by-country';
|
|
6
5
|
|
|
@@ -637,8 +636,8 @@ describe('TreeMultiMap 2', () => {
|
|
|
637
636
|
|
|
638
637
|
it('The node obtained by get Node should match the node type', () => {
|
|
639
638
|
const node3 = tmm.getNode(3);
|
|
640
|
-
expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
641
|
-
expect(node3).toBeInstanceOf(BSTNode);
|
|
639
|
+
// expect(node3).toBeInstanceOf(BinaryTreeNode);
|
|
640
|
+
// expect(node3).toBeInstanceOf(BSTNode);
|
|
642
641
|
expect(node3).toBeInstanceOf(TreeMultiMapNode);
|
|
643
642
|
});
|
|
644
643
|
|
|
@@ -1023,6 +1022,7 @@ function leftKey(tmm: TreeMultiMap<number, Product, Product>): number | undefine
|
|
|
1023
1022
|
const v = tmm.getLeftMost();
|
|
1024
1023
|
return v == null ? undefined : typeof v === 'object' ? v.key : v;
|
|
1025
1024
|
}
|
|
1025
|
+
|
|
1026
1026
|
function rightKey(tmm: TreeMultiMap<number, Product, Product>): number | undefined {
|
|
1027
1027
|
const v = tmm.getRightMost();
|
|
1028
1028
|
return v == null ? undefined : typeof v === 'object' ? v.key : v;
|
package/tsup.node.config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineConfig } from "tsup";
|
|
2
2
|
|
|
3
3
|
export default defineConfig([
|
|
4
|
-
// ESM
|
|
4
|
+
// ESM (modern) - ES2022
|
|
5
5
|
{
|
|
6
6
|
entry: { index: "src/index.ts" },
|
|
7
7
|
format: ["esm"],
|
|
@@ -12,13 +12,30 @@ export default defineConfig([
|
|
|
12
12
|
keepNames: true,
|
|
13
13
|
treeshake: true,
|
|
14
14
|
clean: true,
|
|
15
|
+
target: "es2022",
|
|
16
|
+
outExtension() {
|
|
17
|
+
return { js: ".mjs" };
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// ESM (legacy) - ES2018
|
|
22
|
+
{
|
|
23
|
+
entry: { index: "src/index.ts" },
|
|
24
|
+
format: ["esm"],
|
|
25
|
+
outDir: "dist/esm-legacy",
|
|
26
|
+
splitting: false,
|
|
27
|
+
sourcemap: true,
|
|
28
|
+
minify: false,
|
|
29
|
+
keepNames: true,
|
|
30
|
+
treeshake: true,
|
|
31
|
+
clean: false,
|
|
15
32
|
target: "es2018",
|
|
16
33
|
outExtension() {
|
|
17
|
-
return { js: ".mjs" }
|
|
18
|
-
}
|
|
34
|
+
return { js: ".mjs" };
|
|
35
|
+
}
|
|
19
36
|
},
|
|
20
37
|
|
|
21
|
-
// CJS
|
|
38
|
+
// CJS (modern) - ES2022
|
|
22
39
|
{
|
|
23
40
|
entry: { index: "src/index.ts" },
|
|
24
41
|
format: ["cjs"],
|
|
@@ -29,9 +46,26 @@ export default defineConfig([
|
|
|
29
46
|
keepNames: true,
|
|
30
47
|
treeshake: true,
|
|
31
48
|
clean: false,
|
|
32
|
-
target: "
|
|
49
|
+
target: "es2022",
|
|
33
50
|
outExtension() {
|
|
34
51
|
return { js: ".cjs" };
|
|
35
|
-
}
|
|
52
|
+
}
|
|
36
53
|
},
|
|
54
|
+
|
|
55
|
+
// CJS (legacy) - ES2018
|
|
56
|
+
{
|
|
57
|
+
entry: { index: "src/index.ts" },
|
|
58
|
+
format: ["cjs"],
|
|
59
|
+
outDir: "dist/cjs-legacy",
|
|
60
|
+
splitting: false,
|
|
61
|
+
sourcemap: true,
|
|
62
|
+
minify: false,
|
|
63
|
+
keepNames: true,
|
|
64
|
+
treeshake: true,
|
|
65
|
+
clean: false,
|
|
66
|
+
target: "es2018",
|
|
67
|
+
outExtension() {
|
|
68
|
+
return { js: ".cjs" };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
37
71
|
]);
|