es-toolkit 1.17.0-dev.511 → 1.17.0-dev.514

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.
@@ -101,6 +101,7 @@ export { pascalCase } from '../string/pascalCase.mjs';
101
101
  export { upperFirst } from '../string/upperFirst.mjs';
102
102
  export { lowerFirst } from '../string/lowerFirst.mjs';
103
103
  export { deburr } from '../string/deburr.mjs';
104
+ export { pad } from '../string/pad.mjs';
104
105
  export { chunk } from './array/chunk.mjs';
105
106
  export { concat } from './array/concat.mjs';
106
107
  export { difference } from './array/difference.mjs';
@@ -101,6 +101,7 @@ export { pascalCase } from '../string/pascalCase.js';
101
101
  export { upperFirst } from '../string/upperFirst.js';
102
102
  export { lowerFirst } from '../string/lowerFirst.js';
103
103
  export { deburr } from '../string/deburr.js';
104
+ export { pad } from '../string/pad.js';
104
105
  export { chunk } from './array/chunk.js';
105
106
  export { concat } from './array/concat.js';
106
107
  export { difference } from './array/difference.js';
@@ -933,6 +933,7 @@ exports.deburr = string_index.deburr;
933
933
  exports.kebabCase = string_index.kebabCase;
934
934
  exports.lowerCase = string_index.lowerCase;
935
935
  exports.lowerFirst = string_index.lowerFirst;
936
+ exports.pad = string_index.pad;
936
937
  exports.pascalCase = string_index.pascalCase;
937
938
  exports.snakeCase = string_index.snakeCase;
938
939
  exports.startCase = string_index.startCase;
@@ -102,6 +102,7 @@ export { pascalCase } from '../string/pascalCase.mjs';
102
102
  export { upperFirst } from '../string/upperFirst.mjs';
103
103
  export { lowerFirst } from '../string/lowerFirst.mjs';
104
104
  export { deburr } from '../string/deburr.mjs';
105
+ export { pad } from '../string/pad.mjs';
105
106
  export { chunk } from './array/chunk.mjs';
106
107
  export { concat } from './array/concat.mjs';
107
108
  export { difference } from './array/difference.mjs';
package/dist/index.d.mts CHANGED
@@ -120,3 +120,4 @@ export { pascalCase } from './string/pascalCase.mjs';
120
120
  export { upperFirst } from './string/upperFirst.mjs';
121
121
  export { lowerFirst } from './string/lowerFirst.mjs';
122
122
  export { deburr } from './string/deburr.mjs';
123
+ export { pad } from './string/pad.mjs';
package/dist/index.d.ts CHANGED
@@ -120,3 +120,4 @@ export { pascalCase } from './string/pascalCase.js';
120
120
  export { upperFirst } from './string/upperFirst.js';
121
121
  export { lowerFirst } from './string/lowerFirst.js';
122
122
  export { deburr } from './string/deburr.js';
123
+ export { pad } from './string/pad.js';
package/dist/index.js CHANGED
@@ -136,6 +136,7 @@ exports.deburr = string_index.deburr;
136
136
  exports.kebabCase = string_index.kebabCase;
137
137
  exports.lowerCase = string_index.lowerCase;
138
138
  exports.lowerFirst = string_index.lowerFirst;
139
+ exports.pad = string_index.pad;
139
140
  exports.pascalCase = string_index.pascalCase;
140
141
  exports.snakeCase = string_index.snakeCase;
141
142
  exports.startCase = string_index.startCase;
package/dist/index.mjs CHANGED
@@ -120,3 +120,4 @@ export { pascalCase } from './string/pascalCase.mjs';
120
120
  export { upperFirst } from './string/upperFirst.mjs';
121
121
  export { lowerFirst } from './string/lowerFirst.mjs';
122
122
  export { deburr } from './string/deburr.mjs';
123
+ export { pad } from './string/pad.mjs';
@@ -8,3 +8,4 @@ export { pascalCase } from './pascalCase.mjs';
8
8
  export { upperFirst } from './upperFirst.mjs';
9
9
  export { lowerFirst } from './lowerFirst.mjs';
10
10
  export { deburr } from './deburr.mjs';
11
+ export { pad } from './pad.mjs';
@@ -8,3 +8,4 @@ export { pascalCase } from './pascalCase.js';
8
8
  export { upperFirst } from './upperFirst.js';
9
9
  export { lowerFirst } from './lowerFirst.js';
10
10
  export { deburr } from './deburr.js';
11
+ export { pad } from './pad.js';
@@ -109,12 +109,17 @@ function deburr(str) {
109
109
  return result.join('');
110
110
  }
111
111
 
112
+ const pad = (str, length = 0, chars = ' ') => {
113
+ return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
114
+ };
115
+
112
116
  exports.camelCase = camelCase;
113
117
  exports.capitalize = capitalize;
114
118
  exports.deburr = deburr;
115
119
  exports.kebabCase = kebabCase;
116
120
  exports.lowerCase = lowerCase;
117
121
  exports.lowerFirst = lowerFirst;
122
+ exports.pad = pad;
118
123
  exports.pascalCase = pascalCase;
119
124
  exports.snakeCase = snakeCase;
120
125
  exports.startCase = startCase;
@@ -8,3 +8,4 @@ export { pascalCase } from './pascalCase.mjs';
8
8
  export { upperFirst } from './upperFirst.mjs';
9
9
  export { lowerFirst } from './lowerFirst.mjs';
10
10
  export { deburr } from './deburr.mjs';
11
+ export { pad } from './pad.mjs';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
3
+ * If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
4
+ *
5
+ *
6
+ *
7
+ * @param {string} str - The string to pad.
8
+ * @param {number} [length] - The length of the resulting string once padded.
9
+ * @param {string} [chars] - The character(s) to use for padding.
10
+ * @returns {string} - The padded string, or the original string if padding is not required.
11
+ *
12
+ * @example
13
+ * const result1 = pad('abc', 8); // result will be ' abc '
14
+ * const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
15
+ * const result3 = pad('abc', 3); // result will be 'abc'
16
+ * const result4 = pad('abc', 2); // result will be 'abc'
17
+ *
18
+ */
19
+ declare const pad: (str: string, length?: number, chars?: string) => string;
20
+
21
+ export { pad };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
3
+ * If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
4
+ *
5
+ *
6
+ *
7
+ * @param {string} str - The string to pad.
8
+ * @param {number} [length] - The length of the resulting string once padded.
9
+ * @param {string} [chars] - The character(s) to use for padding.
10
+ * @returns {string} - The padded string, or the original string if padding is not required.
11
+ *
12
+ * @example
13
+ * const result1 = pad('abc', 8); // result will be ' abc '
14
+ * const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
15
+ * const result3 = pad('abc', 3); // result will be 'abc'
16
+ * const result4 = pad('abc', 2); // result will be 'abc'
17
+ *
18
+ */
19
+ declare const pad: (str: string, length?: number, chars?: string) => string;
20
+
21
+ export { pad };
@@ -0,0 +1,5 @@
1
+ const pad = (str, length = 0, chars = ' ') => {
2
+ return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
3
+ };
4
+
5
+ export { pad };
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.17.0-dev.511+3a6cb365",
4
+ "version": "1.17.0-dev.514+4b529e2a",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {