Skip to content

Commit 6159cbe

Browse files
committed
feat: stringToCapitalize
1 parent dcdde75 commit 6159cbe

File tree

8 files changed

+22
-4
lines changed

8 files changed

+22
-4
lines changed

zova-dev/packages-utils/word-utils/dist/cjs/index.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports.skipPrefix = skipPrefix;
99
exports.skipLastWord = skipLastWord;
1010
exports.splitWords = splitWords;
1111
exports.combineWordsDeduplicate = combineWordsDeduplicate;
12+
exports.stringToCapitalize = stringToCapitalize;
1213
exports.replaceTemplate = replaceTemplate;
1314
function _parseLastWord(str) {
1415
if (!str)
@@ -111,6 +112,11 @@ function combineWordsDeduplicate(str1, str2) {
111112
const leftWord = str1.substring(0, str1.length - lastWord.length);
112113
return leftWord + str2;
113114
}
115+
function stringToCapitalize(str, separator) {
116+
if (typeof str === 'string')
117+
str = str.split(separator ?? ',');
118+
return str.map(name => toUpperCaseFirstChar(name)).join('');
119+
}
114120
function replaceTemplate(content, scope) {
115121
if (!content)
116122
return content;

zova-dev/packages-utils/word-utils/dist/cjs/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export declare function skipPrefix(str?: string, prefix?: string, toLowerCase?:
66
export declare function skipLastWord(str?: string, lastWord?: string, toLowerCase?: boolean): string | undefined;
77
export declare function splitWords(str?: string, toLowerCase?: boolean, separator?: string): string | undefined;
88
export declare function combineWordsDeduplicate(str1: string, str2: string): string;
9+
export declare function stringToCapitalize(str: string[] | string, separator?: string): string;
910
export declare function replaceTemplate(content: string | undefined, scope?: object | undefined): string | undefined;
1011
//# sourceMappingURL=index.d.ts.map

zova-dev/packages-utils/word-utils/dist/cjs/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zova-dev/packages-utils/word-utils/dist/esm/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export declare function skipPrefix(str?: string, prefix?: string, toLowerCase?:
66
export declare function skipLastWord(str?: string, lastWord?: string, toLowerCase?: boolean): string | undefined;
77
export declare function splitWords(str?: string, toLowerCase?: boolean, separator?: string): string | undefined;
88
export declare function combineWordsDeduplicate(str1: string, str2: string): string;
9+
export declare function stringToCapitalize(str: string[] | string, separator?: string): string;
910
export declare function replaceTemplate(content: string | undefined, scope?: object | undefined): string | undefined;
1011
//# sourceMappingURL=index.d.ts.map

zova-dev/packages-utils/word-utils/dist/esm/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zova-dev/packages-utils/word-utils/dist/esm/index.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ function combineWordsDeduplicate(str1, str2) {
9999
const leftWord = str1.substring(0, str1.length - lastWord.length);
100100
return leftWord + str2;
101101
}
102+
function stringToCapitalize(str, separator) {
103+
if (typeof str === 'string')
104+
str = str.split(separator ?? ',');
105+
return str.map(name => toUpperCaseFirstChar(name)).join('');
106+
}
102107
function replaceTemplate(content, scope) {
103108
if (!content)
104109
return content;
@@ -132,4 +137,4 @@ function _getProperty(obj, name, sep, forceObject) {
132137
return obj;
133138
}
134139

135-
export { combineWordsDeduplicate, parseFirstWord, parseLastWord, replaceTemplate, skipLastWord, skipPrefix, splitWords, toLowerCaseFirstChar, toUpperCaseFirstChar };
140+
export { combineWordsDeduplicate, parseFirstWord, parseLastWord, replaceTemplate, skipLastWord, skipPrefix, splitWords, stringToCapitalize, toLowerCaseFirstChar, toUpperCaseFirstChar };

zova-dev/packages-utils/word-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cabloy/word-utils",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "word utils",
55
"publishConfig": {
66
"access": "public"

zova-dev/packages-utils/word-utils/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export function combineWordsDeduplicate(str1: string, str2: string) {
9393
return leftWord + str2;
9494
}
9595

96+
export function stringToCapitalize(str: string[] | string, separator?: string): string {
97+
if (typeof str === 'string') str = str.split(separator ?? ',');
98+
return str.map(name => toUpperCaseFirstChar(name)).join('');
99+
}
100+
96101
export function replaceTemplate(content: string | undefined, scope?: object | undefined): string | undefined {
97102
if (!content) return content;
98103
if (!scope) return content;

0 commit comments

Comments
 (0)