@bccampus/utils 0.2.0 → 0.2.2

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 (59) hide show
  1. package/dist/array/chunk.cjs +9 -0
  2. package/dist/array/index.cjs +4 -0
  3. package/dist/date/index.cjs +8 -0
  4. package/dist/date/iso-date-time.cjs +256 -0
  5. package/dist/duration/add-durations.cjs +12 -0
  6. package/dist/duration/index.cjs +8 -0
  7. package/dist/duration/is-duration.cjs +7 -0
  8. package/dist/duration/to-number.cjs +14 -0
  9. package/dist/format/formatter.cjs +40 -0
  10. package/dist/format/index.cjs +13 -0
  11. package/dist/format/stringify.cjs +42 -0
  12. package/dist/format/template.cjs +35 -0
  13. package/dist/index.cjs +4 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +4 -0
  16. package/dist/object/get.cjs +7 -0
  17. package/dist/object/index.cjs +12 -0
  18. package/dist/object/is-object.cjs +4 -0
  19. package/dist/object/omit.cjs +18 -0
  20. package/dist/object/pick.cjs +11 -0
  21. package/dist/object/set.cjs +14 -0
  22. package/dist/path/file-url-to-path.cjs +10 -0
  23. package/dist/path/index.cjs +6 -0
  24. package/dist/path/normalize.cjs +32 -0
  25. package/dist/set/difference.cjs +10 -0
  26. package/dist/set/index.cjs +12 -0
  27. package/dist/set/intersection.cjs +13 -0
  28. package/dist/set/is-superset.cjs +12 -0
  29. package/dist/set/symmetric-difference.cjs +14 -0
  30. package/dist/set/union.cjs +10 -0
  31. package/dist/string/capitalize.cjs +4 -0
  32. package/dist/string/index.cjs +14 -0
  33. package/dist/string/normalize.cjs +6 -0
  34. package/dist/string/pluralize/index.cjs +6 -0
  35. package/dist/string/pluralize/pluralize.cjs +210 -0
  36. package/dist/string/pluralize/rules/index.cjs +10 -0
  37. package/dist/string/pluralize/rules/irregular.cjs +62 -0
  38. package/dist/string/pluralize/rules/pluralization.cjs +39 -0
  39. package/dist/string/pluralize/rules/singularization.cjs +47 -0
  40. package/dist/string/pluralize/rules/uncountable.cjs +113 -0
  41. package/dist/string/pluralize/types.cjs +1 -0
  42. package/dist/string/slugify/index.cjs +2263 -0
  43. package/dist/string/strip-html-tags.cjs +7 -0
  44. package/dist/string/to-int.cjs +10 -0
  45. package/dist/string/to-sentence-case.cjs +8 -0
  46. package/dist/string/trim.cjs +11 -0
  47. package/dist/string/truncate.cjs +20 -0
  48. package/dist/value/index.cjs +4 -0
  49. package/dist/value/index.d.ts +1 -0
  50. package/dist/value/index.js +4 -0
  51. package/dist/value/is-empty.cjs +14 -0
  52. package/dist/value/is-empty.d.ts +17 -0
  53. package/dist/value/is-empty.js +14 -0
  54. package/package.json +31 -11
  55. package/src/format/index.ts +3 -3
  56. package/src/index.ts +1 -0
  57. package/src/value/index.ts +1 -0
  58. package/src/value/is-empty.ts +31 -0
  59. package/vite.config.ts +76 -77
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const htmlTagRegExp = /(<([^>]+)>)/g;
4
+ function stripHtmlTags(text) {
5
+ return text.replace(htmlTagRegExp, "");
6
+ }
7
+ exports.stripHtmlTags = stripHtmlTags;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function stringToInt(value, fallback = 0) {
4
+ let returnValue = value;
5
+ if (typeof returnValue === "string")
6
+ returnValue = Number.parseInt(returnValue);
7
+ if (Number.isNaN(returnValue)) returnValue = fallback;
8
+ return returnValue;
9
+ }
10
+ exports.stringToInt = stringToInt;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const specialCharRegExp = /[\s-_.+]+/g;
4
+ const toSentenceCase = (s) => (s[0].toUpperCase() + s.slice(1).toLowerCase()).replace(
5
+ specialCharRegExp,
6
+ " "
7
+ );
8
+ exports.toSentenceCase = toSentenceCase;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function trim(text, chars = " ") {
4
+ let start = 0;
5
+ let end = text.length;
6
+ if (!Array.isArray(chars)) chars = [chars];
7
+ while (start < end && chars.includes(text[start])) start += 1;
8
+ while (end > start && chars.includes(text[end - 1])) end -= 1;
9
+ return start > 0 || end < text.length ? text.substring(start, end) : text;
10
+ }
11
+ exports.trim = trim;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const defaultOptions = {
4
+ ending: "...",
5
+ maxlength: 100,
6
+ noWordBreak: false
7
+ };
8
+ function truncate(text, options) {
9
+ const conf = { ...defaultOptions, ...options };
10
+ text = text.trim();
11
+ if (conf.noWordBreak) {
12
+ const lastSpaceIndex = text.indexOf(" ", conf.maxlength);
13
+ if (lastSpaceIndex >= conf.maxlength)
14
+ return text.substring(0, lastSpaceIndex) + conf.ending;
15
+ } else if (text.length > conf.maxlength + conf.ending.length) {
16
+ return text.substring(0, conf.maxlength) + conf.ending;
17
+ }
18
+ return text;
19
+ }
20
+ exports.truncate = truncate;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const value_isEmpty = require("./is-empty.cjs");
4
+ exports.isEmpty = value_isEmpty.isEmpty;
@@ -0,0 +1 @@
1
+ export * from './is-empty';
@@ -0,0 +1,4 @@
1
+ import { isEmpty } from "./is-empty.js";
2
+ export {
3
+ isEmpty
4
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const isEmpty = (value) => {
4
+ if (value === void 0) return true;
5
+ if (value === null) return true;
6
+ if (typeof value === "string") return value.trim() === "";
7
+ if (typeof value === "object") {
8
+ if (Array.isArray(value) && value.length === 0) return true;
9
+ if (value instanceof Map || value instanceof Set) return value.size === 0;
10
+ return Object.keys(value).length === 0;
11
+ }
12
+ return false;
13
+ };
14
+ exports.isEmpty = isEmpty;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Checks if the value is `empty`
3
+ *
4
+ * returns `true`, if the value
5
+ *
6
+ * - `undefined`
7
+ * - `null`
8
+ * - `string` and there is no character in the string or all white space
9
+ * - `array` and there is no item in the array
10
+ * - `map` and there is no item in the map
11
+ * - `set` and there is no item in the set
12
+ * - `object` and there is no property in the object
13
+ *
14
+ * otherwise, false
15
+ *
16
+ */
17
+ export declare const isEmpty: (value: unknown) => boolean;
@@ -0,0 +1,14 @@
1
+ const isEmpty = (value) => {
2
+ if (value === void 0) return true;
3
+ if (value === null) return true;
4
+ if (typeof value === "string") return value.trim() === "";
5
+ if (typeof value === "object") {
6
+ if (Array.isArray(value) && value.length === 0) return true;
7
+ if (value instanceof Map || value instanceof Set) return value.size === 0;
8
+ return Object.keys(value).length === 0;
9
+ }
10
+ return false;
11
+ };
12
+ export {
13
+ isEmpty
14
+ };
package/package.json CHANGED
@@ -1,49 +1,69 @@
1
1
  {
2
2
  "name": "@bccampus/utils",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "BCcampus' utility box",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
8
13
  "./array": {
9
14
  "types": "./dist/array/index.d.ts",
10
- "import": "./dist/array/index.js"
15
+ "import": "./dist/array/index.js",
16
+ "require": "./dist/array/index.cjs"
11
17
  },
12
18
  "./date": {
13
19
  "types": "./dist/date/index.d.ts",
14
- "import": "./dist/date/index.js"
20
+ "import": "./dist/date/index.js",
21
+ "require": "./dist/date/index.cjs"
15
22
  },
16
23
  "./duration": {
17
24
  "types": "./dist/duration/index.d.ts",
18
- "import": "./dist/duration/index.js"
25
+ "import": "./dist/duration/index.js",
26
+ "require": "./dist/duration/index.cjs"
19
27
  },
20
28
  "./format": {
21
29
  "types": "./dist/format/index.d.ts",
22
- "import": "./dist/format/index.js"
30
+ "import": "./dist/format/index.js",
31
+ "require": "./dist/format/index.cjs"
23
32
  },
24
33
  "./object": {
25
34
  "types": "./dist/object/index.d.ts",
26
- "import": "./dist/object/index.js"
35
+ "import": "./dist/object/index.js",
36
+ "require": "./dist/object/index.cjs"
27
37
  },
28
38
  "./path": {
29
39
  "types": "./dist/path/index.d.ts",
30
- "import": "./dist/path/index.js"
40
+ "import": "./dist/path/index.js",
41
+ "require": "./dist/path/index.cjs"
31
42
  },
32
43
  "./set": {
33
44
  "types": "./dist/set/index.d.ts",
34
- "import": "./dist/set/index.js"
45
+ "import": "./dist/set/index.js",
46
+ "require": "./dist/set/index.cjs"
35
47
  },
36
48
  "./string": {
37
49
  "types": "./dist/string/index.d.ts",
38
- "import": "./dist/string/index.js"
50
+ "import": "./dist/string/index.js",
51
+ "require": "./dist/string/index.cjs"
39
52
  },
40
53
  "./string/pluralize": {
41
54
  "types": "./dist/string/pluralize/index.d.ts",
42
- "import": "./dist/string/pluralize/index.js"
55
+ "import": "./dist/string/pluralize/index.js",
56
+ "require": "./dist/string/pluralize/index.cjs"
43
57
  },
44
58
  "./string/slugify": {
45
59
  "types": "./dist/string/slugify/index.d.ts",
46
- "import": "./dist/string/slugify/index.js"
60
+ "import": "./dist/string/slugify/index.js",
61
+ "require": "./dist/string/slugify/index.cjs"
62
+ },
63
+ "./value": {
64
+ "types": "./dist/value/index.d.ts",
65
+ "import": "./dist/value/index.js",
66
+ "require": "./dist/value/index.cjs"
47
67
  }
48
68
  },
49
69
  "packageManager": "yarn@4.15.0",
@@ -1,3 +1,3 @@
1
- export * from "./formatter";
2
- export * from "./stringify";
3
- export * from "./template";
1
+ export * from "./formatter";
2
+ export * from "./stringify";
3
+ export * from "./template";
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export const USE_SUBPATH_EXPORTS = true;
@@ -0,0 +1 @@
1
+ export * from "./is-empty";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Checks if the value is `empty`
3
+ *
4
+ * returns `true`, if the value
5
+ *
6
+ * - `undefined`
7
+ * - `null`
8
+ * - `string` and there is no character in the string or all white space
9
+ * - `array` and there is no item in the array
10
+ * - `map` and there is no item in the map
11
+ * - `set` and there is no item in the set
12
+ * - `object` and there is no property in the object
13
+ *
14
+ * otherwise, false
15
+ *
16
+ */
17
+ export const isEmpty = (value: unknown) => {
18
+ if (value === undefined) return true;
19
+ if (value === null) return true;
20
+
21
+ if (typeof value === "string") return value.trim() === "";
22
+ if (typeof value === "object") {
23
+ if (Array.isArray(value) && value.length === 0) return true;
24
+
25
+ if (value instanceof Map || value instanceof Set) return value.size === 0;
26
+
27
+ return Object.keys(value).length === 0;
28
+ }
29
+
30
+ return false;
31
+ };
package/vite.config.ts CHANGED
@@ -1,77 +1,76 @@
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
- });
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
+ require: string;
20
+ }
21
+ >();
22
+
23
+ const files = globSync("src/**/*.ts", {
24
+ cwd: __dirname,
25
+ });
26
+
27
+ for (const file of files) {
28
+ const filePath = file.split(".")[0].replace(/^src[/\\]/, "");
29
+
30
+ if (!filePath) {
31
+ continue;
32
+ }
33
+
34
+ const filePathParts = filePath.split("/");
35
+ if (filePathParts.at(-1) === "index" && filePathParts.length <= 3) {
36
+ const exportPath = filePathParts.length === 1 ? "." : `./${filePathParts.slice(0, -1).join("/")}`;
37
+
38
+ exports.set(exportPath, {
39
+ types: `${outDir}/${filePath}.d.ts`,
40
+ import: `${outDir}/${filePath}.js`,
41
+ require: `${outDir}/${filePath}.cjs`,
42
+ });
43
+ }
44
+
45
+ entries.set(filePath, fileURLToPath(new URL(file, import.meta.url)));
46
+ }
47
+
48
+ const _packageConfig = {
49
+ ...packageConfig,
50
+ exports: Object.fromEntries([...exports].sort((a, b) => a[0].localeCompare(b[0]))),
51
+ };
52
+
53
+ writeFileSync("./package.json", JSON.stringify(_packageConfig, null, 2), {
54
+ encoding: "utf-8",
55
+ });
56
+
57
+ return Object.fromEntries(entries);
58
+ };
59
+
60
+ export default defineConfig({
61
+ plugins: [dts({ tsconfigPath: "./tsconfig.lib.json" })],
62
+ resolve: {
63
+ alias: {
64
+ "@": path.resolve(__dirname, "./src"),
65
+ },
66
+ },
67
+ build: {
68
+ minify: false,
69
+ copyPublicDir: false,
70
+ lib: {
71
+ entry: createEntries(),
72
+ name: "utils",
73
+ formats: ["es", "cjs"],
74
+ },
75
+ },
76
+ });