@win2win/shared 1.0.276 → 1.0.278
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.
|
@@ -21,7 +21,11 @@ export declare function toCurrency(value: number, symbol?: string, options?: {
|
|
|
21
21
|
* @returns
|
|
22
22
|
*/
|
|
23
23
|
export declare function mergeObjects<T = Record<string, any>>(...args: (Record<string, any> | undefined | null | "")[]): T;
|
|
24
|
-
export
|
|
24
|
+
export interface CapitalizeOptions {
|
|
25
|
+
ignoreStopWords?: boolean;
|
|
26
|
+
ignoreWords?: string[];
|
|
27
|
+
}
|
|
28
|
+
export declare function capitalize(text: string, allWords?: boolean, options?: CapitalizeOptions): string;
|
|
25
29
|
export declare function formatContactName(contact?: {
|
|
26
30
|
NOMBRE?: string | null;
|
|
27
31
|
APELLIDO?: string | null;
|
|
@@ -104,12 +104,38 @@ function mergeObjects(...args) {
|
|
|
104
104
|
}, {});
|
|
105
105
|
}
|
|
106
106
|
const formatOneWord = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
107
|
-
|
|
107
|
+
const STOP_WORDS = [
|
|
108
|
+
"de",
|
|
109
|
+
"la",
|
|
110
|
+
"del",
|
|
111
|
+
"y",
|
|
112
|
+
"o",
|
|
113
|
+
"en",
|
|
114
|
+
"el",
|
|
115
|
+
"los",
|
|
116
|
+
"las",
|
|
117
|
+
"a",
|
|
118
|
+
"un",
|
|
119
|
+
"una",
|
|
120
|
+
];
|
|
121
|
+
function capitalize(text, allWords = false, options = {}) {
|
|
108
122
|
if (typeof text !== "string")
|
|
109
123
|
return text;
|
|
110
124
|
text = text.toLowerCase().replaceAll("_", " ").trim();
|
|
111
125
|
return allWords
|
|
112
|
-
? text
|
|
126
|
+
? text
|
|
127
|
+
.split(" ")
|
|
128
|
+
.map((word) => {
|
|
129
|
+
const value = word.trim().toLowerCase();
|
|
130
|
+
if ((options.ignoreWords || []).includes(value)) {
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
if (options.ignoreStopWords && STOP_WORDS.includes(value)) {
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
return formatOneWord(word);
|
|
137
|
+
})
|
|
138
|
+
.join(" ")
|
|
113
139
|
: formatOneWord(text);
|
|
114
140
|
}
|
|
115
141
|
function formatContactName(contact) {
|
|
@@ -124,7 +150,7 @@ function formatContactName(contact) {
|
|
|
124
150
|
return capitalize([nombre, apellido, apellido2]
|
|
125
151
|
.map((v) => String(v || "").trim())
|
|
126
152
|
.filter(Boolean)
|
|
127
|
-
.join(" "), true).trim();
|
|
153
|
+
.join(" "), true, { ignoreStopWords: true }).trim();
|
|
128
154
|
}
|
|
129
155
|
const upperSnakeCase = (text) => (0, lodash_1.snakeCase)(text).toUpperCase();
|
|
130
156
|
exports.upperSnakeCase = upperSnakeCase;
|
package/package.json
CHANGED