@germondai/ts-utils 0.0.5 → 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/dist/module.d.ts +1 -0
- package/dist/module.js +452 -16
- package/dist/runtime/array.d.ts +163 -0
- package/dist/runtime/collection.d.ts +1 -53
- package/dist/runtime/color.d.ts +49 -0
- package/dist/runtime/convertor.d.ts +8 -3
- package/dist/runtime/crypto.d.ts +21 -0
- package/dist/runtime/data.d.ts +1 -1
- package/dist/runtime/function.d.ts +52 -0
- package/dist/runtime/index.d.ts +7 -1
- package/dist/runtime/math.d.ts +63 -0
- package/dist/runtime/normalize.d.ts +1 -0
- package/dist/runtime/object.d.ts +70 -0
- package/dist/runtime/promise.d.ts +30 -0
- package/dist/runtime/string.d.ts +67 -24
- package/dist/runtime/type.d.ts +49 -0
- package/dist/types.d.ts +52 -0
- package/package.json +16 -4
package/dist/runtime/string.d.ts
CHANGED
|
@@ -1,38 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Reverses a string.
|
|
3
3
|
*
|
|
4
|
-
* @param str - The string to
|
|
5
|
-
* @returns The
|
|
4
|
+
* @param str - The string to reverse.
|
|
5
|
+
* @returns The reversed string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* reverse("hello") // "olleh"
|
|
9
|
+
*/
|
|
10
|
+
export declare const reverse: (str: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Counts the number of occurrences of a substring in a string.
|
|
13
|
+
*
|
|
14
|
+
* @param str - The string to search in.
|
|
15
|
+
* @param search - The substring to search for.
|
|
16
|
+
* @returns The number of occurrences.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* countOccurrences("hello world hello", "hello") // 2
|
|
20
|
+
*/
|
|
21
|
+
export declare const countOccurrences: (str: string, search: string) => number;
|
|
22
|
+
/**
|
|
23
|
+
* Pads a string to the specified length with the given character.
|
|
24
|
+
*
|
|
25
|
+
* @param str - The string to pad.
|
|
26
|
+
* @param length - The desired length.
|
|
27
|
+
* @param char - The character to pad with (default: ' ').
|
|
28
|
+
* @param direction - The padding direction: 'left', 'right', or 'both' (default: 'left').
|
|
29
|
+
* @returns The padded string.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* pad("5", 3, "0") // "005"
|
|
33
|
+
* pad("hi", 6, " ", "both") // " hi "
|
|
6
34
|
*/
|
|
7
|
-
export declare const
|
|
35
|
+
export declare const pad: (str: string, length: number, char?: string, direction?: "left" | "right" | "both") => string;
|
|
8
36
|
/**
|
|
9
|
-
*
|
|
37
|
+
* Masks a string, showing only the last N characters.
|
|
10
38
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
39
|
+
* @param str - The string to mask.
|
|
40
|
+
* @param visibleCount - The number of characters to leave visible at the end (default: 4).
|
|
41
|
+
* @param maskChar - The character to use for masking (default: '*').
|
|
42
|
+
* @returns The masked string.
|
|
13
43
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @returns The truncated string.
|
|
44
|
+
* @example
|
|
45
|
+
* mask("1234567890") // "******7890"
|
|
46
|
+
* mask("secret", 2, "#") // "####et"
|
|
18
47
|
*/
|
|
19
|
-
export declare const
|
|
48
|
+
export declare const mask: (str: string, visibleCount?: number, maskChar?: string) => string;
|
|
20
49
|
/**
|
|
21
|
-
*
|
|
50
|
+
* Extracts initials from a name.
|
|
22
51
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* and limits the slug length.
|
|
52
|
+
* @param name - The full name.
|
|
53
|
+
* @returns The uppercase initials.
|
|
26
54
|
*
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
29
|
-
*
|
|
55
|
+
* @example
|
|
56
|
+
* initials("John Doe") // "JD"
|
|
57
|
+
* initials("Alice Bob Charlie") // "ABC"
|
|
30
58
|
*/
|
|
31
|
-
export declare const
|
|
59
|
+
export declare const initials: (name: string) => string;
|
|
32
60
|
/**
|
|
33
|
-
*
|
|
61
|
+
* Counts the number of words in a string.
|
|
62
|
+
*
|
|
63
|
+
* @param str - The string to count words in.
|
|
64
|
+
* @returns The number of words.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* wordCount("Hello world") // 2
|
|
68
|
+
*/
|
|
69
|
+
export declare const wordCount: (str: string) => number;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a string is empty or contains only whitespace.
|
|
72
|
+
*
|
|
73
|
+
* @param str - The string to check.
|
|
74
|
+
* @returns True if the string is blank.
|
|
34
75
|
*
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
76
|
+
* @example
|
|
77
|
+
* isBlank("") // true
|
|
78
|
+
* isBlank(" ") // true
|
|
79
|
+
* isBlank("hello") // false
|
|
37
80
|
*/
|
|
38
|
-
export declare const
|
|
81
|
+
export declare const isBlank: (str: string) => boolean;
|
package/dist/runtime/type.d.ts
CHANGED
|
@@ -48,3 +48,52 @@ export declare const isEmpty: (value: unknown) => boolean;
|
|
|
48
48
|
*
|
|
49
49
|
*/
|
|
50
50
|
export declare const isJSON: (value: string) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a value is a function.
|
|
53
|
+
*
|
|
54
|
+
* @param value - The value to check.
|
|
55
|
+
* @returns True if the value is a function.
|
|
56
|
+
*/
|
|
57
|
+
export declare const isFunction: (value: unknown) => value is Function;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a value is a valid Date instance.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The value to check.
|
|
62
|
+
* @returns True if the value is a valid Date.
|
|
63
|
+
*/
|
|
64
|
+
export declare const isDate: (value: unknown) => value is Date;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a value is a number (and not NaN).
|
|
67
|
+
*
|
|
68
|
+
* @param value - The value to check.
|
|
69
|
+
* @returns True if the value is a finite number.
|
|
70
|
+
*/
|
|
71
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a value is a string.
|
|
74
|
+
*
|
|
75
|
+
* @param value - The value to check.
|
|
76
|
+
* @returns True if the value is a string.
|
|
77
|
+
*/
|
|
78
|
+
export declare const isString: (value: unknown) => value is string;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a value is a boolean.
|
|
81
|
+
*
|
|
82
|
+
* @param value - The value to check.
|
|
83
|
+
* @returns True if the value is a boolean.
|
|
84
|
+
*/
|
|
85
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if a value is null or undefined.
|
|
88
|
+
*
|
|
89
|
+
* @param value - The value to check.
|
|
90
|
+
* @returns True if the value is null or undefined.
|
|
91
|
+
*/
|
|
92
|
+
export declare const isNil: (value: unknown) => value is null | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if a value is a RegExp instance.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to check.
|
|
97
|
+
* @returns True if the value is a RegExp.
|
|
98
|
+
*/
|
|
99
|
+
export declare const isRegExp: (value: unknown) => value is RegExp;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Flatten intersections for readable hover types */
|
|
2
|
+
export type Prettify<T> = {
|
|
3
|
+
[K in keyof T]: T[K];
|
|
4
|
+
} & {};
|
|
5
|
+
/** Recursive Partial — makes all properties optional at every depth */
|
|
6
|
+
export type DeepPartial<T> = {
|
|
7
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
8
|
+
};
|
|
9
|
+
/** Recursive Required — makes all properties required at every depth */
|
|
10
|
+
export type DeepRequired<T> = {
|
|
11
|
+
[K in keyof T]-?: T[K] extends object ? DeepRequired<T[K]> : T[K];
|
|
12
|
+
};
|
|
13
|
+
/** Recursive Readonly — makes all properties readonly at every depth */
|
|
14
|
+
export type DeepReadonly<T> = {
|
|
15
|
+
readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
|
|
16
|
+
};
|
|
17
|
+
/** Makes a type nullable */
|
|
18
|
+
export type Nullable<T> = T | null;
|
|
19
|
+
/** Makes a type nullable or undefined */
|
|
20
|
+
export type Maybe<T> = T | null | undefined;
|
|
21
|
+
/** Recursively removes null and undefined from all properties */
|
|
22
|
+
export type NonNullableDeep<T> = {
|
|
23
|
+
[K in keyof T]: T[K] extends object ? NonNullableDeep<NonNullable<T[K]>> : NonNullable<T[K]>;
|
|
24
|
+
};
|
|
25
|
+
/** Omit that enforces K extends keyof T */
|
|
26
|
+
export type StrictOmit<T, K extends keyof T> = Omit<T, K>;
|
|
27
|
+
/** Extract that enforces U extends T */
|
|
28
|
+
export type StrictExtract<T, U extends T> = Extract<T, U>;
|
|
29
|
+
/** Get the union of all property value types */
|
|
30
|
+
export type ValueOf<T> = T[keyof T];
|
|
31
|
+
/** Typed Object.entries return type */
|
|
32
|
+
export type Entries<T> = {
|
|
33
|
+
[K in keyof T]: [K, T[K]];
|
|
34
|
+
}[keyof T][];
|
|
35
|
+
/** Convert a union type to an intersection type */
|
|
36
|
+
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
37
|
+
/** Require at least one of the specified keys */
|
|
38
|
+
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> & {
|
|
39
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
|
40
|
+
}[Keys];
|
|
41
|
+
/** Require exactly one of the specified keys */
|
|
42
|
+
export type RequireExactlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> & {
|
|
43
|
+
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
|
44
|
+
}[Keys];
|
|
45
|
+
/** Remove readonly from all properties */
|
|
46
|
+
export type Mutable<T> = {
|
|
47
|
+
-readonly [K in keyof T]: T[K];
|
|
48
|
+
};
|
|
49
|
+
/** Make specific keys optional */
|
|
50
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
51
|
+
/** Make specific keys required */
|
|
52
|
+
export type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@germondai/ts-utils",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Germond's TypeScript Utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
},
|
|
9
9
|
"author": "germondai",
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"typescript",
|
|
13
|
+
"utilities",
|
|
14
|
+
"utils",
|
|
15
|
+
"helpers",
|
|
16
|
+
"type-utils",
|
|
17
|
+
"string-utils",
|
|
18
|
+
"array-utils",
|
|
19
|
+
"object-utils"
|
|
20
|
+
],
|
|
11
21
|
"type": "module",
|
|
12
22
|
"exports": {
|
|
13
23
|
".": {
|
|
@@ -22,6 +32,8 @@
|
|
|
22
32
|
"dist"
|
|
23
33
|
],
|
|
24
34
|
"scripts": {
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"test:watch": "bun test --watch",
|
|
25
37
|
"prepack": "bun run build",
|
|
26
38
|
"build": "bun build --target=node ./src/module.ts --outfile=dist/module.js && bun run build:types",
|
|
27
39
|
"build:types": "tsc --emitDeclarationOnly --project tsconfig.types.json",
|
|
@@ -31,10 +43,10 @@
|
|
|
31
43
|
"fmt": "bun prettier:fix"
|
|
32
44
|
},
|
|
33
45
|
"devDependencies": {
|
|
34
|
-
"@types/bun": "
|
|
35
|
-
"prettier": "^3.
|
|
46
|
+
"@types/bun": "^1.3.9",
|
|
47
|
+
"prettier": "^3.8.1"
|
|
36
48
|
},
|
|
37
49
|
"peerDependencies": {
|
|
38
|
-
"typescript": "^5.
|
|
50
|
+
"typescript": "^5.9.3"
|
|
39
51
|
}
|
|
40
52
|
}
|