es-toolkit 1.18.0-dev.580 → 1.18.0-dev.581

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.
@@ -95,6 +95,9 @@ export { lowerCase } from '../string/lowerCase.mjs';
95
95
  export { startCase } from '../string/startCase.mjs';
96
96
  export { capitalize } from '../string/capitalize.mjs';
97
97
  export { pascalCase } from '../string/pascalCase.mjs';
98
+ export { trim } from '../string/trim.mjs';
99
+ export { ltrim } from '../string/ltrim.mjs';
100
+ export { rtrim } from '../string/rtrim.mjs';
98
101
  export { upperFirst } from '../string/upperFirst.mjs';
99
102
  export { lowerFirst } from '../string/lowerFirst.mjs';
100
103
  export { deburr } from '../string/deburr.mjs';
@@ -95,6 +95,9 @@ export { lowerCase } from '../string/lowerCase.js';
95
95
  export { startCase } from '../string/startCase.js';
96
96
  export { capitalize } from '../string/capitalize.js';
97
97
  export { pascalCase } from '../string/pascalCase.js';
98
+ export { trim } from '../string/trim.js';
99
+ export { ltrim } from '../string/ltrim.js';
100
+ export { rtrim } from '../string/rtrim.js';
98
101
  export { upperFirst } from '../string/upperFirst.js';
99
102
  export { lowerFirst } from '../string/lowerFirst.js';
100
103
  export { deburr } from '../string/deburr.js';
@@ -1220,10 +1220,13 @@ exports.escapeRegExp = string_index.escapeRegExp;
1220
1220
  exports.kebabCase = string_index.kebabCase;
1221
1221
  exports.lowerCase = string_index.lowerCase;
1222
1222
  exports.lowerFirst = string_index.lowerFirst;
1223
+ exports.ltrim = string_index.ltrim;
1223
1224
  exports.pad = string_index.pad;
1224
1225
  exports.pascalCase = string_index.pascalCase;
1226
+ exports.rtrim = string_index.rtrim;
1225
1227
  exports.snakeCase = string_index.snakeCase;
1226
1228
  exports.startCase = string_index.startCase;
1229
+ exports.trim = string_index.trim;
1227
1230
  exports.unescape = string_index.unescape;
1228
1231
  exports.upperCase = string_index.upperCase;
1229
1232
  exports.upperFirst = string_index.upperFirst;
@@ -96,6 +96,9 @@ export { upperCase } from '../string/upperCase.mjs';
96
96
  export { lowerCase } from '../string/lowerCase.mjs';
97
97
  export { startCase } from '../string/startCase.mjs';
98
98
  export { pascalCase } from '../string/pascalCase.mjs';
99
+ export { trim } from '../string/trim.mjs';
100
+ export { ltrim } from '../string/ltrim.mjs';
101
+ export { rtrim } from '../string/rtrim.mjs';
99
102
  export { upperFirst } from '../string/upperFirst.mjs';
100
103
  export { lowerFirst } from '../string/lowerFirst.mjs';
101
104
  export { deburr } from '../string/deburr.mjs';
package/dist/index.d.mts CHANGED
@@ -120,6 +120,9 @@ export { lowerCase } from './string/lowerCase.mjs';
120
120
  export { startCase } from './string/startCase.mjs';
121
121
  export { capitalize } from './string/capitalize.mjs';
122
122
  export { pascalCase } from './string/pascalCase.mjs';
123
+ export { trim } from './string/trim.mjs';
124
+ export { ltrim } from './string/ltrim.mjs';
125
+ export { rtrim } from './string/rtrim.mjs';
123
126
  export { upperFirst } from './string/upperFirst.mjs';
124
127
  export { lowerFirst } from './string/lowerFirst.mjs';
125
128
  export { deburr } from './string/deburr.mjs';
package/dist/index.d.ts CHANGED
@@ -120,6 +120,9 @@ export { lowerCase } from './string/lowerCase.js';
120
120
  export { startCase } from './string/startCase.js';
121
121
  export { capitalize } from './string/capitalize.js';
122
122
  export { pascalCase } from './string/pascalCase.js';
123
+ export { trim } from './string/trim.js';
124
+ export { ltrim } from './string/ltrim.js';
125
+ export { rtrim } from './string/rtrim.js';
123
126
  export { upperFirst } from './string/upperFirst.js';
124
127
  export { lowerFirst } from './string/lowerFirst.js';
125
128
  export { deburr } from './string/deburr.js';
package/dist/index.js CHANGED
@@ -141,10 +141,13 @@ exports.escapeRegExp = string_index.escapeRegExp;
141
141
  exports.kebabCase = string_index.kebabCase;
142
142
  exports.lowerCase = string_index.lowerCase;
143
143
  exports.lowerFirst = string_index.lowerFirst;
144
+ exports.ltrim = string_index.ltrim;
144
145
  exports.pad = string_index.pad;
145
146
  exports.pascalCase = string_index.pascalCase;
147
+ exports.rtrim = string_index.rtrim;
146
148
  exports.snakeCase = string_index.snakeCase;
147
149
  exports.startCase = string_index.startCase;
150
+ exports.trim = string_index.trim;
148
151
  exports.unescape = string_index.unescape;
149
152
  exports.upperCase = string_index.upperCase;
150
153
  exports.upperFirst = string_index.upperFirst;
package/dist/index.mjs CHANGED
@@ -120,6 +120,9 @@ export { lowerCase } from './string/lowerCase.mjs';
120
120
  export { startCase } from './string/startCase.mjs';
121
121
  export { capitalize } from './string/capitalize.mjs';
122
122
  export { pascalCase } from './string/pascalCase.mjs';
123
+ export { trim } from './string/trim.mjs';
124
+ export { ltrim } from './string/ltrim.mjs';
125
+ export { rtrim } from './string/rtrim.mjs';
123
126
  export { upperFirst } from './string/upperFirst.mjs';
124
127
  export { lowerFirst } from './string/lowerFirst.mjs';
125
128
  export { deburr } from './string/deburr.mjs';
@@ -6,6 +6,9 @@ export { lowerCase } from './lowerCase.mjs';
6
6
  export { startCase } from './startCase.mjs';
7
7
  export { capitalize } from './capitalize.mjs';
8
8
  export { pascalCase } from './pascalCase.mjs';
9
+ export { trim } from './trim.mjs';
10
+ export { ltrim } from './ltrim.mjs';
11
+ export { rtrim } from './rtrim.mjs';
9
12
  export { upperFirst } from './upperFirst.mjs';
10
13
  export { lowerFirst } from './lowerFirst.mjs';
11
14
  export { deburr } from './deburr.mjs';
@@ -6,6 +6,9 @@ export { lowerCase } from './lowerCase.js';
6
6
  export { startCase } from './startCase.js';
7
7
  export { capitalize } from './capitalize.js';
8
8
  export { pascalCase } from './pascalCase.js';
9
+ export { trim } from './trim.js';
10
+ export { ltrim } from './ltrim.js';
11
+ export { rtrim } from './rtrim.js';
9
12
  export { upperFirst } from './upperFirst.js';
10
13
  export { lowerFirst } from './lowerFirst.js';
11
14
  export { deburr } from './deburr.js';
@@ -69,6 +69,33 @@ function pascalCase(str) {
69
69
  return words.map(word => capitalize(word)).join('');
70
70
  }
71
71
 
72
+ const ltrim = (str, toTrim) => {
73
+ const chars = str.split('');
74
+ let startHere = 0;
75
+ while ((chars[startHere] === toTrim || toTrim.includes(chars[startHere])) && startHere < chars.length) {
76
+ startHere++;
77
+ }
78
+ return chars.splice(startHere, chars.length).join('');
79
+ };
80
+
81
+ const rtrim = (str, toTrim) => {
82
+ const chars = str.split('');
83
+ while (chars.length > 0) {
84
+ const lastChar = chars[chars.length - 1];
85
+ if (typeof toTrim === 'string' ? lastChar === toTrim : toTrim.includes(lastChar)) {
86
+ chars.pop();
87
+ }
88
+ else {
89
+ break;
90
+ }
91
+ }
92
+ return chars.join('');
93
+ };
94
+
95
+ const trim = (str, toTrim) => {
96
+ return ltrim(rtrim(str, toTrim), toTrim);
97
+ };
98
+
72
99
  function upperFirst(str) {
73
100
  return str.substring(0, 1).toUpperCase() + str.substring(1);
74
101
  }
@@ -159,10 +186,13 @@ exports.escapeRegExp = escapeRegExp;
159
186
  exports.kebabCase = kebabCase;
160
187
  exports.lowerCase = lowerCase;
161
188
  exports.lowerFirst = lowerFirst;
189
+ exports.ltrim = ltrim;
162
190
  exports.pad = pad;
163
191
  exports.pascalCase = pascalCase;
192
+ exports.rtrim = rtrim;
164
193
  exports.snakeCase = snakeCase;
165
194
  exports.startCase = startCase;
195
+ exports.trim = trim;
166
196
  exports.unescape = unescape;
167
197
  exports.upperCase = upperCase;
168
198
  exports.upperFirst = upperFirst;
@@ -6,6 +6,9 @@ export { lowerCase } from './lowerCase.mjs';
6
6
  export { startCase } from './startCase.mjs';
7
7
  export { capitalize } from './capitalize.mjs';
8
8
  export { pascalCase } from './pascalCase.mjs';
9
+ export { trim } from './trim.mjs';
10
+ export { ltrim } from './ltrim.mjs';
11
+ export { rtrim } from './rtrim.mjs';
9
12
  export { upperFirst } from './upperFirst.mjs';
10
13
  export { lowerFirst } from './lowerFirst.mjs';
11
14
  export { deburr } from './deburr.mjs';
@@ -0,0 +1,22 @@
1
+ import { TrimParameter } from './trim.mjs';
2
+
3
+ /**
4
+ * Trims specific characters from the start of a string.
5
+ *
6
+ * This function removes all leading occurrences of the specified character from the input string.
7
+ * Only the characters at the beginning of the string will be removed.
8
+ *
9
+ * @param {string} str - The string from which leading characters will be trimmed.
10
+ * @param {string} toTrim - The character to remove from the start of the string.
11
+ * @returns {string} - The resulting string after the specified leading character has been removed.
12
+ *
13
+ * @example
14
+ * const trimmedStr1 = ltrim('---hello', '-') // returns 'hello'
15
+ * const trimmedStr2 = ltrim('000123', '0') // returns '123'
16
+ * const trimmedStr3 = ltrim('abcabcabc', 'a') // returns 'bcabcabc'
17
+ * const trimmedStr4 = ltrim('xxxtrimmed', 'x') // returns 'trimmed'
18
+ */
19
+
20
+ declare const ltrim: (str: string, toTrim: TrimParameter) => string;
21
+
22
+ export { ltrim };
@@ -0,0 +1,22 @@
1
+ import { TrimParameter } from './trim.js';
2
+
3
+ /**
4
+ * Trims specific characters from the start of a string.
5
+ *
6
+ * This function removes all leading occurrences of the specified character from the input string.
7
+ * Only the characters at the beginning of the string will be removed.
8
+ *
9
+ * @param {string} str - The string from which leading characters will be trimmed.
10
+ * @param {string} toTrim - The character to remove from the start of the string.
11
+ * @returns {string} - The resulting string after the specified leading character has been removed.
12
+ *
13
+ * @example
14
+ * const trimmedStr1 = ltrim('---hello', '-') // returns 'hello'
15
+ * const trimmedStr2 = ltrim('000123', '0') // returns '123'
16
+ * const trimmedStr3 = ltrim('abcabcabc', 'a') // returns 'bcabcabc'
17
+ * const trimmedStr4 = ltrim('xxxtrimmed', 'x') // returns 'trimmed'
18
+ */
19
+
20
+ declare const ltrim: (str: string, toTrim: TrimParameter) => string;
21
+
22
+ export { ltrim };
@@ -0,0 +1,10 @@
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 };
@@ -0,0 +1,22 @@
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 };
@@ -0,0 +1,22 @@
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 };
@@ -0,0 +1,15 @@
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 };
@@ -0,0 +1,4 @@
1
+ type TrimParameter = string | string[];
2
+ declare const trim: (str: string, toTrim: TrimParameter) => string;
3
+
4
+ export { type TrimParameter, trim };
@@ -0,0 +1,4 @@
1
+ type TrimParameter = string | string[];
2
+ declare const trim: (str: string, toTrim: TrimParameter) => string;
3
+
4
+ export { type TrimParameter, trim };
@@ -0,0 +1,8 @@
1
+ import { ltrim } from './ltrim.mjs';
2
+ import { rtrim } from './rtrim.mjs';
3
+
4
+ const trim = (str, toTrim) => {
5
+ return ltrim(rtrim(str, toTrim), toTrim);
6
+ };
7
+
8
+ export { trim };
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.580+db82e936",
4
+ "version": "1.18.0-dev.581+5a7d931c",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {