@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,102 @@
|
|
|
1
|
+
import type { Brand } from "./utility_types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a duration of time in milliseconds. You should
|
|
4
|
+
* always use this type when working with durations of time in milliseconds.
|
|
5
|
+
* It helps ensure that you're working with durations of time in milliseconds,
|
|
6
|
+
* and not accidentally using a different unit of time.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* setTimeout(() => {}, 1_000 as Milliseconds);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type Milliseconds = Brand<number, "milliseconds">;
|
|
14
|
+
/** Represents a duration of time in seconds. */
|
|
15
|
+
export type Seconds = Brand<number, "seconds">;
|
|
16
|
+
/** Represents a duration of time in minutes. */
|
|
17
|
+
export type Minutes = Brand<number, "minutes">;
|
|
18
|
+
/** Represents a duration of time in hours. */
|
|
19
|
+
export type Hours = Brand<number, "hours">;
|
|
20
|
+
/** Represents a duration of time in days. */
|
|
21
|
+
export type Days = Brand<number, "days">;
|
|
22
|
+
/** Represents a duration of time in weeks. */
|
|
23
|
+
export type Weeks = Brand<number, "weeks">;
|
|
24
|
+
/** Represents a duration of time in years. */
|
|
25
|
+
export type Years = Brand<number, "years">;
|
|
26
|
+
/**
|
|
27
|
+
* A representation of a duration of time within a codebase.
|
|
28
|
+
* This class provides a way to work with durations of time in a type-safe manner.
|
|
29
|
+
*
|
|
30
|
+
* @see milliseconds to quickly create a millisecond duration.
|
|
31
|
+
*
|
|
32
|
+
* @example Converting seconds to milliseconds
|
|
33
|
+
* ```ts
|
|
34
|
+
* setTimeout(() => {}, Duration.seconds(1 as Seconds).toMilliseconds());
|
|
35
|
+
* ```
|
|
36
|
+
* @example Converting minutes to milliseconds
|
|
37
|
+
* ```ts
|
|
38
|
+
* setTimeout(() => {}, Duration.minutes(1 as Minutes).toMilliseconds());
|
|
39
|
+
* ```
|
|
40
|
+
* @example Converting to milliseconds
|
|
41
|
+
*/
|
|
42
|
+
export declare class Duration {
|
|
43
|
+
private readonly milliseconds;
|
|
44
|
+
private constructor();
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Duration from milliseconds.
|
|
47
|
+
*/
|
|
48
|
+
static milliseconds(milliseconds: Milliseconds): Duration;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Duration from seconds.
|
|
51
|
+
*/
|
|
52
|
+
static seconds(seconds: Seconds): Duration;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Duration from minutes.
|
|
55
|
+
*/
|
|
56
|
+
static minutes(minutes: Minutes): Duration;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a Duration from hours.
|
|
59
|
+
*/
|
|
60
|
+
static hours(hours: Hours): Duration;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a Duration from days.
|
|
63
|
+
*/
|
|
64
|
+
static days(days: Days): Duration;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a Duration from weeks.
|
|
67
|
+
*/
|
|
68
|
+
static weeks(weeks: Weeks): Duration;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a Duration from years.
|
|
71
|
+
*/
|
|
72
|
+
static years(years: Years): Duration;
|
|
73
|
+
/**
|
|
74
|
+
* Converts the duration to milliseconds.
|
|
75
|
+
*/
|
|
76
|
+
toMilliseconds(): Milliseconds;
|
|
77
|
+
/**
|
|
78
|
+
* Converts the duration to seconds.
|
|
79
|
+
*/
|
|
80
|
+
toSeconds(): Seconds;
|
|
81
|
+
/**
|
|
82
|
+
* Converts the duration to minutes.
|
|
83
|
+
*/
|
|
84
|
+
toMinutes(): Minutes;
|
|
85
|
+
/**
|
|
86
|
+
* Converts the duration to hours.
|
|
87
|
+
*/
|
|
88
|
+
toHours(): Hours;
|
|
89
|
+
/**
|
|
90
|
+
* Converts the duration to days.
|
|
91
|
+
*/
|
|
92
|
+
toDays(): Days;
|
|
93
|
+
/**
|
|
94
|
+
* Converts the duration to weeks.
|
|
95
|
+
*/
|
|
96
|
+
toWeeks(): Weeks;
|
|
97
|
+
/**
|
|
98
|
+
* Converts the duration to years.
|
|
99
|
+
*/
|
|
100
|
+
toYears(): Years;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/src/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACzD,gDAAgD;AAChD,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/C,gDAAgD;AAChD,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/C,8CAA8C;AAC9C,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3C,6CAA6C;AAC7C,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACzC,8CAA8C;AAC9C,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3C,8CAA8C;AAC9C,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,QAAQ;IACC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAAjD,OAAO;IAEP;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,QAAQ;IAIzD;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ;IAI1C;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ;IAI1C;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ;IAIpC;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ;IAIjC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ;IAIpC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ;IAIpC;;OAEG;IACH,cAAc,IAAI,YAAY;IAI9B;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,OAAO,IAAI,KAAK;IAIhB;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,IAAI,KAAK;IAIhB;;OAEG;IACH,OAAO,IAAI,KAAK;CAGjB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Duration = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A representation of a duration of time within a codebase.
|
|
6
|
+
* This class provides a way to work with durations of time in a type-safe manner.
|
|
7
|
+
*
|
|
8
|
+
* @see milliseconds to quickly create a millisecond duration.
|
|
9
|
+
*
|
|
10
|
+
* @example Converting seconds to milliseconds
|
|
11
|
+
* ```ts
|
|
12
|
+
* setTimeout(() => {}, Duration.seconds(1 as Seconds).toMilliseconds());
|
|
13
|
+
* ```
|
|
14
|
+
* @example Converting minutes to milliseconds
|
|
15
|
+
* ```ts
|
|
16
|
+
* setTimeout(() => {}, Duration.minutes(1 as Minutes).toMilliseconds());
|
|
17
|
+
* ```
|
|
18
|
+
* @example Converting to milliseconds
|
|
19
|
+
*/
|
|
20
|
+
class Duration {
|
|
21
|
+
constructor(milliseconds) {
|
|
22
|
+
Object.defineProperty(this, "milliseconds", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: milliseconds
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a Duration from milliseconds.
|
|
31
|
+
*/
|
|
32
|
+
static milliseconds(milliseconds) {
|
|
33
|
+
return new Duration(milliseconds);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a Duration from seconds.
|
|
37
|
+
*/
|
|
38
|
+
static seconds(seconds) {
|
|
39
|
+
return new Duration(seconds * 1000);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a Duration from minutes.
|
|
43
|
+
*/
|
|
44
|
+
static minutes(minutes) {
|
|
45
|
+
return new Duration(minutes * 60 * 1000);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a Duration from hours.
|
|
49
|
+
*/
|
|
50
|
+
static hours(hours) {
|
|
51
|
+
return new Duration(hours * 60 * 60 * 1000);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Duration from days.
|
|
55
|
+
*/
|
|
56
|
+
static days(days) {
|
|
57
|
+
return new Duration(days * 24 * 60 * 60 * 1000);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a Duration from weeks.
|
|
61
|
+
*/
|
|
62
|
+
static weeks(weeks) {
|
|
63
|
+
return new Duration(weeks * 7 * 24 * 60 * 60 * 1000);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creates a Duration from years.
|
|
67
|
+
*/
|
|
68
|
+
static years(years) {
|
|
69
|
+
return new Duration(years * 365 * 24 * 60 * 60 * 1000);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Converts the duration to milliseconds.
|
|
73
|
+
*/
|
|
74
|
+
toMilliseconds() {
|
|
75
|
+
return this.milliseconds;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts the duration to seconds.
|
|
79
|
+
*/
|
|
80
|
+
toSeconds() {
|
|
81
|
+
return this.milliseconds / 1000;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Converts the duration to minutes.
|
|
85
|
+
*/
|
|
86
|
+
toMinutes() {
|
|
87
|
+
return this.milliseconds / (60 * 1000);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Converts the duration to hours.
|
|
91
|
+
*/
|
|
92
|
+
toHours() {
|
|
93
|
+
return this.milliseconds / (60 * 60 * 1000);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Converts the duration to days.
|
|
97
|
+
*/
|
|
98
|
+
toDays() {
|
|
99
|
+
return this.milliseconds / (24 * 60 * 60 * 1000);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Converts the duration to weeks.
|
|
103
|
+
*/
|
|
104
|
+
toWeeks() {
|
|
105
|
+
return this.milliseconds / (7 * 24 * 60 * 60 * 1000);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Converts the duration to years.
|
|
109
|
+
*/
|
|
110
|
+
toYears() {
|
|
111
|
+
return this.milliseconds / (365 * 24 * 60 * 60 * 1000);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.Duration = Duration;
|
|
@@ -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,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEven = isEven;
|
|
4
|
+
exports.isOdd = isOdd;
|
|
5
|
+
exports.ordinalize = ordinalize;
|
|
6
|
+
/**
|
|
7
|
+
* Determines if a number is even.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `true`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* isEven(null); // false
|
|
15
|
+
* isEven(1); // false
|
|
16
|
+
* isEven(2); // true
|
|
17
|
+
* isEven(3); // false
|
|
18
|
+
* isEven(4); // true
|
|
19
|
+
* isEven(11); // false
|
|
20
|
+
* isEven(21); // false
|
|
21
|
+
* isEven(112); // true
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function isEven(num) {
|
|
25
|
+
return (num || 0) % 2 === 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Determines if a number is odd.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `false`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* isOdd(null); // false
|
|
36
|
+
* isOdd(1); // true
|
|
37
|
+
* isOdd(2); // false
|
|
38
|
+
* isOdd(3); // true
|
|
39
|
+
* isOdd(4); // false
|
|
40
|
+
* isOdd(11); // true
|
|
41
|
+
* isOdd(21); // true
|
|
42
|
+
* isOdd(112); // false
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function isOdd(num) {
|
|
46
|
+
return !isEven(num);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Converts a number to "1st", "2nd", "3rd", etc.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* This is `null | undefined` safe. If you pass `null | undefined` this will return `0th`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* ordinalize(null); // "0th"
|
|
57
|
+
* ordinalize(1); // "1st"
|
|
58
|
+
* ordinalize(2); // "2nd"
|
|
59
|
+
* ordinalize(3); // "3rd"
|
|
60
|
+
* ordinalize(4); // "4th"
|
|
61
|
+
* ordinalize(11); // "11th"
|
|
62
|
+
* ordinalize(21); // "21st"
|
|
63
|
+
* ordinalize(112); // "112th"
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function ordinalize(num) {
|
|
67
|
+
num || (num = 0);
|
|
68
|
+
const v = num % 100;
|
|
69
|
+
if (v >= 11 && v <= 13)
|
|
70
|
+
return num + "th";
|
|
71
|
+
switch (num % 10) {
|
|
72
|
+
case 1:
|
|
73
|
+
return num + "st";
|
|
74
|
+
case 2:
|
|
75
|
+
return num + "nd";
|
|
76
|
+
case 3:
|
|
77
|
+
return num + "rd";
|
|
78
|
+
default:
|
|
79
|
+
return num + "th";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -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"}
|