@danielhaim/titlecaser 1.2.61 → 1.2.63
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/package.json +5 -5
- package/src/TitleCaser.js +28 -15
- package/src/TitleCaserUtils.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielhaim/titlecaser",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.63",
|
|
4
4
|
"description": "Converts a string to title case with multiple style options, ability to ignore certain words, and handle acronyms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"title case",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
],
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build-docs": "cd docs && bundle install && bundle exec jekyll build",
|
|
47
|
-
"build
|
|
47
|
+
"build": "npx webpack --mode production",
|
|
48
48
|
"copy-package-to-docs": "cp -R dist/ docs/assets/js",
|
|
49
|
-
"release": "npm version patch && npm run build
|
|
49
|
+
"release": "npm version patch && npm run build && git add -A && git commit -m 'Release: v$(node -p \"require('./package.json').version\")' && git push && npm publish",
|
|
50
50
|
"test": "jest",
|
|
51
|
-
"tree": "tree -I 'node_modules'"
|
|
51
|
+
"tree": "tree -a -I 'node_modules|.git'"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/cli": "^7.21.5",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"babel-loader": "^9.1.2",
|
|
64
64
|
"esbuild-jest": "^0.5.0",
|
|
65
65
|
"exports-loader": "^4.0.0",
|
|
66
|
-
"jest": "^29.
|
|
66
|
+
"jest": "^29.7.0",
|
|
67
67
|
"jest-environment-jsdom": "^29.5.0",
|
|
68
68
|
"jest-environment-puppeteer": "^9.0.0",
|
|
69
69
|
"jest-puppeteer": "^9.0.0",
|
package/src/TitleCaser.js
CHANGED
|
@@ -10,10 +10,18 @@ import { TitleCaserUtils } from "./TitleCaserUtils.js";
|
|
|
10
10
|
export class TitleCaser {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
this.options = options;
|
|
13
|
+
this.debug = options.debug || false;
|
|
13
14
|
this.wordReplacementsList = wordReplacementsList;
|
|
14
15
|
this.correctPhraseCasingList = correctPhraseCasingList;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
log_warning(message) {
|
|
19
|
+
if (this.debug) {
|
|
20
|
+
console.warn(`Warning: ${message}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
17
25
|
toTitleCase(str) {
|
|
18
26
|
try {
|
|
19
27
|
// If input is empty, throw an error.
|
|
@@ -50,8 +58,8 @@ export class TitleCaser {
|
|
|
50
58
|
replaceTermList.map((term) => [Object.keys(term)[0].toLowerCase(), Object.values(term)[0]]),
|
|
51
59
|
);
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
this.log_warning(`replaceTermsArray: ${replaceTermsArray}`);
|
|
62
|
+
this.log_warning(`this.wordReplacementsList: ${this.wordReplacementsList}`);
|
|
55
63
|
|
|
56
64
|
const map = {
|
|
57
65
|
"&": "&",
|
|
@@ -125,25 +133,32 @@ export class TitleCaser {
|
|
|
125
133
|
? word.charAt(0).toUpperCase() + word.slice(1)
|
|
126
134
|
: word.toLowerCase();
|
|
127
135
|
case TitleCaserUtils.endsWithSymbol(word):
|
|
128
|
-
|
|
136
|
+
this.log_warning(`Check if the word ends with a symbol: ${word}`);
|
|
129
137
|
// If the word ends with a symbol, return the correct casing.
|
|
130
138
|
const splitWord = word.split(/([.,\/#!$%\^&\*;:{}=\-_`~()?])/g);
|
|
131
|
-
|
|
139
|
+
this.log_warning(`Splitting word at symbols, result: ${splitWord}`);
|
|
132
140
|
// Process each part for correct casing
|
|
133
141
|
const processedWords = splitWord.map((part) => {
|
|
142
|
+
this.log_warning(`Processing part: ${part}`);
|
|
134
143
|
// Check if part is a symbol
|
|
135
144
|
if (TitleCaserUtils.endsWithSymbol(part)) {
|
|
136
|
-
|
|
145
|
+
this.log_warning(`Part is a symbol: ${part}`);
|
|
137
146
|
return part;
|
|
138
147
|
} else {
|
|
148
|
+
this.log_warning(`Part is a word: ${part}`);
|
|
139
149
|
// If it's a word, process it for correct casing
|
|
140
150
|
if (TitleCaserUtils.isWordInArray(part, correctTitleCasingList)) {
|
|
141
|
-
|
|
151
|
+
const correctedTerm = TitleCaserUtils.correctTerm(part, correctTitleCasingList);
|
|
152
|
+
this.log_warning(`Word is in correctTitleCasingList, corrected term: ${correctedTerm}`);
|
|
153
|
+
return correctedTerm;
|
|
142
154
|
} else if (replaceTermsArray.includes(part)) {
|
|
143
|
-
|
|
155
|
+
const replacement = replaceTermObj[part];
|
|
156
|
+
this.log_warning(`Word is in replaceTermsArray, replacement: ${replacement}`);
|
|
157
|
+
return replacement;
|
|
144
158
|
} else {
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
const titledWord = part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();
|
|
160
|
+
this.log_warning(`Applying title casing to word: ${titledWord}`);
|
|
161
|
+
return titledWord;
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
});
|
|
@@ -213,7 +228,7 @@ export class TitleCaser {
|
|
|
213
228
|
} else {
|
|
214
229
|
newWords[i] = "US" + punctuation;
|
|
215
230
|
}
|
|
216
|
-
|
|
231
|
+
} else {
|
|
217
232
|
if (punctuation === "") {
|
|
218
233
|
newWords[i] = "Us";
|
|
219
234
|
} else {
|
|
@@ -255,8 +270,7 @@ export class TitleCaser {
|
|
|
255
270
|
|
|
256
271
|
this.options.wordReplacementsList = this.wordReplacementsList;
|
|
257
272
|
|
|
258
|
-
|
|
259
|
-
// console.log(this.wordReplacementsList);
|
|
273
|
+
this.log_warning(`Log the updated this.wordReplacementsList: ${this.wordReplacementsList}`);
|
|
260
274
|
}
|
|
261
275
|
|
|
262
276
|
addReplaceTerm(term, replacement) {
|
|
@@ -295,8 +309,7 @@ export class TitleCaser {
|
|
|
295
309
|
// Update the replace terms option
|
|
296
310
|
this.options.wordReplacementsList = this.wordReplacementsList;
|
|
297
311
|
|
|
298
|
-
|
|
299
|
-
// console.log(this.wordReplacementsList);
|
|
312
|
+
this.log_warning(`Log the updated this.wordReplacementsList: ${this.wordReplacementsList}`);
|
|
300
313
|
}
|
|
301
314
|
|
|
302
315
|
addExactPhraseReplacements(newPhrases) {
|
|
@@ -331,7 +344,7 @@ export class TitleCaser {
|
|
|
331
344
|
}
|
|
332
345
|
});
|
|
333
346
|
|
|
334
|
-
|
|
347
|
+
this.log_warning(`Log the this.correctPhraseCasingList: ${this.correctPhraseCasingList}`);
|
|
335
348
|
}
|
|
336
349
|
|
|
337
350
|
setStyle(style) {
|