@bytebury/toolkit 1.0.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/LICENSE +21 -0
- package/README.md +49 -0
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/_dnt.test_shims.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
- package/esm/mod.d.ts +7 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +6 -0
- package/esm/package.json +3 -0
- package/esm/src/core.d.ts +297 -0
- package/esm/src/core.d.ts.map +1 -0
- package/esm/src/core.js +256 -0
- package/esm/src/core_test.d.ts.map +1 -0
- package/esm/src/dates.d.ts +113 -0
- package/esm/src/dates.d.ts.map +1 -0
- package/esm/src/dates.js +197 -0
- package/esm/src/dates_test.d.ts.map +1 -0
- package/esm/src/duration.d.ts +102 -0
- package/esm/src/duration.d.ts.map +1 -0
- package/esm/src/duration.js +110 -0
- package/esm/src/duration_test.d.ts.map +1 -0
- package/esm/src/numbers.d.ts +58 -0
- package/esm/src/numbers.d.ts.map +1 -0
- package/esm/src/numbers.js +76 -0
- package/esm/src/numbers_test.d.ts.map +1 -0
- package/esm/src/strings.d.ts +164 -0
- package/esm/src/strings.d.ts.map +1 -0
- package/esm/src/strings.js +196 -0
- package/esm/src/strings_test.d.ts.map +1 -0
- package/esm/src/utility_types.d.ts +117 -0
- package/esm/src/utility_types.d.ts.map +1 -0
- package/esm/src/utility_types.js +1 -0
- package/package.json +28 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/_dnt.test_shims.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/almost_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/array_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/fail.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/false.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/greater_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/is_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/less_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/not_strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/object_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/rejects.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/string_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/throws.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unimplemented.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.16/unreachable.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/build_message.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/diff_str.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/format.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/styles.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.12/types.d.ts.map +1 -0
- package/script/mod.d.ts +7 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +22 -0
- package/script/package.json +3 -0
- package/script/src/core.d.ts +297 -0
- package/script/src/core.d.ts.map +1 -0
- package/script/src/core.js +279 -0
- package/script/src/core_test.d.ts.map +1 -0
- package/script/src/dates.d.ts +113 -0
- package/script/src/dates.d.ts.map +1 -0
- package/script/src/dates.js +224 -0
- package/script/src/dates_test.d.ts.map +1 -0
- package/script/src/duration.d.ts +102 -0
- package/script/src/duration.d.ts.map +1 -0
- package/script/src/duration.js +114 -0
- package/script/src/duration_test.d.ts.map +1 -0
- package/script/src/numbers.d.ts +58 -0
- package/script/src/numbers.d.ts.map +1 -0
- package/script/src/numbers.js +81 -0
- package/script/src/numbers_test.d.ts.map +1 -0
- package/script/src/strings.d.ts +164 -0
- package/script/src/strings.d.ts.map +1 -0
- package/script/src/strings.js +209 -0
- package/script/src/strings_test.d.ts.map +1 -0
- package/script/src/utility_types.d.ts +117 -0
- package/script/src/utility_types.d.ts.map +1 -0
- package/script/src/utility_types.js +2 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A representation of a duration of time within a codebase.
|
|
3
|
+
* This class provides a way to work with durations of time in a type-safe manner.
|
|
4
|
+
*
|
|
5
|
+
* @see milliseconds to quickly create a millisecond duration.
|
|
6
|
+
*
|
|
7
|
+
* @example Converting seconds to milliseconds
|
|
8
|
+
* ```ts
|
|
9
|
+
* setTimeout(() => {}, Duration.seconds(1 as Seconds).toMilliseconds());
|
|
10
|
+
* ```
|
|
11
|
+
* @example Converting minutes to milliseconds
|
|
12
|
+
* ```ts
|
|
13
|
+
* setTimeout(() => {}, Duration.minutes(1 as Minutes).toMilliseconds());
|
|
14
|
+
* ```
|
|
15
|
+
* @example Converting to milliseconds
|
|
16
|
+
*/
|
|
17
|
+
export class Duration {
|
|
18
|
+
constructor(milliseconds) {
|
|
19
|
+
Object.defineProperty(this, "milliseconds", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: milliseconds
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a Duration from milliseconds.
|
|
28
|
+
*/
|
|
29
|
+
static milliseconds(milliseconds) {
|
|
30
|
+
return new Duration(milliseconds);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a Duration from seconds.
|
|
34
|
+
*/
|
|
35
|
+
static seconds(seconds) {
|
|
36
|
+
return new Duration(seconds * 1000);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a Duration from minutes.
|
|
40
|
+
*/
|
|
41
|
+
static minutes(minutes) {
|
|
42
|
+
return new Duration(minutes * 60 * 1000);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a Duration from hours.
|
|
46
|
+
*/
|
|
47
|
+
static hours(hours) {
|
|
48
|
+
return new Duration(hours * 60 * 60 * 1000);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Duration from days.
|
|
52
|
+
*/
|
|
53
|
+
static days(days) {
|
|
54
|
+
return new Duration(days * 24 * 60 * 60 * 1000);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a Duration from weeks.
|
|
58
|
+
*/
|
|
59
|
+
static weeks(weeks) {
|
|
60
|
+
return new Duration(weeks * 7 * 24 * 60 * 60 * 1000);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a Duration from years.
|
|
64
|
+
*/
|
|
65
|
+
static years(years) {
|
|
66
|
+
return new Duration(years * 365 * 24 * 60 * 60 * 1000);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts the duration to milliseconds.
|
|
70
|
+
*/
|
|
71
|
+
toMilliseconds() {
|
|
72
|
+
return this.milliseconds;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Converts the duration to seconds.
|
|
76
|
+
*/
|
|
77
|
+
toSeconds() {
|
|
78
|
+
return this.milliseconds / 1000;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts the duration to minutes.
|
|
82
|
+
*/
|
|
83
|
+
toMinutes() {
|
|
84
|
+
return this.milliseconds / (60 * 1000);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts the duration to hours.
|
|
88
|
+
*/
|
|
89
|
+
toHours() {
|
|
90
|
+
return this.milliseconds / (60 * 60 * 1000);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Converts the duration to days.
|
|
94
|
+
*/
|
|
95
|
+
toDays() {
|
|
96
|
+
return this.milliseconds / (24 * 60 * 60 * 1000);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Converts the duration to weeks.
|
|
100
|
+
*/
|
|
101
|
+
toWeeks() {
|
|
102
|
+
return this.milliseconds / (7 * 24 * 60 * 60 * 1000);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Converts the duration to years.
|
|
106
|
+
*/
|
|
107
|
+
toYears() {
|
|
108
|
+
return this.milliseconds / (365 * 24 * 60 * 60 * 1000);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration_test.d.ts","sourceRoot":"","sources":["../../src/src/duration_test.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a number is even.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `true`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isEven(null); // false
|
|
10
|
+
* isEven(1); // false
|
|
11
|
+
* isEven(2); // true
|
|
12
|
+
* isEven(3); // false
|
|
13
|
+
* isEven(4); // true
|
|
14
|
+
* isEven(11); // false
|
|
15
|
+
* isEven(21); // false
|
|
16
|
+
* isEven(112); // true
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function isEven(num: number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Determines if a number is odd.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `false`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* isOdd(null); // false
|
|
29
|
+
* isOdd(1); // true
|
|
30
|
+
* isOdd(2); // false
|
|
31
|
+
* isOdd(3); // true
|
|
32
|
+
* isOdd(4); // false
|
|
33
|
+
* isOdd(11); // true
|
|
34
|
+
* isOdd(21); // true
|
|
35
|
+
* isOdd(112); // false
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function isOdd(num: number): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a number to "1st", "2nd", "3rd", etc.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `0th`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* ordinalize(null); // "0th"
|
|
48
|
+
* ordinalize(1); // "1st"
|
|
49
|
+
* ordinalize(2); // "2nd"
|
|
50
|
+
* ordinalize(3); // "3rd"
|
|
51
|
+
* ordinalize(4); // "4th"
|
|
52
|
+
* ordinalize(11); // "11th"
|
|
53
|
+
* ordinalize(21); // "21st"
|
|
54
|
+
* ordinalize(112); // "112th"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function ordinalize(num: number): string;
|
|
58
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/src/numbers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB9C"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a number is even.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `true`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isEven(null); // false
|
|
10
|
+
* isEven(1); // false
|
|
11
|
+
* isEven(2); // true
|
|
12
|
+
* isEven(3); // false
|
|
13
|
+
* isEven(4); // true
|
|
14
|
+
* isEven(11); // false
|
|
15
|
+
* isEven(21); // false
|
|
16
|
+
* isEven(112); // true
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function isEven(num) {
|
|
20
|
+
return (num || 0) % 2 === 0;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Determines if a number is odd.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `false`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* isOdd(null); // false
|
|
31
|
+
* isOdd(1); // true
|
|
32
|
+
* isOdd(2); // false
|
|
33
|
+
* isOdd(3); // true
|
|
34
|
+
* isOdd(4); // false
|
|
35
|
+
* isOdd(11); // true
|
|
36
|
+
* isOdd(21); // true
|
|
37
|
+
* isOdd(112); // false
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function isOdd(num) {
|
|
41
|
+
return !isEven(num);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts a number to "1st", "2nd", "3rd", etc.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `0th`.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* ordinalize(null); // "0th"
|
|
52
|
+
* ordinalize(1); // "1st"
|
|
53
|
+
* ordinalize(2); // "2nd"
|
|
54
|
+
* ordinalize(3); // "3rd"
|
|
55
|
+
* ordinalize(4); // "4th"
|
|
56
|
+
* ordinalize(11); // "11th"
|
|
57
|
+
* ordinalize(21); // "21st"
|
|
58
|
+
* ordinalize(112); // "112th"
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function ordinalize(num) {
|
|
62
|
+
num || (num = 0);
|
|
63
|
+
const v = num % 100;
|
|
64
|
+
if (v >= 11 && v <= 13)
|
|
65
|
+
return num + "th";
|
|
66
|
+
switch (num % 10) {
|
|
67
|
+
case 1:
|
|
68
|
+
return num + "st";
|
|
69
|
+
case 2:
|
|
70
|
+
return num + "nd";
|
|
71
|
+
case 3:
|
|
72
|
+
return num + "rd";
|
|
73
|
+
default:
|
|
74
|
+
return num + "th";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers_test.d.ts","sourceRoot":"","sources":["../../src/src/numbers_test.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the given text is only comprised of whitespace.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `true`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isWhitespace(null); // true
|
|
10
|
+
* isWhitespace(" "); // true
|
|
11
|
+
* isWhitespace("\n\t"); // true
|
|
12
|
+
* isWhitespace("Hello"); // false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function isWhitespace(text: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the given text contains any non-whitespace characters.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `false`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* isNotWhitespace(null); // false
|
|
25
|
+
* isNotWhitespace(" "); // false
|
|
26
|
+
* isNotWhitespace("Hello"); // true
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function isNotWhitespace(text: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Trims the whitespace from the beginning and the end. This is an
|
|
32
|
+
* alias for `.trim()`. Useful for when you're mapping over lists.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* trim(null); // ""
|
|
40
|
+
* trim(" HELLO WORLD \n"); // "HELLO WORLD"
|
|
41
|
+
* [' hello ', ' world '].map(trim); // ['hello', 'world'];
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function trim(text: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Converts the string to Title Case. This will capitalize
|
|
47
|
+
* the letter of each word that is separated by a space. Underscores
|
|
48
|
+
* are considered spaces. Hyphens are respected.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* title(null); // ""
|
|
56
|
+
* title("hello world"); // Hello World
|
|
57
|
+
* title("hello-world"); // Hello-world
|
|
58
|
+
* title("hello_world"); // Hello World
|
|
59
|
+
* title("HELLO wORLD"); // Hello World
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function title(text: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Converts the string to lowercase.
|
|
65
|
+
* An alias for `toLowerCase()`.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* lower(null); // ""
|
|
73
|
+
* lower("Hello WORLD"); // "hello world"
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function lower(text: string): Lowercase<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Converts the string to uppercase.
|
|
79
|
+
* An alias for `toUpperCase()`.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* upper(null); // ""
|
|
87
|
+
* upper("Hello world"); // "HELLO WORLD"
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function upper(text: string): Uppercase<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Converts the string to `kebab-case` by removing punctuation,
|
|
93
|
+
* trimming extra spaces, converting to lowercase, and joining words with hyphens.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* kebab(null); // ""
|
|
101
|
+
* kebab("Hello World!"); // "hello-world"
|
|
102
|
+
* kebab(" Clean THIS_up!! "); // "clean-this-up"
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function kebab(text: string): Lowercase<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Converts a string to `snake_case` by replacing spaces and punctuation with underscores.
|
|
108
|
+
* Uses `kebab()` internally, replacing hyphens with underscores.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* snake(null); // ""
|
|
116
|
+
* snake("Hello World"); // "hello_world"
|
|
117
|
+
* snake("User-Profile Page"); // "user_profile_page"
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function snake(text: string): Lowercase<string>;
|
|
121
|
+
/**
|
|
122
|
+
* Returns a copy of the given string with all non-alpha characters removed,
|
|
123
|
+
* except for spaces. Letters are preserved regardless of case.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* keepAlphabetical(null); // ""
|
|
131
|
+
* keepAlphabetical("Hello, World!"); // "Hello World"
|
|
132
|
+
* keepAlphabetical("123@#Test"); // "Test"
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function keepAlphabetical(text: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* Returns a copy of the given string with all non-alphanumeric characters removed,
|
|
138
|
+
* except for spaces. Letters and digits are preserved regardless of case.
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* keepAlphanumeric(null); // ""
|
|
146
|
+
* keepAlphanumeric("Hello, World!"); // "Hello World"
|
|
147
|
+
* keepAlphanumeric("123@#Test"); // "123Test"
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function keepAlphanumeric(text: string): string;
|
|
151
|
+
/**
|
|
152
|
+
* Removes any non-numeric characters. This includes spaces.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* keepNumeric(null); // ""
|
|
160
|
+
* keepNumeric('(555) 555-5555'); // 5555555555
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare function keepNumeric(text: string): string;
|
|
164
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/src/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAErD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAIrD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the given text is only comprised of whitespace.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `true`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isWhitespace(null); // true
|
|
10
|
+
* isWhitespace(" "); // true
|
|
11
|
+
* isWhitespace("\n\t"); // true
|
|
12
|
+
* isWhitespace("Hello"); // false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function isWhitespace(text) {
|
|
16
|
+
return trim(text).length === 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Determines if the given text contains any non-whitespace characters.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `false`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* isNotWhitespace(null); // false
|
|
27
|
+
* isNotWhitespace(" "); // false
|
|
28
|
+
* isNotWhitespace("Hello"); // true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function isNotWhitespace(text) {
|
|
32
|
+
return !isWhitespace(text);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Trims the whitespace from the beginning and the end. This is an
|
|
36
|
+
* alias for `.trim()`. Useful for when you're mapping over lists.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* trim(null); // ""
|
|
44
|
+
* trim(" HELLO WORLD \n"); // "HELLO WORLD"
|
|
45
|
+
* [' hello ', ' world '].map(trim); // ['hello', 'world'];
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function trim(text) {
|
|
49
|
+
return (text || "").trim();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts the string to Title Case. This will capitalize
|
|
53
|
+
* the letter of each word that is separated by a space. Underscores
|
|
54
|
+
* are considered spaces. Hyphens are respected.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* title(null); // ""
|
|
62
|
+
* title("hello world"); // Hello World
|
|
63
|
+
* title("hello-world"); // Hello-world
|
|
64
|
+
* title("hello_world"); // Hello World
|
|
65
|
+
* title("HELLO wORLD"); // Hello World
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function title(text) {
|
|
69
|
+
return lower(text)
|
|
70
|
+
.replace(/_/g, " ")
|
|
71
|
+
.split(" ")
|
|
72
|
+
.map((word) => upper(word.charAt(0)) + word.slice(1))
|
|
73
|
+
.join(" ");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Converts the string to lowercase.
|
|
77
|
+
* An alias for `toLowerCase()`.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* lower(null); // ""
|
|
85
|
+
* lower("Hello WORLD"); // "hello world"
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export function lower(text) {
|
|
89
|
+
return (text || "").toLowerCase();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Converts the string to uppercase.
|
|
93
|
+
* An alias for `toUpperCase()`.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* upper(null); // ""
|
|
101
|
+
* upper("Hello world"); // "HELLO WORLD"
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function upper(text) {
|
|
105
|
+
return (text || "").toUpperCase();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Converts the string to `kebab-case` by removing punctuation,
|
|
109
|
+
* trimming extra spaces, converting to lowercase, and joining words with hyphens.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* kebab(null); // ""
|
|
117
|
+
* kebab("Hello World!"); // "hello-world"
|
|
118
|
+
* kebab(" Clean THIS_up!! "); // "clean-this-up"
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export function kebab(text) {
|
|
122
|
+
return trim(removePunctuation(lower(text))).replace(/\s+/g, "-");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Converts a string to `snake_case` by replacing spaces and punctuation with underscores.
|
|
126
|
+
* Uses `kebab()` internally, replacing hyphens with underscores.
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* snake(null); // ""
|
|
134
|
+
* snake("Hello World"); // "hello_world"
|
|
135
|
+
* snake("User-Profile Page"); // "user_profile_page"
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export function snake(text) {
|
|
139
|
+
return kebab(text).replace(/-/g, "_");
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns a copy of the given string with all non-alpha characters removed,
|
|
143
|
+
* except for spaces. Letters are preserved regardless of case.
|
|
144
|
+
*
|
|
145
|
+
* @remarks
|
|
146
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* keepAlphabetical(null); // ""
|
|
151
|
+
* keepAlphabetical("Hello, World!"); // "Hello World"
|
|
152
|
+
* keepAlphabetical("123@#Test"); // "Test"
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function keepAlphabetical(text) {
|
|
156
|
+
return (text || "").replace(/[^a-z ]/gi, "");
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns a copy of the given string with all non-alphanumeric characters removed,
|
|
160
|
+
* except for spaces. Letters and digits are preserved regardless of case.
|
|
161
|
+
*
|
|
162
|
+
* @remarks
|
|
163
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* keepAlphanumeric(null); // ""
|
|
168
|
+
* keepAlphanumeric("Hello, World!"); // "Hello World"
|
|
169
|
+
* keepAlphanumeric("123@#Test"); // "123Test"
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export function keepAlphanumeric(text) {
|
|
173
|
+
return (text || "").replace(/[^a-z0-9 ]/gi, "");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Removes any non-numeric characters. This includes spaces.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* This is `null | undefined` safe. If you pass `null | undefined` then this will return `""`.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* keepNumeric(null); // ""
|
|
184
|
+
* keepNumeric('(555) 555-5555'); // 5555555555
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export function keepNumeric(text) {
|
|
188
|
+
return (text || "").replace(/[^\d]/g, "");
|
|
189
|
+
}
|
|
190
|
+
function removePunctuation(text) {
|
|
191
|
+
return text
|
|
192
|
+
.normalize("NFKD")
|
|
193
|
+
.replace(/[-_]/g, " ")
|
|
194
|
+
.replace(/\s+/g, " ")
|
|
195
|
+
.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
196
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings_test.d.ts","sourceRoot":"","sources":["../../src/src/strings_test.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|