js-utils-kit 0.3.0 → 0.3.1
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 +49 -16
- package/dist/char/index.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/string/index.cjs +1 -1
- package/dist/string/index.d.ts +76 -42
- package/dist/string/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,20 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/TenEplaysOfficial/js-utils-kit)
|
|
4
4
|
|
|
5
|
-
[](https://github.com/TenEplaysOfficial/js-utils-kit)
|
|
6
|
+
[](https://www.npmjs.com/package/js-utils-kit)
|
|
7
|
+
[](https://jsr.io/@tene/js-utils-kit)
|
|
8
|
+
[](https://jsr.io/@tene/js-utils-kit)
|
|
9
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit/blob/main/LICENSE)
|
|
10
|
+
[](https://bundlephobia.com/package/js-utils-kit)
|
|
11
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit/stargazers)
|
|
12
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit/issues)
|
|
13
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit/pulls)
|
|
14
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit/commits)
|
|
15
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit/discussions)
|
|
16
|
+
[](https://www.npmjs.com/package/js-utils-kit)
|
|
17
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit)
|
|
18
|
+
[](https://github.com/TenEplaysOfficial/js-utils-kit)
|
|
19
|
+
[](https://github.com/sponsors/TenEplaysOfficial)
|
|
20
|
+
[](https://x.com/teneplays)
|
|
19
21
|
|
|
20
22
|
</div>
|
|
21
23
|
|
|
@@ -28,9 +30,26 @@ This package includes utilities designed for both browser and Node.js environmen
|
|
|
28
30
|
## Installation
|
|
29
31
|
|
|
30
32
|
```sh
|
|
31
|
-
|
|
32
|
-
# or
|
|
33
|
+
# via npm
|
|
33
34
|
npm install js-utils-kit
|
|
35
|
+
|
|
36
|
+
# via yarn
|
|
37
|
+
yarn add js-utils-kit
|
|
38
|
+
|
|
39
|
+
# via pnpm
|
|
40
|
+
pnpm add js-utils-kit
|
|
41
|
+
|
|
42
|
+
# via bun
|
|
43
|
+
bun add js-utils-kit
|
|
44
|
+
|
|
45
|
+
# via Deno (using npm)
|
|
46
|
+
deno add npm:js-utils-kit
|
|
47
|
+
|
|
48
|
+
# via Deno (using JSR)
|
|
49
|
+
deno add jsr:@tene/js-utils-kit
|
|
50
|
+
|
|
51
|
+
# via JSR
|
|
52
|
+
npx jsr add @tene/js-utils-kit
|
|
34
53
|
```
|
|
35
54
|
|
|
36
55
|
## Usage
|
|
@@ -77,6 +96,20 @@ console.log(string.capitalize('js-utils-kit')); // 'Js-utils-kit'
|
|
|
77
96
|
console.log(env.isDev()); // true/false
|
|
78
97
|
```
|
|
79
98
|
|
|
99
|
+
### Using JSR or Deno
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { number, string, env } from '@tene/js-utils-kit';
|
|
103
|
+
// or
|
|
104
|
+
import { number, string, env } from 'jsr:@tene/js-utils-kit';
|
|
105
|
+
// or
|
|
106
|
+
import number from '@tene/js-utils-kit/number';
|
|
107
|
+
import string from '@tene/js-utils-kit/string';
|
|
108
|
+
import array from '@tene/js-utils-kit/array';
|
|
109
|
+
import object from '@tene/js-utils-kit/object';
|
|
110
|
+
import env from '@tene/js-utils-kit/env';
|
|
111
|
+
```
|
|
112
|
+
|
|
80
113
|
### CommonJS Usage
|
|
81
114
|
|
|
82
115
|
```js
|
package/dist/char/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates an array of lowercase ASCII alphabet characters (a–z).
|
|
3
3
|
*
|
|
4
|
-
* @returns
|
|
4
|
+
* @returns An array containing 'a' to 'z'.
|
|
5
5
|
* @example
|
|
6
6
|
* lowercase(); // ['a', 'b', ..., 'z']
|
|
7
7
|
*/
|
|
@@ -9,7 +9,7 @@ declare const lowercase: () => string[];
|
|
|
9
9
|
/**
|
|
10
10
|
* Generates an array of uppercase ASCII alphabet characters (A–Z).
|
|
11
11
|
*
|
|
12
|
-
* @returns
|
|
12
|
+
* @returns An array containing 'A' to 'Z'.
|
|
13
13
|
* @example
|
|
14
14
|
* uppercase(); // ['A', 'B', ..., 'Z']
|
|
15
15
|
*/
|
|
@@ -17,7 +17,7 @@ declare const uppercase: () => string[];
|
|
|
17
17
|
/**
|
|
18
18
|
* Generates an array of ASCII digit characters (0–9).
|
|
19
19
|
*
|
|
20
|
-
* @returns
|
|
20
|
+
* @returns An array containing '0' to '9'.
|
|
21
21
|
* @example
|
|
22
22
|
* digits(); // ['0', '1', ..., '9']
|
|
23
23
|
*/
|
|
@@ -25,7 +25,7 @@ declare const digits: () => string[];
|
|
|
25
25
|
/**
|
|
26
26
|
* Combines lowercase, uppercase, and digit characters into a single array.
|
|
27
27
|
*
|
|
28
|
-
* @returns
|
|
28
|
+
* @returns An array containing 'a'–'z', 'A'–'Z', and '0'–'9'.
|
|
29
29
|
* @example
|
|
30
30
|
* all(); // ['a', ..., 'z', 'A', ..., 'Z', '0', ..., '9']
|
|
31
31
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { Environment, default as env, getRunTimeEnvironment, isBrowser, isDev, i
|
|
|
4
4
|
export { ArchiveFormat, CreateArchiveOptions, createArchive, default as file } from './file/index.js';
|
|
5
5
|
export { clamp, isEven, isOdd, default as number, randomFloat, randomInt } from './number/index.js';
|
|
6
6
|
export { isEmptyObject, isNonEmptyObject, isObject, mergeObj, default as object } from './object/index.js';
|
|
7
|
-
export { capitalize, containsWhitespace, endsWithPunctuation, isAlphabetic, isCamelCase, isEmail, isKebabCase, isLowerCase, isNonEmptyString, isNumericString, isPascalCase, isSnakeCase, isString, isURL, isUpperCase, padLeft, padRight, repeatString, startsWithUppercase, default as string, trim, truncate } from './string/index.js';
|
|
7
|
+
export { Trim, capitalize, containsWhitespace, endsWithPunctuation, isAlphabetic, isCamelCase, isEmail, isKebabCase, isLowerCase, isNonEmptyString, isNumericString, isPascalCase, isSnakeCase, isString, isURL, isUpperCase, padLeft, padRight, repeatString, startsWithUppercase, default as string, trim, truncate } from './string/index.js';
|
|
8
8
|
export { ArchiverOptions } from 'archiver';
|
|
9
9
|
|
|
10
10
|
/**
|
package/dist/string/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t){return t.replace(/^\w/,t=>t.toUpperCase())}function e(t,e,r=" "){return t.padStart(e,r)}function r(t,e,r=" "){return t.padEnd(e,r)}function s(t,e,r="..."){return t.length>e?t.slice(0,e-r.length)+r:t}function n(t,e){return t.repeat(e)}Object.defineProperty(exports,"__esModule",{value:!0});const i={function:t=>t.trim(),start:t=>t.trimStart(),end:t=>t.trimEnd(),normalizeWhitespace:t=>t.trim().replace(/\s+/g," ")};function a(t){return null!=t&&"string"==typeof t}function o(t,e=!0){return!!a(t)&&(e?t.trim().length>0:t.length>0)}function p(t){try{return new URL(t),!0}catch{return!1}}function u(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function c(t){return/^[a-zA-Z]+$/.test(t)}function f(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}function l(t){return/^[A-Z]/.test(t)}function x(t){return/[\p{P}]$/u.test(t)}function
|
|
1
|
+
"use strict";function t(t){return t.replace(/^\w/,t=>t.toUpperCase())}function e(t,e,r=" "){return t.padStart(e,r)}function r(t,e,r=" "){return t.padEnd(e,r)}function s(t,e,r="..."){return t.length>e?t.slice(0,e-r.length)+r:t}function n(t,e){return t.repeat(e)}Object.defineProperty(exports,"__esModule",{value:!0});const i={function:t=>t.trim(),start:t=>t.trimStart(),end:t=>t.trimEnd(),normalizeWhitespace:t=>t.trim().replace(/\s+/g," ")};function a(t){return null!=t&&"string"==typeof t}function o(t,e=!0){return!!a(t)&&("string"==typeof t&&(e?t.trim().length>0:t.length>0))}function p(t){try{return new URL(t),!0}catch{return!1}}function u(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function c(t){return/^[a-zA-Z]+$/.test(t)}function f(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}function l(t){return/^[A-Z]/.test(t)}function x(t){return/[\p{P}]$/u.test(t)}function g(t){return/\s/.test(t)}function m(t){return/^[a-z][a-zA-Z0-9]*$/.test(t)}function h(t){return/^[A-Z][a-zA-Z0-9]*$/.test(t)}function C(t){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(t)}function d(t){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(t)}function z(t){return/^[A-Z]+$/.test(t)}function S(t){return/^[a-z]+$/.test(t)}var N={capitalize:t,padLeft:e,padRight:r,truncate:s,repeatString:n,trim:i,isString:a,isNonEmptyString:o,isURL:p,isEmail:u,isAlphabetic:c,isNumericString:f,startsWithUppercase:l,endsWithPunctuation:x,containsWhitespace:g,isCamelCase:m,isPascalCase:h,isKebabCase:C,isSnakeCase:d,isUpperCase:z,isLowerCase:S};exports.capitalize=t,exports.containsWhitespace=g,exports.default=N,exports.endsWithPunctuation=x,exports.isAlphabetic=c,exports.isCamelCase=m,exports.isEmail=u,exports.isKebabCase=C,exports.isLowerCase=S,exports.isNonEmptyString=o,exports.isNumericString=f,exports.isPascalCase=h,exports.isSnakeCase=d,exports.isString=a,exports.isURL=p,exports.isUpperCase=z,exports.padLeft=e,exports.padRight=r,exports.repeatString=n,exports.startsWithUppercase=l,exports.trim=i,exports.truncate=s;
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String trimming utilities.
|
|
3
|
+
* Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.
|
|
4
|
+
*/
|
|
5
|
+
interface Trim {
|
|
6
|
+
/**
|
|
7
|
+
* Removes whitespace from both ends of a string.
|
|
8
|
+
*
|
|
9
|
+
* @param str - The string to trim.
|
|
10
|
+
* @returns The trimmed string.
|
|
11
|
+
*/
|
|
12
|
+
function(str: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Removes leading whitespace from a string.
|
|
15
|
+
*
|
|
16
|
+
* @param str - The string to trim.
|
|
17
|
+
* @returns The string with leading whitespace removed.
|
|
18
|
+
*/
|
|
19
|
+
start(str: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Removes trailing whitespace from a string.
|
|
22
|
+
*
|
|
23
|
+
* @param str - The string to trim.
|
|
24
|
+
* @returns The string with trailing whitespace removed.
|
|
25
|
+
*/
|
|
26
|
+
end(str: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Trims the string and replaces sequences of whitespace with a single space.
|
|
29
|
+
*
|
|
30
|
+
* @param str - The string to normalize.
|
|
31
|
+
* @returns The string with normalized whitespace.
|
|
32
|
+
*/
|
|
33
|
+
normalizeWhitespace(str: string): string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* String trimming utilities.
|
|
37
|
+
* Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.
|
|
38
|
+
*
|
|
39
|
+
* @param str - The string to trim.
|
|
40
|
+
*
|
|
41
|
+
* @returns The string with leading and trailing whitespace removed.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* - The main callable form behaves like {@link String.prototype.trim}, removing whitespace from both ends.
|
|
45
|
+
* - `.start` removes only leading whitespace (like {@link String.prototype.trimStart}).
|
|
46
|
+
* - `.end` removes only trailing whitespace (like {@link String.prototype.trimEnd}).
|
|
47
|
+
* - `.normalizeWhitespace` trims the string and replaces any sequence of whitespace characters with a single space.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Trim both sides
|
|
52
|
+
* console.log(trim(" hello ")); // "hello"
|
|
53
|
+
* console.log(trim("")); // ""
|
|
54
|
+
* console.log(trim("hello")); // "hello"
|
|
55
|
+
*
|
|
56
|
+
* // Trim leading whitespace
|
|
57
|
+
* console.log(trim.start(" hello ")); // "hello "
|
|
58
|
+
* console.log(trim.start("")); // ""
|
|
59
|
+
* console.log(trim.start("hello")); // "hello"
|
|
60
|
+
*
|
|
61
|
+
* // Trim trailing whitespace
|
|
62
|
+
* console.log(trim.end(" hello ")); // " hello"
|
|
63
|
+
* console.log(trim.end("")); // ""
|
|
64
|
+
* console.log(trim.end("hello")); // "hello"
|
|
65
|
+
*
|
|
66
|
+
* // Normalize whitespace
|
|
67
|
+
* console.log(trim.normalizeWhitespace(" hello world ")); // "hello world"
|
|
68
|
+
* console.log(trim.normalizeWhitespace("hello\t world")); // "hello world"
|
|
69
|
+
* console.log(trim.normalizeWhitespace("")); // ""
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare const trim: Trim;
|
|
73
|
+
|
|
1
74
|
/**
|
|
2
75
|
* Capitalizes the first character of a string using a regular expression.
|
|
3
76
|
*
|
|
@@ -75,41 +148,6 @@ declare function truncate(str: string, length: number, suffix?: string): string;
|
|
|
75
148
|
*/
|
|
76
149
|
declare function repeatString(str: string, count: number): string;
|
|
77
150
|
|
|
78
|
-
/**
|
|
79
|
-
* String trimming utilities.
|
|
80
|
-
* Trims whitespace from a string (both sides by default) with methods for leading and trailing and normalizing whitespace.
|
|
81
|
-
* @param str - The string to trim.
|
|
82
|
-
* @returns The string with leading and trailing whitespace removed.
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* // Trim both sides
|
|
86
|
-
* console.log(trim(" hello ")); // "hello"
|
|
87
|
-
* console.log(trim("")); // ""
|
|
88
|
-
* console.log(trim("hello")); // "hello"
|
|
89
|
-
*
|
|
90
|
-
* // Trim leading whitespace
|
|
91
|
-
* console.log(trim.start(" hello ")); // "hello "
|
|
92
|
-
* console.log(trim.start("")); // ""
|
|
93
|
-
* console.log(trim.start("hello")); // "hello"
|
|
94
|
-
*
|
|
95
|
-
* // Trim trailing whitespace
|
|
96
|
-
* console.log(trim.end(" hello ")); // " hello"
|
|
97
|
-
* console.log(trim.end("")); // ""
|
|
98
|
-
* console.log(trim.end("hello")); // "hello"
|
|
99
|
-
*
|
|
100
|
-
* // Normalize whitespace
|
|
101
|
-
* console.log(trim.normalizeWhitespace(" hello world ")); // "hello world"
|
|
102
|
-
* console.log(trim.normalizeWhitespace("hello\t world")); // "hello world"
|
|
103
|
-
* console.log(trim.normalizeWhitespace("")); // ""
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
declare const trim: {
|
|
107
|
-
function(str: string): string;
|
|
108
|
-
start: (str: string) => string;
|
|
109
|
-
end: (str: string) => string;
|
|
110
|
-
normalizeWhitespace: (str: string) => string;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
151
|
/**
|
|
114
152
|
* Determines whether the provided value is a string.
|
|
115
153
|
*
|
|
@@ -134,7 +172,7 @@ declare const trim: {
|
|
|
134
172
|
* }
|
|
135
173
|
* ```
|
|
136
174
|
*/
|
|
137
|
-
declare function isString<T>(value: T):
|
|
175
|
+
declare function isString<T>(value: T): boolean;
|
|
138
176
|
/**
|
|
139
177
|
* Determines whether the given value is a non-empty string.
|
|
140
178
|
*
|
|
@@ -353,12 +391,7 @@ declare const _default: {
|
|
|
353
391
|
padRight: typeof padRight;
|
|
354
392
|
truncate: typeof truncate;
|
|
355
393
|
repeatString: typeof repeatString;
|
|
356
|
-
trim:
|
|
357
|
-
function(str: string): string;
|
|
358
|
-
start: (str: string) => string;
|
|
359
|
-
end: (str: string) => string;
|
|
360
|
-
normalizeWhitespace: (str: string) => string;
|
|
361
|
-
};
|
|
394
|
+
trim: Trim;
|
|
362
395
|
isString: typeof isString;
|
|
363
396
|
isNonEmptyString: typeof isNonEmptyString;
|
|
364
397
|
isURL: typeof isURL;
|
|
@@ -377,3 +410,4 @@ declare const _default: {
|
|
|
377
410
|
};
|
|
378
411
|
|
|
379
412
|
export { capitalize, containsWhitespace, _default as default, endsWithPunctuation, isAlphabetic, isCamelCase, isEmail, isKebabCase, isLowerCase, isNonEmptyString, isNumericString, isPascalCase, isSnakeCase, isString, isURL, isUpperCase, padLeft, padRight, repeatString, startsWithUppercase, trim, truncate };
|
|
413
|
+
export type { Trim };
|
package/dist/string/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t){return t.replace(/^\w/,t=>t.toUpperCase())}function n(t,n,e=" "){return t.padStart(n,e)}function e(t,n,e=" "){return t.padEnd(n,e)}function r(t,n,e="..."){return t.length>n?t.slice(0,n-e.length)+e:t}function i(t,n){return t.repeat(n)}const a={function:t=>t.trim(),start:t=>t.trimStart(),end:t=>t.trimEnd(),normalizeWhitespace:t=>t.trim().replace(/\s+/g," ")};function s(t){return null!=t&&"string"==typeof t}function u(t,n=!0){return!!s(t)&&(n?t.trim().length>0:t.length>0)}function c(t){try{return new URL(t),!0}catch{return!1}}function o(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function f(t){return/^[a-zA-Z]+$/.test(t)}function p(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}function l(t){return/^[A-Z]/.test(t)}function
|
|
1
|
+
function t(t){return t.replace(/^\w/,t=>t.toUpperCase())}function n(t,n,e=" "){return t.padStart(n,e)}function e(t,n,e=" "){return t.padEnd(n,e)}function r(t,n,e="..."){return t.length>n?t.slice(0,n-e.length)+e:t}function i(t,n){return t.repeat(n)}const a={function:t=>t.trim(),start:t=>t.trimStart(),end:t=>t.trimEnd(),normalizeWhitespace:t=>t.trim().replace(/\s+/g," ")};function s(t){return null!=t&&"string"==typeof t}function u(t,n=!0){return!!s(t)&&("string"==typeof t&&(n?t.trim().length>0:t.length>0))}function c(t){try{return new URL(t),!0}catch{return!1}}function o(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}function f(t){return/^[a-zA-Z]+$/.test(t)}function p(t){return!isNaN(Number(t))&&!isNaN(parseFloat(t))}function l(t){return/^[A-Z]/.test(t)}function g(t){return/[\p{P}]$/u.test(t)}function m(t){return/\s/.test(t)}function h(t){return/^[a-z][a-zA-Z0-9]*$/.test(t)}function z(t){return/^[A-Z][a-zA-Z0-9]*$/.test(t)}function d(t){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(t)}function $(t){return/^[a-z0-9]+(_[a-z0-9]+)*$/.test(t)}function C(t){return/^[A-Z]+$/.test(t)}function A(t){return/^[a-z]+$/.test(t)}var N={capitalize:t,padLeft:n,padRight:e,truncate:r,repeatString:i,trim:a,isString:s,isNonEmptyString:u,isURL:c,isEmail:o,isAlphabetic:f,isNumericString:p,startsWithUppercase:l,endsWithPunctuation:g,containsWhitespace:m,isCamelCase:h,isPascalCase:z,isKebabCase:d,isSnakeCase:$,isUpperCase:C,isLowerCase:A};export{t as capitalize,m as containsWhitespace,N as default,g as endsWithPunctuation,f as isAlphabetic,h as isCamelCase,o as isEmail,d as isKebabCase,A as isLowerCase,u as isNonEmptyString,p as isNumericString,z as isPascalCase,$ as isSnakeCase,s as isString,c as isURL,C as isUpperCase,n as padLeft,e as padRight,i as repeatString,l as startsWithUppercase,a as trim,r as truncate};
|