toosoon-utils 4.2.3 → 4.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 +501 -603
- package/lib/colors.d.ts +147 -66
- package/lib/colors.js +149 -63
- package/lib/constants.js +1 -1
- package/lib/dom.d.ts +1 -1
- package/lib/dom.js +1 -1
- package/lib/extras/colors/Color.d.ts +406 -0
- package/lib/extras/colors/Color.js +546 -0
- package/lib/extras/colors/ColorPalette.d.ts +105 -0
- package/lib/extras/colors/ColorPalette.js +124 -0
- package/lib/extras/colors/ColorScale.d.ts +257 -0
- package/lib/extras/colors/ColorScale.js +347 -0
- package/lib/extras/colors/_ColorScale.d.ts +62 -0
- package/lib/extras/colors/_ColorScale.js +156 -0
- package/lib/extras/colors/index.d.ts +3 -0
- package/lib/extras/colors/index.js +3 -0
- package/lib/extras/frame-rate/FrameRate.d.ts +12 -9
- package/lib/extras/frame-rate/FrameRate.js +10 -7
- package/lib/extras/geometry/Vector.d.ts +1 -1
- package/lib/extras/geometry/Vector2.d.ts +17 -11
- package/lib/extras/geometry/Vector2.js +29 -23
- package/lib/extras/geometry/Vector3.d.ts +5 -5
- package/lib/extras/geometry/Vector3.js +10 -10
- package/lib/extras/paths/Path.d.ts +3 -3
- package/lib/extras/paths/Path.js +10 -10
- package/lib/extras/paths/PathContext.d.ts +7 -10
- package/lib/extras/paths/PathContext.js +79 -102
- package/lib/extras/paths/PathSVG.d.ts +31 -25
- package/lib/extras/paths/PathSVG.js +36 -39
- package/lib/extras/paths/index.d.ts +1 -1
- package/lib/geometry.d.ts +7 -7
- package/lib/geometry.js +13 -13
- package/lib/maths.d.ts +19 -13
- package/lib/maths.js +23 -17
- package/lib/prng.d.ts +4 -4
- package/lib/prng.js +4 -4
- package/lib/random.d.ts +4 -4
- package/lib/random.js +4 -4
- package/lib/strings.d.ts +14 -8
- package/lib/strings.js +14 -8
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +15 -8
- package/package.json +14 -14
package/lib/geometry.d.ts
CHANGED
|
@@ -25,18 +25,18 @@ export declare function angle(x1: number, y1: number, x2: number, y2: number): n
|
|
|
25
25
|
/**
|
|
26
26
|
* Find the closest angle between to angles
|
|
27
27
|
*
|
|
28
|
-
* @param {number}
|
|
29
|
-
* @param {number}
|
|
28
|
+
* @param {number} startAngle Start angle (in radians)
|
|
29
|
+
* @param {number} endAngle End angle (in radians)
|
|
30
30
|
* @returns {number} Closest angle
|
|
31
31
|
*/
|
|
32
|
-
export declare function closestAngle(
|
|
32
|
+
export declare function closestAngle(startAngle: number, endAngle: number): number;
|
|
33
33
|
/**
|
|
34
34
|
* Calculate the distance between two points
|
|
35
35
|
*
|
|
36
|
-
* @param {number} x1 X-axis coordinate of the
|
|
37
|
-
* @param {number} y1 Y-axis coordinate of the
|
|
38
|
-
* @param {number} x2 X-axis coordinate of the
|
|
39
|
-
* @param {number} y2 Y-axis coordinate of the
|
|
36
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
37
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
38
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
39
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
40
40
|
* @returns {number} Computed distance
|
|
41
41
|
*/
|
|
42
42
|
export declare function distance(x1: number, y1: number, x2: number, y2: number): number;
|
package/lib/geometry.js
CHANGED
|
@@ -32,21 +32,21 @@ export function angle(x1, y1, x2, y2) {
|
|
|
32
32
|
/**
|
|
33
33
|
* Find the closest angle between to angles
|
|
34
34
|
*
|
|
35
|
-
* @param {number}
|
|
36
|
-
* @param {number}
|
|
35
|
+
* @param {number} startAngle Start angle (in radians)
|
|
36
|
+
* @param {number} endAngle End angle (in radians)
|
|
37
37
|
* @returns {number} Closest angle
|
|
38
38
|
*/
|
|
39
|
-
export function closestAngle(
|
|
40
|
-
const delta =
|
|
41
|
-
return delta > PI ?
|
|
39
|
+
export function closestAngle(startAngle, endAngle) {
|
|
40
|
+
const delta = endAngle - startAngle;
|
|
41
|
+
return delta > PI ? endAngle - 2 * PI : endAngle < -PI ? delta + 2 * PI : endAngle;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Calculate the distance between two points
|
|
45
45
|
*
|
|
46
|
-
* @param {number} x1 X-axis coordinate of the
|
|
47
|
-
* @param {number} y1 Y-axis coordinate of the
|
|
48
|
-
* @param {number} x2 X-axis coordinate of the
|
|
49
|
-
* @param {number} y2 Y-axis coordinate of the
|
|
46
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
47
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
48
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
49
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
50
50
|
* @returns {number} Computed distance
|
|
51
51
|
*/
|
|
52
52
|
export function distance(x1, y1, x2, y2) {
|
|
@@ -67,10 +67,10 @@ export function diagonal(width, height) {
|
|
|
67
67
|
/**
|
|
68
68
|
* Make a target fit a container
|
|
69
69
|
*
|
|
70
|
-
* @param {
|
|
71
|
-
* @param {
|
|
72
|
-
* @param {
|
|
73
|
-
* @returns {
|
|
70
|
+
* @param {FitInput} target Dimensions of the target
|
|
71
|
+
* @param {FitInput} container Dimensions of the container
|
|
72
|
+
* @param {string} mode Can be 'contain' | 'cover'
|
|
73
|
+
* @returns {FitOutput}
|
|
74
74
|
*/
|
|
75
75
|
function fit(target, container, mode) {
|
|
76
76
|
const ratioWidth = container.width / target.width;
|
package/lib/maths.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function isPowerOf2(value: number): boolean;
|
|
|
24
24
|
*
|
|
25
25
|
* @param {number} value Incoming value
|
|
26
26
|
* @param {string} [mode='ceil'] Can be 'floor' | 'ceil' | 'round'
|
|
27
|
-
* @returns {number}
|
|
27
|
+
* @returns {number} Computed power of 2
|
|
28
28
|
*/
|
|
29
29
|
export declare function toPowerOf2(value: number, mode?: 'floor' | 'ceil' | 'round'): number;
|
|
30
30
|
/**
|
|
@@ -83,24 +83,29 @@ export declare function map(value: number, currentMin: number, currentMax: numbe
|
|
|
83
83
|
/**
|
|
84
84
|
* Interpolate a value between two values using Triangular interpolation
|
|
85
85
|
*
|
|
86
|
-
* @param {number} t
|
|
87
|
-
* @param {number} min
|
|
88
|
-
* @param {number} max
|
|
89
|
-
* @param {number}
|
|
86
|
+
* @param {number} t Normalized time value to interpolate
|
|
87
|
+
* @param {number} min Minimum value
|
|
88
|
+
* @param {number} max Maximum value
|
|
89
|
+
* @param {number} peak Peak value controling the interpolation triangle shape
|
|
90
|
+
* - peak <= min : linear (same as lerp)
|
|
91
|
+
* - peak <= max : linear (same as lerp)
|
|
92
|
+
* - peak > min && peak > max : triangular
|
|
90
93
|
* @returns {number} Interpolated value
|
|
91
94
|
*/
|
|
92
|
-
export declare function triLerp(t: number, min: number, max: number,
|
|
95
|
+
export declare function triLerp(t: number, min: number, max: number, peak: number): number;
|
|
93
96
|
/**
|
|
94
97
|
* Interpolate a value using Exponential interpolation
|
|
95
98
|
*
|
|
96
|
-
* @param {number} t
|
|
97
|
-
* @param {number}
|
|
98
|
-
* @param {number}
|
|
99
|
-
* @param {number}
|
|
100
|
-
*
|
|
99
|
+
* @param {number} t Normalized time value to interpolate
|
|
100
|
+
* @param {number} min Minimum value
|
|
101
|
+
* @param {number} max Maximum value
|
|
102
|
+
* @param {number} power Exponent controling the interpolation curve shape
|
|
103
|
+
* - power > 1 : ease-in
|
|
104
|
+
* - power < 1 : ease-out
|
|
105
|
+
* - power = 1 : linear (same as lerp)
|
|
101
106
|
* @returns {number} Interpolated value
|
|
102
107
|
*/
|
|
103
|
-
export declare function expLerp(t: number,
|
|
108
|
+
export declare function expLerp(t: number, min: number, max: number, power: number): number;
|
|
104
109
|
/**
|
|
105
110
|
* Interpolate a value using Quadratic Bézier interpolation
|
|
106
111
|
*
|
|
@@ -160,7 +165,8 @@ export declare function pingPong(value: number, length: number): number;
|
|
|
160
165
|
export declare function smoothstep(value: number, min?: number, max?: number): number;
|
|
161
166
|
/**
|
|
162
167
|
* Re-map the [0, 1] interval into [0, 1] parabola, such that corners are remaped to 0 and the center to 1
|
|
163
|
-
*
|
|
168
|
+
* - parabola(0) = parabola(1) = 0
|
|
169
|
+
* - parabola(0.5) = 1
|
|
164
170
|
*
|
|
165
171
|
* @param {number} x Normalized coordinate on X axis
|
|
166
172
|
* @param {number} [power=1] Parabola power
|
package/lib/maths.js
CHANGED
|
@@ -30,7 +30,7 @@ export function isPowerOf2(value) {
|
|
|
30
30
|
*
|
|
31
31
|
* @param {number} value Incoming value
|
|
32
32
|
* @param {string} [mode='ceil'] Can be 'floor' | 'ceil' | 'round'
|
|
33
|
-
* @returns {number}
|
|
33
|
+
* @returns {number} Computed power of 2
|
|
34
34
|
*/
|
|
35
35
|
export function toPowerOf2(value, mode = 'ceil') {
|
|
36
36
|
return Math.pow(2, Math[mode](Math.log(value) / Math.log(2)));
|
|
@@ -109,29 +109,34 @@ export function map(value, currentMin, currentMax, targetMin, targetMax) {
|
|
|
109
109
|
/**
|
|
110
110
|
* Interpolate a value between two values using Triangular interpolation
|
|
111
111
|
*
|
|
112
|
-
* @param {number} t
|
|
113
|
-
* @param {number} min
|
|
114
|
-
* @param {number} max
|
|
115
|
-
* @param {number}
|
|
112
|
+
* @param {number} t Normalized time value to interpolate
|
|
113
|
+
* @param {number} min Minimum value
|
|
114
|
+
* @param {number} max Maximum value
|
|
115
|
+
* @param {number} peak Peak value controling the interpolation triangle shape
|
|
116
|
+
* - peak <= min : linear (same as lerp)
|
|
117
|
+
* - peak <= max : linear (same as lerp)
|
|
118
|
+
* - peak > min && peak > max : triangular
|
|
116
119
|
* @returns {number} Interpolated value
|
|
117
120
|
*/
|
|
118
|
-
export function triLerp(t, min, max,
|
|
119
|
-
const x = Math.pow(1 + Math.abs(
|
|
120
|
-
return t <= x ? min - (min -
|
|
121
|
+
export function triLerp(t, min, max, peak) {
|
|
122
|
+
const x = Math.pow(1 + Math.abs(peak - max) / Math.abs(peak - min), -1);
|
|
123
|
+
return t <= x ? min - (min - peak) * (t / x) : peak - (peak - max) * ((t - x) / (1 - x));
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Interpolate a value using Exponential interpolation
|
|
124
127
|
*
|
|
125
|
-
* @param {number} t
|
|
126
|
-
* @param {number}
|
|
127
|
-
* @param {number}
|
|
128
|
-
* @param {number}
|
|
129
|
-
*
|
|
128
|
+
* @param {number} t Normalized time value to interpolate
|
|
129
|
+
* @param {number} min Minimum value
|
|
130
|
+
* @param {number} max Maximum value
|
|
131
|
+
* @param {number} power Exponent controling the interpolation curve shape
|
|
132
|
+
* - power > 1 : ease-in
|
|
133
|
+
* - power < 1 : ease-out
|
|
134
|
+
* - power = 1 : linear (same as lerp)
|
|
130
135
|
* @returns {number} Interpolated value
|
|
131
136
|
*/
|
|
132
|
-
export function expLerp(t,
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
export function expLerp(t, min, max, power) {
|
|
138
|
+
const factor = Math.pow(t, power);
|
|
139
|
+
return min + (max - min) * factor;
|
|
135
140
|
}
|
|
136
141
|
/**
|
|
137
142
|
* Interpolate a value using Quadratic Bézier interpolation
|
|
@@ -221,7 +226,8 @@ export function smoothstep(value, min = 0, max = 1) {
|
|
|
221
226
|
}
|
|
222
227
|
/**
|
|
223
228
|
* Re-map the [0, 1] interval into [0, 1] parabola, such that corners are remaped to 0 and the center to 1
|
|
224
|
-
*
|
|
229
|
+
* - parabola(0) = parabola(1) = 0
|
|
230
|
+
* - parabola(0.5) = 1
|
|
225
231
|
*
|
|
226
232
|
* @param {number} x Normalized coordinate on X axis
|
|
227
233
|
* @param {number} [power=1] Parabola power
|
package/lib/prng.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare function random(prng: PRNGParameters): number;
|
|
|
60
60
|
*
|
|
61
61
|
* @param {PRNGParameters} prng PRNG parameters
|
|
62
62
|
* @param {number} [probability=0.5] Probability to get true
|
|
63
|
-
* @returns {boolean} Either
|
|
63
|
+
* @returns {boolean} Either true or false
|
|
64
64
|
*/
|
|
65
65
|
export declare function randomBoolean(prng: PRNGParameters, probability?: number): boolean;
|
|
66
66
|
/**
|
|
@@ -101,8 +101,8 @@ export declare function randomHexColor(prng: PRNGParameters): string;
|
|
|
101
101
|
* Pick a pseudo-random item from a given array
|
|
102
102
|
*
|
|
103
103
|
* @param {PRNGParameters} prng PRNG parameters
|
|
104
|
-
* @param {
|
|
105
|
-
* @returns {
|
|
104
|
+
* @param {unknown[]} array Array to pick the item from
|
|
105
|
+
* @returns {unknown|undefined} Random item picked
|
|
106
106
|
*/
|
|
107
107
|
export declare function randomItem<T = unknown>(prng: PRNGParameters, array: T[]): T | undefined;
|
|
108
108
|
/**
|
|
@@ -110,7 +110,7 @@ export declare function randomItem<T = unknown>(prng: PRNGParameters, array: T[]
|
|
|
110
110
|
*
|
|
111
111
|
* @param {PRNGParameters} prng PRNG parameters
|
|
112
112
|
* @param {object} object Object to pick the property from
|
|
113
|
-
* @returns {
|
|
113
|
+
* @returns {unknown|undefined} Random item picked
|
|
114
114
|
*/
|
|
115
115
|
export declare function randomObjectProperty<T = unknown>(prng: PRNGParameters, object: Record<string, T>): T | undefined;
|
|
116
116
|
/**
|
package/lib/prng.js
CHANGED
|
@@ -129,7 +129,7 @@ export function random(prng) {
|
|
|
129
129
|
*
|
|
130
130
|
* @param {PRNGParameters} prng PRNG parameters
|
|
131
131
|
* @param {number} [probability=0.5] Probability to get true
|
|
132
|
-
* @returns {boolean} Either
|
|
132
|
+
* @returns {boolean} Either true or false
|
|
133
133
|
*/
|
|
134
134
|
export function randomBoolean(prng, probability = 0.5) {
|
|
135
135
|
return random(prng) < probability;
|
|
@@ -180,8 +180,8 @@ export function randomHexColor(prng) {
|
|
|
180
180
|
* Pick a pseudo-random item from a given array
|
|
181
181
|
*
|
|
182
182
|
* @param {PRNGParameters} prng PRNG parameters
|
|
183
|
-
* @param {
|
|
184
|
-
* @returns {
|
|
183
|
+
* @param {unknown[]} array Array to pick the item from
|
|
184
|
+
* @returns {unknown|undefined} Random item picked
|
|
185
185
|
*/
|
|
186
186
|
export function randomItem(prng, array) {
|
|
187
187
|
if (array.length === 0)
|
|
@@ -193,7 +193,7 @@ export function randomItem(prng, array) {
|
|
|
193
193
|
*
|
|
194
194
|
* @param {PRNGParameters} prng PRNG parameters
|
|
195
195
|
* @param {object} object Object to pick the property from
|
|
196
|
-
* @returns {
|
|
196
|
+
* @returns {unknown|undefined} Random item picked
|
|
197
197
|
*/
|
|
198
198
|
export function randomObjectProperty(prng, object) {
|
|
199
199
|
const keys = Object.keys(object);
|
package/lib/random.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Point2, Point3 } from './types';
|
|
|
3
3
|
* Generate a random boolean (true or false)
|
|
4
4
|
*
|
|
5
5
|
* @param {number} [probability=0.5] Probability to get true
|
|
6
|
-
* @returns {boolean} Either
|
|
6
|
+
* @returns {boolean} Either true or false
|
|
7
7
|
*/
|
|
8
8
|
export declare function randomBoolean(probability?: number): boolean;
|
|
9
9
|
/**
|
|
@@ -39,15 +39,15 @@ export declare function randomHexColor(): string;
|
|
|
39
39
|
/**
|
|
40
40
|
* Pick a random item from a given array
|
|
41
41
|
*
|
|
42
|
-
* @param {
|
|
43
|
-
* @returns {
|
|
42
|
+
* @param {unknown[]} array Array to pick the item from
|
|
43
|
+
* @returns {unknown|undefined} Random item picked
|
|
44
44
|
*/
|
|
45
45
|
export declare function randomItem<T = unknown>(array: T[]): T | undefined;
|
|
46
46
|
/**
|
|
47
47
|
* Pick a random property value from a given object
|
|
48
48
|
*
|
|
49
49
|
* @param {object} object Object to pick the property from
|
|
50
|
-
* @returns {
|
|
50
|
+
* @returns {unknown|undefined} Random item picked
|
|
51
51
|
*/
|
|
52
52
|
export declare function randomObjectProperty<T = unknown>(object: Record<string, T>): T | undefined;
|
|
53
53
|
/**
|
package/lib/random.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Vector2, Vector3 } from './extras/geometry';
|
|
|
3
3
|
* Generate a random boolean (true or false)
|
|
4
4
|
*
|
|
5
5
|
* @param {number} [probability=0.5] Probability to get true
|
|
6
|
-
* @returns {boolean} Either
|
|
6
|
+
* @returns {boolean} Either true or false
|
|
7
7
|
*/
|
|
8
8
|
export function randomBoolean(probability = 0.5) {
|
|
9
9
|
return Math.random() < probability;
|
|
@@ -49,8 +49,8 @@ export function randomHexColor() {
|
|
|
49
49
|
/**
|
|
50
50
|
* Pick a random item from a given array
|
|
51
51
|
*
|
|
52
|
-
* @param {
|
|
53
|
-
* @returns {
|
|
52
|
+
* @param {unknown[]} array Array to pick the item from
|
|
53
|
+
* @returns {unknown|undefined} Random item picked
|
|
54
54
|
*/
|
|
55
55
|
export function randomItem(array) {
|
|
56
56
|
if (array.length === 0)
|
|
@@ -61,7 +61,7 @@ export function randomItem(array) {
|
|
|
61
61
|
* Pick a random property value from a given object
|
|
62
62
|
*
|
|
63
63
|
* @param {object} object Object to pick the property from
|
|
64
|
-
* @returns {
|
|
64
|
+
* @returns {unknown|undefined} Random item picked
|
|
65
65
|
*/
|
|
66
66
|
export function randomObjectProperty(object) {
|
|
67
67
|
const keys = Object.keys(object);
|
package/lib/strings.d.ts
CHANGED
|
@@ -6,42 +6,48 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function capitalize(string: string): string;
|
|
8
8
|
/**
|
|
9
|
-
* Convert a string to kebab-case
|
|
9
|
+
* Convert a string to kebab-case
|
|
10
|
+
* - 'Hello world' -> 'hello-world'
|
|
10
11
|
*
|
|
11
12
|
* @param {string} string String to convert
|
|
12
13
|
* @returns {string} Converted string
|
|
13
14
|
*/
|
|
14
15
|
export declare function toKebabCase(string: string): string;
|
|
15
16
|
/**
|
|
16
|
-
* Convert a string to snake_case
|
|
17
|
+
* Convert a string to snake_case
|
|
18
|
+
* - 'Hello world' -> 'hello_world'
|
|
17
19
|
*
|
|
18
20
|
* @param {string} string String to convert
|
|
19
21
|
* @returns {string} Converted string
|
|
20
22
|
*/
|
|
21
23
|
export declare function toSnakeCase(string: string): string;
|
|
22
24
|
/**
|
|
23
|
-
* Convert a string to camelCase
|
|
25
|
+
* Convert a string to camelCase
|
|
26
|
+
* - 'Hello world' -> 'helloWorld'
|
|
24
27
|
*
|
|
25
28
|
* @param {string} string String to convert
|
|
26
29
|
* @returns {string} Converted string
|
|
27
30
|
*/
|
|
28
31
|
export declare function toCamelCase(string: string): string;
|
|
29
32
|
/**
|
|
30
|
-
* Convert a string to PascalCase
|
|
33
|
+
* Convert a string to PascalCase
|
|
34
|
+
* - 'Hello world' -> 'HelloWorld'
|
|
31
35
|
*
|
|
32
36
|
* @param {string} string String to convert
|
|
33
37
|
* @returns {string} Converted string
|
|
34
38
|
*/
|
|
35
39
|
export declare function toPascalCase(string: string): string;
|
|
36
40
|
/**
|
|
37
|
-
* Convert a string to Train-Case
|
|
41
|
+
* Convert a string to Train-Case
|
|
42
|
+
* - 'Hello world' -> 'Hello-World'
|
|
38
43
|
*
|
|
39
44
|
* @param {string} string String to convert
|
|
40
45
|
* @returns {string} Converted string
|
|
41
46
|
*/
|
|
42
47
|
export declare function toTrainCase(string: string): string;
|
|
43
48
|
/**
|
|
44
|
-
* Convert a string to CONSTANT_CASE
|
|
49
|
+
* Convert a string to CONSTANT_CASE
|
|
50
|
+
* - 'Hello world' -> 'HELLO_WORLD'
|
|
45
51
|
*
|
|
46
52
|
* @param {string} string String to convert
|
|
47
53
|
* @returns {string} Converted string
|
|
@@ -58,13 +64,13 @@ export declare function cleanPath(path: string): string;
|
|
|
58
64
|
* Convert a path by ensuring it has a trailing slash
|
|
59
65
|
*
|
|
60
66
|
* @param {string} path Path to convert
|
|
61
|
-
* @returns {string}
|
|
67
|
+
* @returns {string} Converted path
|
|
62
68
|
*/
|
|
63
69
|
export declare function addTrailingSlash(path: string): string;
|
|
64
70
|
/**
|
|
65
71
|
* Convert a path by ensuring it has not a trailing slash
|
|
66
72
|
*
|
|
67
73
|
* @param {string} path Path to convert
|
|
68
|
-
* @returns {string}
|
|
74
|
+
* @returns {string} Converted path
|
|
69
75
|
*/
|
|
70
76
|
export declare function removeTrailingSlash(path: string): string;
|
package/lib/strings.js
CHANGED
|
@@ -11,7 +11,8 @@ export function capitalize(string) {
|
|
|
11
11
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Convert a string to kebab-case
|
|
14
|
+
* Convert a string to kebab-case
|
|
15
|
+
* - 'Hello world' -> 'hello-world'
|
|
15
16
|
*
|
|
16
17
|
* @param {string} string String to convert
|
|
17
18
|
* @returns {string} Converted string
|
|
@@ -25,7 +26,8 @@ export function toKebabCase(string) {
|
|
|
25
26
|
.toLowerCase());
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
* Convert a string to snake_case
|
|
29
|
+
* Convert a string to snake_case
|
|
30
|
+
* - 'Hello world' -> 'hello_world'
|
|
29
31
|
*
|
|
30
32
|
* @param {string} string String to convert
|
|
31
33
|
* @returns {string} Converted string
|
|
@@ -39,7 +41,8 @@ export function toSnakeCase(string) {
|
|
|
39
41
|
.toLowerCase());
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
|
-
* Convert a string to camelCase
|
|
44
|
+
* Convert a string to camelCase
|
|
45
|
+
* - 'Hello world' -> 'helloWorld'
|
|
43
46
|
*
|
|
44
47
|
* @param {string} string String to convert
|
|
45
48
|
* @returns {string} Converted string
|
|
@@ -52,7 +55,8 @@ export function toCamelCase(string) {
|
|
|
52
55
|
.replace(/^([A-Z])/, (c) => c.toLowerCase()));
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
55
|
-
* Convert a string to PascalCase
|
|
58
|
+
* Convert a string to PascalCase
|
|
59
|
+
* - 'Hello world' -> 'HelloWorld'
|
|
56
60
|
*
|
|
57
61
|
* @param {string} string String to convert
|
|
58
62
|
* @returns {string} Converted string
|
|
@@ -65,7 +69,8 @@ export function toPascalCase(string) {
|
|
|
65
69
|
.replace(/^([a-z])/, (c) => c.toUpperCase()));
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
|
-
* Convert a string to Train-Case
|
|
72
|
+
* Convert a string to Train-Case
|
|
73
|
+
* - 'Hello world' -> 'Hello-World'
|
|
69
74
|
*
|
|
70
75
|
* @param {string} string String to convert
|
|
71
76
|
* @returns {string} Converted string
|
|
@@ -81,7 +86,8 @@ export function toTrainCase(string) {
|
|
|
81
86
|
.replace(/\b\w/g, (c) => c.toUpperCase()));
|
|
82
87
|
}
|
|
83
88
|
/**
|
|
84
|
-
* Convert a string to CONSTANT_CASE
|
|
89
|
+
* Convert a string to CONSTANT_CASE
|
|
90
|
+
* - 'Hello world' -> 'HELLO_WORLD'
|
|
85
91
|
*
|
|
86
92
|
* @param {string} string String to convert
|
|
87
93
|
* @returns {string} Converted string
|
|
@@ -110,7 +116,7 @@ export function cleanPath(path) {
|
|
|
110
116
|
* Convert a path by ensuring it has a trailing slash
|
|
111
117
|
*
|
|
112
118
|
* @param {string} path Path to convert
|
|
113
|
-
* @returns {string}
|
|
119
|
+
* @returns {string} Converted path
|
|
114
120
|
*/
|
|
115
121
|
export function addTrailingSlash(path) {
|
|
116
122
|
if (path.match(/\.[a-z]{2,4}$/i) || path.match(/^mailto:/) || path.endsWith('/'))
|
|
@@ -121,7 +127,7 @@ export function addTrailingSlash(path) {
|
|
|
121
127
|
* Convert a path by ensuring it has not a trailing slash
|
|
122
128
|
*
|
|
123
129
|
* @param {string} path Path to convert
|
|
124
|
-
* @returns {string}
|
|
130
|
+
* @returns {string} Converted path
|
|
125
131
|
*/
|
|
126
132
|
export function removeTrailingSlash(path) {
|
|
127
133
|
if (path.endsWith('/'))
|