es-toolkit 1.18.0-dev.581 → 1.18.0-dev.582
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +3 -3
- package/dist/compat/index.d.ts +3 -3
- package/dist/compat/index.js +69 -3
- package/dist/compat/index.mjs +3 -3
- package/dist/compat/string/trim.d.mts +15 -0
- package/dist/compat/string/trim.d.ts +15 -0
- package/dist/compat/string/trim.mjs +25 -0
- package/dist/compat/string/trimEnd.d.mts +16 -0
- package/dist/compat/string/trimEnd.d.ts +16 -0
- package/dist/compat/string/trimEnd.mjs +25 -0
- package/dist/{string/ltrim.d.ts → compat/string/trimStart.d.mts} +4 -10
- package/dist/{string/ltrim.d.mts → compat/string/trimStart.d.ts} +4 -10
- package/dist/compat/string/trimStart.mjs +25 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/string/index.d.mts +2 -2
- package/dist/string/index.d.ts +2 -2
- package/dist/string/index.js +44 -22
- package/dist/string/index.mjs +2 -2
- package/dist/string/trim.d.mts +14 -3
- package/dist/string/trim.d.ts +14 -3
- package/dist/string/trim.mjs +8 -5
- package/dist/string/trimEnd.d.mts +16 -0
- package/dist/string/trimEnd.d.ts +16 -0
- package/dist/string/trimEnd.mjs +22 -0
- package/dist/string/trimStart.d.mts +16 -0
- package/dist/string/trimStart.d.ts +16 -0
- package/dist/string/trimStart.mjs +22 -0
- package/package.json +1 -1
- package/dist/string/ltrim.mjs +0 -10
- package/dist/string/rtrim.d.mts +0 -22
- package/dist/string/rtrim.d.ts +0 -22
- package/dist/string/rtrim.mjs +0 -15
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function trimEnd(str, chars) {
|
|
2
|
+
if (chars == null) {
|
|
3
|
+
return str.trimEnd();
|
|
4
|
+
}
|
|
5
|
+
let endIndex = str.length;
|
|
6
|
+
switch (typeof chars) {
|
|
7
|
+
case 'string': {
|
|
8
|
+
while (endIndex > 0 && str[endIndex - 1] === chars) {
|
|
9
|
+
endIndex--;
|
|
10
|
+
}
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case 'object': {
|
|
14
|
+
while (endIndex > 0 && chars.includes(str[endIndex - 1])) {
|
|
15
|
+
endIndex--;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return str.substring(0, endIndex);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { trimEnd };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes leading whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which leading characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string.
|
|
6
|
+
* @returns {string} - The resulting string after the specified leading character has been removed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const trimmedStr1 = trimStart('---hello', '-') // returns 'hello'
|
|
10
|
+
* const trimmedStr2 = trimStart('000123', '0') // returns '123'
|
|
11
|
+
* const trimmedStr3 = trimStart('abcabcabc', 'a') // returns 'bcabcabc'
|
|
12
|
+
* const trimmedStr4 = trimStart('xxxtrimmed', 'x') // returns 'trimmed'
|
|
13
|
+
*/
|
|
14
|
+
declare function trimStart(str: string, chars?: string | string[]): string;
|
|
15
|
+
|
|
16
|
+
export { trimStart };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes leading whitespace or specified characters from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string from which leading characters will be trimmed.
|
|
5
|
+
* @param {string | string[]} chars - The character(s) to remove from the end of the string.
|
|
6
|
+
* @returns {string} - The resulting string after the specified leading character has been removed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const trimmedStr1 = trimStart('---hello', '-') // returns 'hello'
|
|
10
|
+
* const trimmedStr2 = trimStart('000123', '0') // returns '123'
|
|
11
|
+
* const trimmedStr3 = trimStart('abcabcabc', 'a') // returns 'bcabcabc'
|
|
12
|
+
* const trimmedStr4 = trimStart('xxxtrimmed', 'x') // returns 'trimmed'
|
|
13
|
+
*/
|
|
14
|
+
declare function trimStart(str: string, chars?: string | string[]): string;
|
|
15
|
+
|
|
16
|
+
export { trimStart };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function trimStart(str, chars) {
|
|
2
|
+
if (chars == null) {
|
|
3
|
+
return str.trimStart();
|
|
4
|
+
}
|
|
5
|
+
let startIndex = 0;
|
|
6
|
+
switch (typeof chars) {
|
|
7
|
+
case 'string': {
|
|
8
|
+
while (startIndex < str.length && str[startIndex] === chars) {
|
|
9
|
+
startIndex++;
|
|
10
|
+
}
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case 'object': {
|
|
14
|
+
while (startIndex < str.length && chars.includes(str[startIndex])) {
|
|
15
|
+
startIndex++;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return str.substring(startIndex);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { trimStart };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.18.0-dev.
|
|
4
|
+
"version": "1.18.0-dev.582+4a172144",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|
package/dist/string/ltrim.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const ltrim = (str, toTrim) => {
|
|
2
|
-
const chars = str.split('');
|
|
3
|
-
let startHere = 0;
|
|
4
|
-
while ((chars[startHere] === toTrim || toTrim.includes(chars[startHere])) && startHere < chars.length) {
|
|
5
|
-
startHere++;
|
|
6
|
-
}
|
|
7
|
-
return chars.splice(startHere, chars.length).join('');
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export { ltrim };
|
package/dist/string/rtrim.d.mts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { TrimParameter } from './trim.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Trims specific characters from the end of a string.
|
|
5
|
-
*
|
|
6
|
-
* This function removes all trailing occurrences of the specified character from the input string.
|
|
7
|
-
* Only the characters at the end of the string will be removed.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} str - The string from which trailing characters will be trimmed.
|
|
10
|
-
* @param {string} toTrim - The character to remove from the end of the string.
|
|
11
|
-
* @returns {string} - The resulting string after the specified trailing character has been removed.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* const trimmedStr1 = rtrim('hello---', '-') // returns 'hello'
|
|
15
|
-
* const trimmedStr2 = rtrim('123000', '0') // returns '123'
|
|
16
|
-
* const trimmedStr3 = rtrim('abcabcabc', 'c') // returns 'abcabcab'
|
|
17
|
-
* const trimmedStr4 = rtrim('trimmedxxx', 'x') // returns 'trimmed'
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
declare const rtrim: (str: string, toTrim: TrimParameter) => string;
|
|
21
|
-
|
|
22
|
-
export { rtrim };
|
package/dist/string/rtrim.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { TrimParameter } from './trim.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Trims specific characters from the end of a string.
|
|
5
|
-
*
|
|
6
|
-
* This function removes all trailing occurrences of the specified character from the input string.
|
|
7
|
-
* Only the characters at the end of the string will be removed.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} str - The string from which trailing characters will be trimmed.
|
|
10
|
-
* @param {string} toTrim - The character to remove from the end of the string.
|
|
11
|
-
* @returns {string} - The resulting string after the specified trailing character has been removed.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* const trimmedStr1 = rtrim('hello---', '-') // returns 'hello'
|
|
15
|
-
* const trimmedStr2 = rtrim('123000', '0') // returns '123'
|
|
16
|
-
* const trimmedStr3 = rtrim('abcabcabc', 'c') // returns 'abcabcab'
|
|
17
|
-
* const trimmedStr4 = rtrim('trimmedxxx', 'x') // returns 'trimmed'
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
declare const rtrim: (str: string, toTrim: TrimParameter) => string;
|
|
21
|
-
|
|
22
|
-
export { rtrim };
|
package/dist/string/rtrim.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const rtrim = (str, toTrim) => {
|
|
2
|
-
const chars = str.split('');
|
|
3
|
-
while (chars.length > 0) {
|
|
4
|
-
const lastChar = chars[chars.length - 1];
|
|
5
|
-
if (typeof toTrim === 'string' ? lastChar === toTrim : toTrim.includes(lastChar)) {
|
|
6
|
-
chars.pop();
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
break;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return chars.join('');
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { rtrim };
|