es-toolkit 1.10.1-dev.228 → 1.10.1-dev.230
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/chunk-MJA7DAOJ.mjs +25 -0
- package/dist/chunk-MJA7DAOJ.mjs.map +1 -0
- package/dist/{chunk-74WWMNZS.mjs → chunk-OLX53VEF.mjs} +4 -2
- package/dist/{chunk-74WWMNZS.mjs.map → chunk-OLX53VEF.mjs.map} +1 -1
- package/dist/chunk-XT74R35S.mjs +1 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +22 -1
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +6 -2
- package/dist/compat/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -2
- package/dist/object/index.js +3 -1
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +1 -1
- package/dist/object/invert.js +3 -1
- package/dist/object/invert.js.map +1 -1
- package/dist/object/invert.mjs +1 -1
- package/dist/string/index.d.mts +1 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +21 -2
- package/dist/string/index.js.map +1 -1
- package/dist/string/index.mjs +6 -2
- package/dist/string/startCase.d.mts +16 -0
- package/dist/string/startCase.d.ts +16 -0
- package/dist/string/startCase.js +54 -0
- package/dist/string/startCase.js.map +1 -0
- package/dist/string/startCase.mjs +9 -0
- package/dist/string/startCase.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-QKYYOLJ6.mjs +0 -1
- /package/dist/{chunk-QKYYOLJ6.mjs.map → chunk-XT74R35S.mjs.map} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getWords
|
|
3
|
+
} from "./chunk-WVQ7YVRK.mjs";
|
|
4
|
+
|
|
5
|
+
// src/string/startCase.ts
|
|
6
|
+
function startCase(str) {
|
|
7
|
+
const words = getWords(str.trim());
|
|
8
|
+
let result = "";
|
|
9
|
+
for (const word of words) {
|
|
10
|
+
if (result) {
|
|
11
|
+
result += " ";
|
|
12
|
+
}
|
|
13
|
+
if (word === word.toUpperCase()) {
|
|
14
|
+
result += word;
|
|
15
|
+
} else {
|
|
16
|
+
result += word[0].toUpperCase() + word.slice(1).toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
startCase
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-MJA7DAOJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/string/startCase.ts"],"sourcesContent":["import { getWords } from './_internal/getWords';\n\n/**\n * Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.\n *\n * Start case is the naming convention in which each word is written with an initial capital letter.\n * @param {string} str - The string to convert.\n * @returns {string} The converted string.\n *\n * @example\n * const result1 = startCase('hello world'); // result will be 'Hello World'\n * const result2 = startCase('HELLO WORLD'); // result will be 'Hello World'\n * const result3 = startCase('hello-world'); // result will be 'Hello World'\n * const result4 = startCase('hello_world'); // result will be 'Hello World'\n */\nexport function startCase(str: string): string {\n const words = getWords(str.trim());\n let result = '';\n for (const word of words) {\n if (result) {\n result += ' ';\n }\n if (word === word.toUpperCase()) {\n result += word;\n } else {\n result += word[0].toUpperCase() + word.slice(1).toLowerCase();\n }\n }\n return result;\n}\n"],"mappings":";;;;;AAeO,SAAS,UAAU,KAAqB;AAC7C,QAAM,QAAQ,SAAS,IAAI,KAAK,CAAC;AACjC,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,QAAI,QAAQ;AACV,gBAAU;AAAA,IACZ;AACA,QAAI,SAAS,KAAK,YAAY,GAAG;AAC/B,gBAAU;AAAA,IACZ,OAAO;AACL,gBAAU,KAAK,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,EAAE,YAAY;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/object/invert.ts
|
|
2
2
|
function invert(obj) {
|
|
3
3
|
const result = {};
|
|
4
|
-
|
|
4
|
+
const keys = Object.keys(obj);
|
|
5
|
+
for (let i = 0; i < keys.length; i++) {
|
|
6
|
+
const key = keys[i];
|
|
5
7
|
const value = obj[key];
|
|
6
8
|
result[value] = key;
|
|
7
9
|
}
|
|
@@ -11,4 +13,4 @@ function invert(obj) {
|
|
|
11
13
|
export {
|
|
12
14
|
invert
|
|
13
15
|
};
|
|
14
|
-
//# sourceMappingURL=chunk-
|
|
16
|
+
//# sourceMappingURL=chunk-OLX53VEF.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/object/invert.ts"],"sourcesContent":["/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n for (
|
|
1
|
+
{"version":3,"sources":["../src/object/invert.ts"],"sourcesContent":["/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n"],"mappings":";AAkBO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,QAAM,OAAO,OAAO,KAAK,GAAG;AAE5B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,QAAQ,IAAI,GAAG;AACrB,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-XT74R35S.mjs.map
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -80,6 +80,7 @@ export { camelCase } from '../string/camelCase.mjs';
|
|
|
80
80
|
export { snakeCase } from '../string/snakeCase.mjs';
|
|
81
81
|
export { kebabCase } from '../string/kebabCase.mjs';
|
|
82
82
|
export { lowerCase } from '../string/lowerCase.mjs';
|
|
83
|
+
export { startCase } from '../string/startCase.mjs';
|
|
83
84
|
export { capitalize } from '../string/capitalize.mjs';
|
|
84
85
|
|
|
85
86
|
/**
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -80,6 +80,7 @@ export { camelCase } from '../string/camelCase.js';
|
|
|
80
80
|
export { snakeCase } from '../string/snakeCase.js';
|
|
81
81
|
export { kebabCase } from '../string/kebabCase.js';
|
|
82
82
|
export { lowerCase } from '../string/lowerCase.js';
|
|
83
|
+
export { startCase } from '../string/startCase.js';
|
|
83
84
|
export { capitalize } from '../string/capitalize.js';
|
|
84
85
|
|
|
85
86
|
/**
|
package/dist/compat/index.js
CHANGED
|
@@ -94,6 +94,7 @@ __export(compat_exports, {
|
|
|
94
94
|
sampleSize: () => sampleSize,
|
|
95
95
|
shuffle: () => shuffle,
|
|
96
96
|
snakeCase: () => snakeCase,
|
|
97
|
+
startCase: () => startCase,
|
|
97
98
|
sum: () => sum,
|
|
98
99
|
sumBy: () => sumBy,
|
|
99
100
|
tail: () => tail,
|
|
@@ -834,7 +835,9 @@ function pickBy(obj, shouldPick) {
|
|
|
834
835
|
// src/object/invert.ts
|
|
835
836
|
function invert(obj) {
|
|
836
837
|
const result = {};
|
|
837
|
-
|
|
838
|
+
const keys = Object.keys(obj);
|
|
839
|
+
for (let i = 0; i < keys.length; i++) {
|
|
840
|
+
const key = keys[i];
|
|
838
841
|
const value = obj[key];
|
|
839
842
|
result[value] = key;
|
|
840
843
|
}
|
|
@@ -989,6 +992,23 @@ var lowerCase = (str) => {
|
|
|
989
992
|
return words.map((word) => word.toLowerCase()).join(" ");
|
|
990
993
|
};
|
|
991
994
|
|
|
995
|
+
// src/string/startCase.ts
|
|
996
|
+
function startCase(str) {
|
|
997
|
+
const words = getWords(str.trim());
|
|
998
|
+
let result = "";
|
|
999
|
+
for (const word of words) {
|
|
1000
|
+
if (result) {
|
|
1001
|
+
result += " ";
|
|
1002
|
+
}
|
|
1003
|
+
if (word === word.toUpperCase()) {
|
|
1004
|
+
result += word;
|
|
1005
|
+
} else {
|
|
1006
|
+
result += word[0].toUpperCase() + word.slice(1).toLowerCase();
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return result;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
992
1012
|
// src/compat/array/chunk.ts
|
|
993
1013
|
function chunk2(arr, size = 1) {
|
|
994
1014
|
size = Math.max(Math.floor(size), 0);
|
|
@@ -1059,6 +1079,7 @@ function chunk2(arr, size = 1) {
|
|
|
1059
1079
|
sampleSize,
|
|
1060
1080
|
shuffle,
|
|
1061
1081
|
snakeCase,
|
|
1082
|
+
startCase,
|
|
1062
1083
|
sum,
|
|
1063
1084
|
sumBy,
|
|
1064
1085
|
tail,
|