@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.
Files changed (128) hide show
  1. package/README.md +8 -0
  2. package/dist/array/chunk.d.ts +1 -0
  3. package/dist/array/chunk.js +9 -0
  4. package/dist/array/index.d.ts +1 -0
  5. package/dist/array/index.js +4 -0
  6. package/dist/date/index.d.ts +1 -0
  7. package/dist/date/index.js +8 -0
  8. package/dist/date/iso-date-time.d.ts +127 -0
  9. package/dist/date/iso-date-time.js +256 -0
  10. package/dist/duration/add-durations.d.ts +1 -0
  11. package/dist/duration/add-durations.js +12 -0
  12. package/dist/duration/index.d.ts +3 -0
  13. package/dist/duration/index.js +8 -0
  14. package/dist/duration/is-duration.d.ts +1 -0
  15. package/dist/duration/is-duration.js +7 -0
  16. package/dist/duration/to-number.d.ts +1 -0
  17. package/dist/duration/to-number.js +14 -0
  18. package/dist/format/formatter.d.ts +5 -0
  19. package/dist/format/formatter.js +40 -0
  20. package/dist/format/index.d.ts +3 -0
  21. package/dist/format/index.js +13 -0
  22. package/dist/format/stringify.d.ts +38 -0
  23. package/dist/format/stringify.js +42 -0
  24. package/dist/format/template.d.ts +6 -0
  25. package/dist/format/template.js +35 -0
  26. package/dist/object/get.d.ts +1 -0
  27. package/dist/object/get.js +7 -0
  28. package/dist/object/index.d.ts +5 -0
  29. package/dist/object/index.js +12 -0
  30. package/dist/object/is-object.d.ts +1 -0
  31. package/dist/object/is-object.js +4 -0
  32. package/dist/object/omit.d.ts +1 -0
  33. package/dist/object/omit.js +18 -0
  34. package/dist/object/pick.d.ts +1 -0
  35. package/dist/object/pick.js +11 -0
  36. package/dist/object/set.d.ts +1 -0
  37. package/dist/object/set.js +14 -0
  38. package/dist/set/difference.d.ts +1 -0
  39. package/dist/set/difference.js +10 -0
  40. package/dist/set/index.d.ts +5 -0
  41. package/dist/set/index.js +12 -0
  42. package/dist/set/intersection.d.ts +1 -0
  43. package/dist/set/intersection.js +13 -0
  44. package/dist/set/is-superset.d.ts +1 -0
  45. package/dist/set/is-superset.js +12 -0
  46. package/dist/set/symmetric-difference.d.ts +1 -0
  47. package/dist/set/symmetric-difference.js +14 -0
  48. package/dist/set/union.d.ts +1 -0
  49. package/dist/set/union.js +10 -0
  50. package/dist/string/capitalize.d.ts +1 -0
  51. package/dist/string/capitalize.js +4 -0
  52. package/dist/string/index.d.ts +6 -0
  53. package/dist/string/index.js +14 -0
  54. package/dist/string/pluralize/index.d.ts +2 -0
  55. package/dist/string/pluralize/index.js +4 -0
  56. package/dist/string/pluralize/pluralize.d.ts +85 -0
  57. package/dist/string/pluralize/pluralize.js +210 -0
  58. package/dist/string/pluralize/rules/index.d.ts +4 -0
  59. package/dist/string/pluralize/rules/index.js +10 -0
  60. package/dist/string/pluralize/rules/irregular.d.ts +1 -0
  61. package/dist/string/pluralize/rules/irregular.js +62 -0
  62. package/dist/string/pluralize/rules/pluralization.d.ts +2 -0
  63. package/dist/string/pluralize/rules/pluralization.js +39 -0
  64. package/dist/string/pluralize/rules/singularization.d.ts +2 -0
  65. package/dist/string/pluralize/rules/singularization.js +47 -0
  66. package/dist/string/pluralize/rules/uncountable.d.ts +2 -0
  67. package/dist/string/pluralize/rules/uncountable.js +113 -0
  68. package/dist/string/pluralize/types.d.ts +3 -0
  69. package/dist/string/pluralize/types.js +1 -0
  70. package/dist/string/slugify/index.d.ts +1 -0
  71. package/dist/string/slugify/index.js +2263 -0
  72. package/dist/string/strip-html-tags.d.ts +1 -0
  73. package/dist/string/strip-html-tags.js +7 -0
  74. package/dist/string/to-int.d.ts +9 -0
  75. package/dist/string/to-int.js +10 -0
  76. package/dist/string/to-sentence-case.d.ts +1 -0
  77. package/dist/string/to-sentence-case.js +8 -0
  78. package/dist/string/trim.d.ts +1 -0
  79. package/dist/string/trim.js +11 -0
  80. package/dist/string/truncate.d.ts +1 -0
  81. package/dist/string/truncate.js +9 -0
  82. package/eslint.config.js +19 -0
  83. package/package.json +68 -0
  84. package/src/array/chunk.ts +6 -0
  85. package/src/array/index.ts +1 -0
  86. package/src/date/index.ts +1 -0
  87. package/src/date/iso-date-time.ts +356 -0
  88. package/src/duration/add-durations.ts +16 -0
  89. package/src/duration/index.ts +3 -0
  90. package/src/duration/is-duration.ts +5 -0
  91. package/src/duration/to-number.ts +18 -0
  92. package/src/format/formatter.ts +37 -0
  93. package/src/format/index.ts +3 -0
  94. package/src/format/stringify.ts +87 -0
  95. package/src/format/template.ts +48 -0
  96. package/src/object/get.ts +9 -0
  97. package/src/object/index.ts +5 -0
  98. package/src/object/is-object.ts +2 -0
  99. package/src/object/omit.ts +21 -0
  100. package/src/object/pick.ts +10 -0
  101. package/src/object/set.ts +15 -0
  102. package/src/set/difference.ts +9 -0
  103. package/src/set/index.ts +5 -0
  104. package/src/set/intersection.ts +12 -0
  105. package/src/set/is-superset.ts +12 -0
  106. package/src/set/symmetric-difference.ts +12 -0
  107. package/src/set/union.ts +8 -0
  108. package/src/string/capitalize.ts +2 -0
  109. package/src/string/index.ts +6 -0
  110. package/src/string/pluralize/index.ts +2 -0
  111. package/src/string/pluralize/pluralize.ts +296 -0
  112. package/src/string/pluralize/rules/index.ts +4 -0
  113. package/src/string/pluralize/rules/irregular.ts +59 -0
  114. package/src/string/pluralize/rules/pluralization.ts +40 -0
  115. package/src/string/pluralize/rules/singularization.ts +46 -0
  116. package/src/string/pluralize/rules/uncountable.ts +107 -0
  117. package/src/string/pluralize/types.ts +4 -0
  118. package/src/string/slugify/index.ts +3 -0
  119. package/src/string/strip-html-tags.ts +4 -0
  120. package/src/string/to-int.ts +20 -0
  121. package/src/string/to-sentence-case.ts +6 -0
  122. package/src/string/trim.ts +11 -0
  123. package/src/string/truncate.ts +11 -0
  124. package/tsconfig.json +18 -0
  125. package/tsconfig.lib.json +36 -0
  126. package/tsconfig.lib.tsbuildinfo +1 -0
  127. package/tsconfig.node.json +25 -0
  128. 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,4 @@
1
+ export type RuleKey = string | RegExp;
2
+ export type RuleValue = string;
3
+
4
+ export type Rule = [RuleKey, RuleValue];
@@ -0,0 +1,3 @@
1
+ import slugifyNP from "@sindresorhus/slugify";
2
+
3
+ export const slugify = (text: string) => slugifyNP(text);
@@ -0,0 +1,4 @@
1
+ const htmlTagRegExp = /(<([^>]+)>)/g;
2
+ export function stripHtmlTags(text: string) {
3
+ return text.replace(htmlTagRegExp, "");
4
+ }
@@ -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,6 @@
1
+ const specialCharRegExp = /[\s-_.+]+/g;
2
+ export const toSentenceCase = <T extends string>(s: T) =>
3
+ (s[0].toUpperCase() + s.slice(1).toLowerCase()).replace(
4
+ specialCharRegExp,
5
+ " ",
6
+ );
@@ -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
+ }
@@ -0,0 +1,11 @@
1
+ export function truncate(
2
+ text: string,
3
+ maxlength: number = 100,
4
+ ending: string = "...",
5
+ ) {
6
+ if (text.length > maxlength) {
7
+ return text.substring(0, maxlength - ending.length) + ending;
8
+ }
9
+
10
+ return text;
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.lib.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.node.json"
9
+ }
10
+ ],
11
+ "compilerOptions": {
12
+ "paths": {
13
+ "@/*": [
14
+ "./src/*"
15
+ ]
16
+ }
17
+ },
18
+ }
@@ -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
+ });