@bccampus/utils 0.2.2 → 0.2.3

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 (65) hide show
  1. package/dist/array/index.d.ts +2 -1
  2. package/dist/date/index.d.ts +3 -1
  3. package/dist/duration/index.d.ts +4 -3
  4. package/dist/format/index.d.ts +5 -3
  5. package/dist/index.cjs +0 -3
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +1 -4
  8. package/dist/object/index.d.ts +6 -5
  9. package/dist/path/index.d.ts +4 -2
  10. package/dist/set/index.d.ts +6 -5
  11. package/dist/string/index.d.ts +8 -6
  12. package/dist/value/index.d.ts +2 -1
  13. package/package.json +6 -1
  14. package/eslint.config.js +0 -19
  15. package/src/array/chunk.ts +0 -6
  16. package/src/array/index.ts +0 -1
  17. package/src/date/index.ts +0 -1
  18. package/src/date/iso-date-time.ts +0 -356
  19. package/src/duration/add-durations.ts +0 -16
  20. package/src/duration/index.ts +0 -3
  21. package/src/duration/is-duration.ts +0 -5
  22. package/src/duration/to-number.ts +0 -18
  23. package/src/format/formatter.ts +0 -37
  24. package/src/format/index.ts +0 -3
  25. package/src/format/stringify.ts +0 -87
  26. package/src/format/template.ts +0 -48
  27. package/src/index.ts +0 -1
  28. package/src/object/get.ts +0 -9
  29. package/src/object/index.ts +0 -5
  30. package/src/object/is-object.ts +0 -2
  31. package/src/object/omit.ts +0 -21
  32. package/src/object/pick.ts +0 -10
  33. package/src/object/set.ts +0 -15
  34. package/src/path/file-url-to-path.ts +0 -12
  35. package/src/path/index.ts +0 -2
  36. package/src/path/normalize.ts +0 -72
  37. package/src/set/difference.ts +0 -9
  38. package/src/set/index.ts +0 -5
  39. package/src/set/intersection.ts +0 -12
  40. package/src/set/is-superset.ts +0 -12
  41. package/src/set/symmetric-difference.ts +0 -12
  42. package/src/set/union.ts +0 -8
  43. package/src/string/capitalize.ts +0 -2
  44. package/src/string/index.ts +0 -6
  45. package/src/string/normalize.ts +0 -7
  46. package/src/string/pluralize/index.ts +0 -7
  47. package/src/string/pluralize/pluralize.ts +0 -296
  48. package/src/string/pluralize/rules/index.ts +0 -4
  49. package/src/string/pluralize/rules/irregular.ts +0 -59
  50. package/src/string/pluralize/rules/pluralization.ts +0 -40
  51. package/src/string/pluralize/rules/singularization.ts +0 -46
  52. package/src/string/pluralize/rules/uncountable.ts +0 -107
  53. package/src/string/pluralize/types.ts +0 -4
  54. package/src/string/slugify/index.ts +0 -3
  55. package/src/string/strip-html-tags.ts +0 -4
  56. package/src/string/to-int.ts +0 -20
  57. package/src/string/to-sentence-case.ts +0 -6
  58. package/src/string/trim.ts +0 -11
  59. package/src/string/truncate.ts +0 -44
  60. package/src/value/index.ts +0 -1
  61. package/src/value/is-empty.ts +0 -31
  62. package/tsconfig.json +0 -18
  63. package/tsconfig.lib.json +0 -37
  64. package/tsconfig.node.json +0 -25
  65. package/vite.config.ts +0 -76
@@ -1,87 +0,0 @@
1
- import { dateFormatter, formatList, formatNumber } from "./formatter";
2
- import { ISODateTime } from "../date/iso-date-time";
3
-
4
- export interface StringifyValueOptions {
5
- /**
6
- * String value to return when the value undefined or null.
7
- *
8
- * Default Unicode NUL(\u0000) character,
9
- * guarantees that the function always returns a string and
10
- * allows to distinguish invalid values from an empty string.
11
- *
12
- * ```ts
13
- * const stringValue = stringify(value);
14
- * console.log(stringValue !== '\u0000' ? 'Invalid' : stringValue)
15
- * ```
16
- */
17
- invalidValueString?: string;
18
- /**
19
- * `stringify` prepends type info to the return value.
20
- */
21
- withTypeInfo?: boolean;
22
- /**
23
- * If the value is a function that doesn't expect an argument,
24
- * `stringify` calls the function recursively.
25
- */
26
- callFunctions?: boolean;
27
- /**
28
- * `stringify` adds indentation and new lines to object return values.
29
- */
30
- prettyObjects?: boolean;
31
- /**
32
- * `stringify` returns verbose value.
33
- */
34
- verbose?: boolean;
35
- }
36
-
37
- /**
38
- * Returns string representation of the value;
39
- *
40
- * If the valid is null or undefined, returns `options.invalidValueString`.
41
- */
42
- export const stringify = (
43
- value: unknown,
44
- options?: StringifyValueOptions,
45
- ): string => {
46
- const _options = {
47
- invalidValueString: "\u0000", // Unicode NUL
48
- withTypeInfo: options?.verbose,
49
- prettyObjects: options?.verbose,
50
- ...options,
51
- };
52
-
53
- if (value === undefined)
54
- return _options.withTypeInfo ? "[undefined]" : _options.invalidValueString;
55
- if (value === null)
56
- return _options.withTypeInfo ? "[null]" : _options.invalidValueString;
57
-
58
- if (typeof value === "string")
59
- return `${_options.withTypeInfo ? "[string] " : ""}${value}`;
60
- if (typeof value === "number")
61
- return `${_options.withTypeInfo ? "[number] " : ""}${formatNumber(value)}`;
62
- if (typeof value === "bigint")
63
- return `${_options.withTypeInfo ? "[bigint] " : ""}${value}`;
64
- if (typeof value === "boolean")
65
- return `${_options.withTypeInfo ? "[boolean] " : ""}${value}`;
66
- if (typeof value === "object") {
67
- if (Array.isArray(value)) {
68
- const stringfiedValue = value.map((el) => stringify(el, _options));
69
- return `${_options.withTypeInfo ? "[array] " : ""}${_options.verbose ? stringfiedValue.join(", ") : formatList(stringfiedValue)}`;
70
- }
71
-
72
- if (value instanceof Date)
73
- return `${_options.withTypeInfo ? "[date] " : ""}${dateFormatter.format(value)}`;
74
- if (value instanceof ISODateTime)
75
- return `${_options.withTypeInfo ? "[date] " : ""}${value.format()}`;
76
-
77
- return `${_options.withTypeInfo ? "[object] " : ""}${JSON.stringify(value, null, _options.prettyObjects ? 2 : undefined)}`;
78
- }
79
-
80
- if (typeof value === "function")
81
- return `${_options.withTypeInfo ? "[function] " : ""}${_options.callFunctions && value.length === 0 ? stringify(value(), _options) : value.toString()}`;
82
-
83
- if (typeof value === "symbol")
84
- return `${_options.withTypeInfo ? "[symbol] " : ""}${value.toString()}`;
85
-
86
- return _options.invalidValueString;
87
- };
@@ -1,48 +0,0 @@
1
- import { get } from "../object/get";
2
- import { stringify } from "./stringify";
3
-
4
- type TemplateVarValue = unknown | undefined | null;
5
- export type TemplateVar = TemplateVarValue | (() => TemplateVarValue);
6
- export type TemplateVars = Record<string, TemplateVar>;
7
-
8
- const tagRegExp = new RegExp(/\${([a-zA-Z0-9_.]+)}/gm);
9
-
10
- export const template = (text: string, templateVars: TemplateVars) => {
11
- return text.replace(tagRegExp, (match, key) => {
12
- const templateVar = get(templateVars, key) as TemplateVar;
13
- const value =
14
- typeof templateVar === "function" ? templateVar() : templateVar;
15
-
16
- if (value === undefined) return match;
17
- if (value === null) return "";
18
-
19
- return stringify(value, { invalidValueString: "" });
20
- });
21
- };
22
-
23
- export const templateObject = <T extends object>(
24
- obj: T,
25
- templateVars: TemplateVars,
26
- ) => {
27
- const _objClone: Record<string, unknown> = {};
28
-
29
- for (const [key, value] of Object.entries(obj)) {
30
- const _key = template(key, templateVars);
31
-
32
- if (typeof value === "string") {
33
- _objClone[_key] = template(value, templateVars);
34
- } else if (value && typeof value === "object") {
35
- if (Array.isArray(value))
36
- _objClone[_key] = value.map((valueItem) =>
37
- typeof valueItem === "string"
38
- ? template(valueItem, templateVars)
39
- : valueItem,
40
- );
41
- else _objClone[_key] = templateObject(value, templateVars);
42
- } else {
43
- _objClone[_key] = value;
44
- }
45
- }
46
-
47
- return _objClone as T;
48
- };
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export const USE_SUBPATH_EXPORTS = true;
package/src/object/get.ts DELETED
@@ -1,9 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export const get = <T extends object>(object: T, prop: string) =>
3
- prop
4
- .split(".")
5
- .reduce<any>(
6
- (reducedObject, key) =>
7
- reducedObject && key in reducedObject ? reducedObject[key] : undefined,
8
- object,
9
- );
@@ -1,5 +0,0 @@
1
- export * from "./is-object";
2
- export * from "./get";
3
- export * from "./set";
4
- export * from "./omit";
5
- export * from "./pick";
@@ -1,2 +0,0 @@
1
- export const isObject = (object: unknown) =>
2
- typeof object === "object" && !Array.isArray(object) && object !== null;
@@ -1,21 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export const omit = <T extends object>(object: T, props: string[]) => {
3
- const result: Partial<T> = { ...object };
4
-
5
- props.forEach((prop) => {
6
- const propChunks = prop.split(".");
7
- const lastChunk = propChunks.pop();
8
- if (lastChunk) {
9
- const ref = propChunks.reduce<any>(
10
- (reducedObject, key) =>
11
- reducedObject && key in reducedObject
12
- ? reducedObject[key]
13
- : undefined,
14
- result,
15
- );
16
- if (ref && lastChunk in ref) delete ref[lastChunk];
17
- }
18
- });
19
-
20
- return result;
21
- };
@@ -1,10 +0,0 @@
1
- import { set } from ".";
2
- import { get } from "./get";
3
-
4
- export const pick = <T extends object>(object: T, props: string[]) => {
5
- return props.reduce<Record<string, unknown>>((result, key) => {
6
- set(result, key, get(object, key));
7
-
8
- return result;
9
- }, {}) as Partial<T>;
10
- };
package/src/object/set.ts DELETED
@@ -1,15 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export const set = <T extends object, V>(object: T, prop: string, value: V) => {
3
- const propChunks = prop.split(".");
4
- const lastChunk = propChunks.pop();
5
- if (!lastChunk) return object;
6
-
7
- const ref = propChunks.reduce<any>((reducedObject, key) => {
8
- if (reducedObject[key] === undefined) reducedObject[key] = {};
9
- return reducedObject[key];
10
- }, object);
11
-
12
- ref[lastChunk] = value;
13
-
14
- return object;
15
- };
@@ -1,12 +0,0 @@
1
- const windowsDriveRegExp = /^\/[a-zA-Z1-9_-]+:\//;
2
-
3
- /**
4
- * Browser compatible version of `node:url.fileURLToPath`
5
- */
6
- export function fileURLToPath(fileUrl: string) {
7
- const url = new URL(fileUrl);
8
- let path = decodeURIComponent(url.pathname);
9
- if (windowsDriveRegExp.test(path)) path = path.slice(1);
10
-
11
- return path;
12
- }
package/src/path/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./normalize";
2
- export * from "./file-url-to-path";
@@ -1,72 +0,0 @@
1
- import { fileURLToPath } from "./file-url-to-path";
2
-
3
- export interface NormalizeOptions {
4
- /**
5
- * - `always`: ensure leading slash exists
6
- * - `never`: ensure leading slash does not exist
7
- * - `as-is`: do not modify the leading char
8
- *
9
- * @default "always"
10
- */
11
- leadingSlash?: "always" | "never" | "as-is";
12
-
13
- /**
14
- * - `always`: ensure trailing slash exists
15
- * - `never`: ensure trailing slash does not exist
16
- * - `as-is`: do not modify the trailing char
17
- *
18
- * @default "never"
19
- */
20
- trailingSlash?: "always" | "never" | "as-is";
21
- }
22
-
23
- const defaultOptions: Required<NormalizeOptions> = {
24
- leadingSlash: "always",
25
- trailingSlash: "never",
26
- };
27
-
28
- const windowsPathSepRegExp = /[\\]+/g;
29
- const unixPathSepRegExp = /[/]+/g;
30
- const windowsDriveRegExp = /^[a-zA-Z1-9_-]+:\//;
31
- const fileProtocolRegExp = /^file:\/\//;
32
- const leadingSlashRegExp = /^\//g;
33
- const trailingSlashRegExp = /\/$/g;
34
-
35
- /**
36
- * Clears and converts the provided path to a Posix filepath
37
- *
38
- * By default, adds a leading slash and removes the trailing
39
- *
40
- * @example
41
- * ```
42
- * normalize("src/test/"); //returns: /src/test
43
- * normalize("C:\\Users\\test\\folder\\"); //returns: C:/Users/test/folder
44
- * normalize("file:///C:/Users/test/folder/file.ts"); //returns: C:/Users/test/folder/file.ts
45
- * ```
46
- */
47
- export function normalize(path: string, options?: NormalizeOptions) {
48
- const conf = { ...defaultOptions, ...options };
49
- const sep = "\\";
50
- let normalPath = path.trim();
51
-
52
- if (fileProtocolRegExp.test(normalPath))
53
- normalPath = fileURLToPath(normalPath);
54
-
55
- normalPath = normalPath
56
- .replace(windowsPathSepRegExp, sep) // windows -> linux
57
- .replace(unixPathSepRegExp, sep); // multiple -> single
58
-
59
- if (conf.leadingSlash !== "as-is") {
60
- normalPath = normalPath.replace(leadingSlashRegExp, "");
61
-
62
- if (conf.leadingSlash === "always" && !windowsDriveRegExp.test(normalPath))
63
- normalPath = `${sep}${normalPath}`;
64
- }
65
-
66
- if (conf.trailingSlash !== "as-is") {
67
- normalPath = normalPath.replace(trailingSlashRegExp, "");
68
- if (conf.trailingSlash === "always") normalPath = `${normalPath}${sep}`;
69
- }
70
-
71
- return normalPath;
72
- }
@@ -1,9 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- export function difference(setA: Iterable<any>, setB: Iterable<any>) {
4
- const _difference = new Set(setA);
5
- for (const elem of setB) {
6
- _difference.delete(elem);
7
- }
8
- return _difference;
9
- }
package/src/set/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./union";
2
- export * from "./intersection";
3
- export * from "./is-superset";
4
- export * from "./difference";
5
- export * from "./symmetric-difference";
@@ -1,12 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export function intersection(setA: Iterable<any>, setB: Iterable<any>) {
3
- const _setA = setA instanceof Set ? setA : new Set(setA);
4
-
5
- const _intersection = new Set();
6
- for (const elem of setB) {
7
- if (_setA.has(elem)) {
8
- _intersection.add(elem);
9
- }
10
- }
11
- return _intersection;
12
- }
@@ -1,12 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- export function isSuperset(set: Iterable<any>, subset: Iterable<any>) {
4
- const _set = set instanceof Set ? set : new Set(set);
5
-
6
- for (const elem of subset) {
7
- if (!_set.has(elem)) {
8
- return false;
9
- }
10
- }
11
- return true;
12
- }
@@ -1,12 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export function symmetricDifference(setA: Iterable<any>, setB: Iterable<any>) {
3
- const _difference = new Set(setA);
4
- for (const elem of setB) {
5
- if (_difference.has(elem)) {
6
- _difference.delete(elem);
7
- } else {
8
- _difference.add(elem);
9
- }
10
- }
11
- return _difference;
12
- }
package/src/set/union.ts DELETED
@@ -1,8 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export function union(setA: Iterable<any>, setB: Iterable<any>) {
3
- const _union = new Set(setA);
4
- for (const elem of setB) {
5
- _union.add(elem);
6
- }
7
- return _union;
8
- }
@@ -1,2 +0,0 @@
1
- export const capitalize = <T extends string>(s: T) =>
2
- (s[0].toUpperCase() + s.slice(1)) as Capitalize<typeof s>;
@@ -1,6 +0,0 @@
1
- export * from "./truncate";
2
- export * from "./trim";
3
- export * from "./strip-html-tags";
4
- export * from "./capitalize";
5
- export * from "./to-sentence-case";
6
- export * from "./to-int";
@@ -1,7 +0,0 @@
1
- /**
2
- * Trims white spaces and
3
- * replaces multiple white space characters with a single space
4
- */
5
- export function normalize(text: string) {
6
- return text.trim().replace(/\s+/g, " ");
7
- }
@@ -1,7 +0,0 @@
1
- import { Pluralize } from "./pluralize";
2
-
3
- const pluralize = new Pluralize();
4
-
5
- export type * from "./types";
6
-
7
- export { pluralize, Pluralize };