@bccampus/utils 0.1.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/README.md +8 -0
- package/dist/array/chunk.d.ts +1 -0
- package/dist/array/chunk.js +9 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +4 -0
- package/dist/date/index.d.ts +1 -0
- package/dist/date/index.js +8 -0
- package/dist/date/iso-date-time.d.ts +127 -0
- package/dist/date/iso-date-time.js +256 -0
- package/dist/duration/add-durations.d.ts +1 -0
- package/dist/duration/add-durations.js +12 -0
- package/dist/duration/index.d.ts +3 -0
- package/dist/duration/index.js +8 -0
- package/dist/duration/is-duration.d.ts +1 -0
- package/dist/duration/is-duration.js +7 -0
- package/dist/duration/to-number.d.ts +1 -0
- package/dist/duration/to-number.js +14 -0
- package/dist/format/formatter.d.ts +5 -0
- package/dist/format/formatter.js +40 -0
- package/dist/format/index.d.ts +3 -0
- package/dist/format/index.js +13 -0
- package/dist/format/stringify.d.ts +38 -0
- package/dist/format/stringify.js +42 -0
- package/dist/format/template.d.ts +6 -0
- package/dist/format/template.js +35 -0
- package/dist/object/get.d.ts +1 -0
- package/dist/object/get.js +7 -0
- package/dist/object/index.d.ts +5 -0
- package/dist/object/index.js +12 -0
- package/dist/object/is-object.d.ts +1 -0
- package/dist/object/is-object.js +4 -0
- package/dist/object/omit.d.ts +1 -0
- package/dist/object/omit.js +18 -0
- package/dist/object/pick.d.ts +1 -0
- package/dist/object/pick.js +11 -0
- package/dist/object/set.d.ts +1 -0
- package/dist/object/set.js +14 -0
- package/dist/set/difference.d.ts +1 -0
- package/dist/set/difference.js +10 -0
- package/dist/set/index.d.ts +5 -0
- package/dist/set/index.js +12 -0
- package/dist/set/intersection.d.ts +1 -0
- package/dist/set/intersection.js +13 -0
- package/dist/set/is-superset.d.ts +1 -0
- package/dist/set/is-superset.js +12 -0
- package/dist/set/symmetric-difference.d.ts +1 -0
- package/dist/set/symmetric-difference.js +14 -0
- package/dist/set/union.d.ts +1 -0
- package/dist/set/union.js +10 -0
- package/dist/string/capitalize.d.ts +1 -0
- package/dist/string/capitalize.js +4 -0
- package/dist/string/index.d.ts +6 -0
- package/dist/string/index.js +14 -0
- package/dist/string/pluralize/index.d.ts +2 -0
- package/dist/string/pluralize/index.js +4 -0
- package/dist/string/pluralize/pluralize.d.ts +85 -0
- package/dist/string/pluralize/pluralize.js +210 -0
- package/dist/string/pluralize/rules/index.d.ts +4 -0
- package/dist/string/pluralize/rules/index.js +10 -0
- package/dist/string/pluralize/rules/irregular.d.ts +1 -0
- package/dist/string/pluralize/rules/irregular.js +62 -0
- package/dist/string/pluralize/rules/pluralization.d.ts +2 -0
- package/dist/string/pluralize/rules/pluralization.js +39 -0
- package/dist/string/pluralize/rules/singularization.d.ts +2 -0
- package/dist/string/pluralize/rules/singularization.js +47 -0
- package/dist/string/pluralize/rules/uncountable.d.ts +2 -0
- package/dist/string/pluralize/rules/uncountable.js +113 -0
- package/dist/string/pluralize/types.d.ts +3 -0
- package/dist/string/pluralize/types.js +1 -0
- package/dist/string/slugify/index.d.ts +1 -0
- package/dist/string/slugify/index.js +2263 -0
- package/dist/string/strip-html-tags.d.ts +1 -0
- package/dist/string/strip-html-tags.js +7 -0
- package/dist/string/to-int.d.ts +9 -0
- package/dist/string/to-int.js +10 -0
- package/dist/string/to-sentence-case.d.ts +1 -0
- package/dist/string/to-sentence-case.js +8 -0
- package/dist/string/trim.d.ts +1 -0
- package/dist/string/trim.js +11 -0
- package/dist/string/truncate.d.ts +1 -0
- package/dist/string/truncate.js +9 -0
- package/eslint.config.js +19 -0
- package/package.json +68 -0
- package/src/array/chunk.ts +6 -0
- package/src/array/index.ts +1 -0
- package/src/date/index.ts +1 -0
- package/src/date/iso-date-time.ts +356 -0
- package/src/duration/add-durations.ts +16 -0
- package/src/duration/index.ts +3 -0
- package/src/duration/is-duration.ts +5 -0
- package/src/duration/to-number.ts +18 -0
- package/src/format/formatter.ts +37 -0
- package/src/format/index.ts +3 -0
- package/src/format/stringify.ts +87 -0
- package/src/format/template.ts +48 -0
- package/src/object/get.ts +9 -0
- package/src/object/index.ts +5 -0
- package/src/object/is-object.ts +2 -0
- package/src/object/omit.ts +21 -0
- package/src/object/pick.ts +10 -0
- package/src/object/set.ts +15 -0
- package/src/set/difference.ts +9 -0
- package/src/set/index.ts +5 -0
- package/src/set/intersection.ts +12 -0
- package/src/set/is-superset.ts +12 -0
- package/src/set/symmetric-difference.ts +12 -0
- package/src/set/union.ts +8 -0
- package/src/string/capitalize.ts +2 -0
- package/src/string/index.ts +6 -0
- package/src/string/pluralize/index.ts +2 -0
- package/src/string/pluralize/pluralize.ts +296 -0
- package/src/string/pluralize/rules/index.ts +4 -0
- package/src/string/pluralize/rules/irregular.ts +59 -0
- package/src/string/pluralize/rules/pluralization.ts +40 -0
- package/src/string/pluralize/rules/singularization.ts +46 -0
- package/src/string/pluralize/rules/uncountable.ts +107 -0
- package/src/string/pluralize/types.ts +4 -0
- package/src/string/slugify/index.ts +3 -0
- package/src/string/strip-html-tags.ts +4 -0
- package/src/string/to-int.ts +20 -0
- package/src/string/to-sentence-case.ts +6 -0
- package/src/string/trim.ts +11 -0
- package/src/string/truncate.ts +11 -0
- package/tsconfig.json +18 -0
- package/tsconfig.lib.json +36 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
- package/tsconfig.node.json +25 -0
- package/vite.config.ts +77 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable no-control-regex */
|
|
2
|
+
|
|
3
|
+
import type { Rule } from "../types";
|
|
4
|
+
|
|
5
|
+
export const PLURALIZATION_RULES: Rule[] = [
|
|
6
|
+
[/s?$/i, "s"],
|
|
7
|
+
[/[^\u0000-\u007F]$/, "$0"],
|
|
8
|
+
[/([^aeiou]ese)$/i, "$1"],
|
|
9
|
+
[/(ax|test)is$/i, "$1es"],
|
|
10
|
+
[/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
|
|
11
|
+
[/(e[mn]u)s?$/i, "$1s"],
|
|
12
|
+
[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
|
|
13
|
+
[
|
|
14
|
+
/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
|
|
15
|
+
"$1i",
|
|
16
|
+
],
|
|
17
|
+
[/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
|
|
18
|
+
[/(seraph|cherub)(?:im)?$/i, "$1im"],
|
|
19
|
+
[/(her|at|gr)o$/i, "$1oes"],
|
|
20
|
+
[
|
|
21
|
+
/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,
|
|
22
|
+
"$1a",
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,
|
|
26
|
+
"$1a",
|
|
27
|
+
],
|
|
28
|
+
[/sis$/i, "ses"],
|
|
29
|
+
[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
|
|
30
|
+
[/([^aeiouy]|qu)y$/i, "$1ies"],
|
|
31
|
+
[/([^ch][ieo][ln])ey$/i, "$1ies"],
|
|
32
|
+
[/(x|ch|ss|sh|zz)$/i, "$1es"],
|
|
33
|
+
[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
|
|
34
|
+
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
|
|
35
|
+
[/(pe)(?:rson|ople)$/i, "$1ople"],
|
|
36
|
+
[/(child)(?:ren)?$/i, "$1ren"],
|
|
37
|
+
[/eaux$/i, "$0"],
|
|
38
|
+
[/m[ae]n$/i, "men"],
|
|
39
|
+
["thou", "you"],
|
|
40
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Rule } from "../types";
|
|
2
|
+
|
|
3
|
+
export const SINGULARIZATION_RULES: Rule[] = [
|
|
4
|
+
[/s$/i, ""],
|
|
5
|
+
[/(ss)$/i, "$1"],
|
|
6
|
+
[/(wi|kni|(?:after|half|high|low|mid|non|night|\W|^)li)ves$/i, "$1fe"],
|
|
7
|
+
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
|
|
8
|
+
[/ies$/i, "y"],
|
|
9
|
+
[/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i, "$1ie"],
|
|
10
|
+
[
|
|
11
|
+
/\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i,
|
|
12
|
+
"$1ie",
|
|
13
|
+
],
|
|
14
|
+
[/\b(mon|smil)ies$/i, "$1ey"],
|
|
15
|
+
[/\b((?:tit)?m|l)ice$/i, "$1ouse"],
|
|
16
|
+
[/(seraph|cherub)im$/i, "$1"],
|
|
17
|
+
[
|
|
18
|
+
/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,
|
|
19
|
+
"$1",
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,
|
|
23
|
+
"$1sis",
|
|
24
|
+
],
|
|
25
|
+
[/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
|
|
26
|
+
[/(test)(?:is|es)$/i, "$1is"],
|
|
27
|
+
[
|
|
28
|
+
/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
|
|
29
|
+
"$1us",
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,
|
|
33
|
+
"$1um",
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
|
|
37
|
+
"$1on",
|
|
38
|
+
],
|
|
39
|
+
[/(alumn|alg|vertebr)ae$/i, "$1a"],
|
|
40
|
+
[/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
|
|
41
|
+
[/(matr|append)ices$/i, "$1ix"],
|
|
42
|
+
[/(pe)(rson|ople)$/i, "$1rson"],
|
|
43
|
+
[/(child)ren$/i, "$1"],
|
|
44
|
+
[/(eau)x?$/i, "$1"],
|
|
45
|
+
[/men$/i, "man"],
|
|
46
|
+
];
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { RuleKey } from '../types';
|
|
2
|
+
|
|
3
|
+
export const UNCOUNTABLE_WORDS: RuleKey[] = [
|
|
4
|
+
// Singular words with no plurals.
|
|
5
|
+
'adulthood',
|
|
6
|
+
'advice',
|
|
7
|
+
'agenda',
|
|
8
|
+
'aid',
|
|
9
|
+
'aircraft',
|
|
10
|
+
'alcohol',
|
|
11
|
+
'ammo',
|
|
12
|
+
'analytics',
|
|
13
|
+
'anime',
|
|
14
|
+
'athletics',
|
|
15
|
+
'audio',
|
|
16
|
+
'bison',
|
|
17
|
+
'blood',
|
|
18
|
+
'bream',
|
|
19
|
+
'buffalo',
|
|
20
|
+
'butter',
|
|
21
|
+
'carp',
|
|
22
|
+
'cash',
|
|
23
|
+
'chassis',
|
|
24
|
+
'chess',
|
|
25
|
+
'clothing',
|
|
26
|
+
'cod',
|
|
27
|
+
'commerce',
|
|
28
|
+
'cooperation',
|
|
29
|
+
'corps',
|
|
30
|
+
'debris',
|
|
31
|
+
'diabetes',
|
|
32
|
+
'digestion',
|
|
33
|
+
'elk',
|
|
34
|
+
'energy',
|
|
35
|
+
'equipment',
|
|
36
|
+
'excretion',
|
|
37
|
+
'expertise',
|
|
38
|
+
'firmware',
|
|
39
|
+
'flounder',
|
|
40
|
+
'fun',
|
|
41
|
+
'gallows',
|
|
42
|
+
'garbage',
|
|
43
|
+
'graffiti',
|
|
44
|
+
'hardware',
|
|
45
|
+
'headquarters',
|
|
46
|
+
'health',
|
|
47
|
+
'herpes',
|
|
48
|
+
'highjinks',
|
|
49
|
+
'homework',
|
|
50
|
+
'housework',
|
|
51
|
+
'information',
|
|
52
|
+
'jeans',
|
|
53
|
+
'justice',
|
|
54
|
+
'kudos',
|
|
55
|
+
'labour',
|
|
56
|
+
'literature',
|
|
57
|
+
'machinery',
|
|
58
|
+
'mackerel',
|
|
59
|
+
'mail',
|
|
60
|
+
'media',
|
|
61
|
+
'mews',
|
|
62
|
+
'moose',
|
|
63
|
+
'music',
|
|
64
|
+
'mud',
|
|
65
|
+
'manga',
|
|
66
|
+
'news',
|
|
67
|
+
'only',
|
|
68
|
+
'personnel',
|
|
69
|
+
'pike',
|
|
70
|
+
'plankton',
|
|
71
|
+
'pliers',
|
|
72
|
+
'police',
|
|
73
|
+
'pollution',
|
|
74
|
+
'premises',
|
|
75
|
+
'rain',
|
|
76
|
+
'research',
|
|
77
|
+
'rice',
|
|
78
|
+
'salmon',
|
|
79
|
+
'scissors',
|
|
80
|
+
'series',
|
|
81
|
+
'sewage',
|
|
82
|
+
'shambles',
|
|
83
|
+
'shrimp',
|
|
84
|
+
'software',
|
|
85
|
+
'staff',
|
|
86
|
+
'swine',
|
|
87
|
+
'tennis',
|
|
88
|
+
'traffic',
|
|
89
|
+
'transportation',
|
|
90
|
+
'trout',
|
|
91
|
+
'tuna',
|
|
92
|
+
'wealth',
|
|
93
|
+
'welfare',
|
|
94
|
+
'whiting',
|
|
95
|
+
'wildebeest',
|
|
96
|
+
'wildlife',
|
|
97
|
+
'you',
|
|
98
|
+
/pok[eé]mon$/i,
|
|
99
|
+
// Regexes.
|
|
100
|
+
/[^aeiou]ese$/i, // "chinese", "japanese"
|
|
101
|
+
/deer$/i, // "deer", "reindeer"
|
|
102
|
+
/fish$/i, // "fish", "blowfish", "angelfish"
|
|
103
|
+
/measles$/i,
|
|
104
|
+
/o[iu]s$/i, // "carnivorous"
|
|
105
|
+
/pox$/i, // "chickpox", "smallpox"
|
|
106
|
+
/sheep$/i,
|
|
107
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string (or a number) into a number.
|
|
3
|
+
* If the input can not be successfully converted, it will return the fallback.
|
|
4
|
+
* It will not return NaN.
|
|
5
|
+
* @param value - The value to convert
|
|
6
|
+
* @param fallback - The value to fallback to. Defaults to 0
|
|
7
|
+
* @returns number
|
|
8
|
+
*/
|
|
9
|
+
export function stringToInt(
|
|
10
|
+
value: string | number,
|
|
11
|
+
fallback: number = 0,
|
|
12
|
+
): number {
|
|
13
|
+
let returnValue = value;
|
|
14
|
+
if (typeof returnValue === "string")
|
|
15
|
+
returnValue = Number.parseInt(returnValue);
|
|
16
|
+
|
|
17
|
+
if (Number.isNaN(returnValue)) returnValue = fallback;
|
|
18
|
+
|
|
19
|
+
return returnValue;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function trim(text: string, chars: string | string[] = " ") {
|
|
2
|
+
let start = 0;
|
|
3
|
+
let end = text.length;
|
|
4
|
+
|
|
5
|
+
if (!Array.isArray(chars)) chars = [chars];
|
|
6
|
+
|
|
7
|
+
while (start < end && chars.includes(text[start])) start += 1;
|
|
8
|
+
while (end > start && chars.includes(text[end - 1])) end -= 1;
|
|
9
|
+
|
|
10
|
+
return start > 0 || end < text.length ? text.substring(start, end) : text;
|
|
11
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"lib": [
|
|
6
|
+
"DOM",
|
|
7
|
+
"ESNext"
|
|
8
|
+
],
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"jsx": "preserve",
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"moduleResolution": "bundler",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"strictNullChecks": true,
|
|
17
|
+
"allowJs": true,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"noEmit": true,
|
|
20
|
+
"types": [
|
|
21
|
+
"node",
|
|
22
|
+
],
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": [
|
|
25
|
+
"./src/*"
|
|
26
|
+
],
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"include": [
|
|
30
|
+
"src/**/*",
|
|
31
|
+
],
|
|
32
|
+
"exclude": [
|
|
33
|
+
"dist",
|
|
34
|
+
"node_modules"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/array/chunk.ts","./src/array/index.ts","./src/date/index.ts","./src/date/iso-date-time.ts","./src/duration/add-durations.ts","./src/duration/index.ts","./src/duration/is-duration.ts","./src/duration/to-number.ts","./src/format/formatter.ts","./src/format/index.ts","./src/format/stringify.ts","./src/format/template.ts","./src/object/get.ts","./src/object/index.ts","./src/object/is-object.ts","./src/object/omit.ts","./src/object/pick.ts","./src/object/set.ts","./src/set/difference.ts","./src/set/index.ts","./src/set/intersection.ts","./src/set/is-superset.ts","./src/set/symmetric-difference.ts","./src/set/union.ts","./src/string/capitalize.ts","./src/string/index.ts","./src/string/strip-html-tags.ts","./src/string/to-int.ts","./src/string/to-sentence-case.ts","./src/string/trim.ts","./src/string/truncate.ts","./src/string/pluralize/index.ts","./src/string/pluralize/pluralize.ts","./src/string/pluralize/types.ts","./src/string/pluralize/rules/index.ts","./src/string/pluralize/rules/irregular.ts","./src/string/pluralize/rules/pluralization.ts","./src/string/pluralize/rules/singularization.ts","./src/string/pluralize/rules/uncountable.ts","./src/string/slugify/index.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "ES2023",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
|
|
16
|
+
/* Linting */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"erasableSyntaxOnly": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"noUncheckedSideEffectImports": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["vite.config.ts"]
|
|
25
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { globSync } from "tinyglobby";
|
|
4
|
+
import { defineConfig } from "vite";
|
|
5
|
+
import dts from "vite-plugin-dts";
|
|
6
|
+
import packageConfig from "./package.json";
|
|
7
|
+
import { writeFileSync } from "node:fs";
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const outDir = "./dist";
|
|
11
|
+
|
|
12
|
+
const createEntries = () => {
|
|
13
|
+
const entries = new Map<string, string>();
|
|
14
|
+
const exports = new Map<
|
|
15
|
+
string,
|
|
16
|
+
{
|
|
17
|
+
types: string;
|
|
18
|
+
import: string;
|
|
19
|
+
}
|
|
20
|
+
>();
|
|
21
|
+
|
|
22
|
+
const files = globSync("src/**/*.ts", {
|
|
23
|
+
cwd: __dirname,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
const filePath = file.split(".")[0].replace(/^src[/\\]/, "");
|
|
28
|
+
|
|
29
|
+
if (!filePath) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const filePathParts = filePath.split("/");
|
|
34
|
+
if (filePathParts.at(-1) === "index" && filePathParts.length <= 3) {
|
|
35
|
+
const exportPath =
|
|
36
|
+
filePathParts.length === 1
|
|
37
|
+
? "."
|
|
38
|
+
: `./${filePathParts.slice(0, -1).join("/")}`;
|
|
39
|
+
|
|
40
|
+
exports.set(exportPath, {
|
|
41
|
+
types: `${outDir}/${filePath}.d.ts`,
|
|
42
|
+
import: `${outDir}/${filePath}.js`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
entries.set(filePath, fileURLToPath(new URL(file, import.meta.url)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const _packageConfig = {
|
|
50
|
+
...packageConfig,
|
|
51
|
+
exports: Object.fromEntries(exports),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
writeFileSync("./package.json", JSON.stringify(_packageConfig, null, 2), {
|
|
55
|
+
encoding: "utf-8",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return Object.fromEntries(entries);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
plugins: [dts({ tsconfigPath: "./tsconfig.lib.json" })],
|
|
63
|
+
resolve: {
|
|
64
|
+
alias: {
|
|
65
|
+
"@": path.resolve(__dirname, "./src"),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
build: {
|
|
69
|
+
minify: false,
|
|
70
|
+
copyPublicDir: false,
|
|
71
|
+
lib: {
|
|
72
|
+
entry: createEntries(),
|
|
73
|
+
name: "utils",
|
|
74
|
+
formats: ["es"],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|