@danielhaim/titlecaser 1.2.62 → 1.2.64

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/README.md CHANGED
@@ -83,12 +83,12 @@ console.log(output); // 'The Book of Life'
83
83
 
84
84
  ## Usage in the Browser
85
85
 
86
- The function can also be used in a browser environment by including the `titlecaser.amd.js` script in your HTML file:
86
+ The function can also be used in a browser environment by including the `TitleCaser.amd.js` script in your HTML file:
87
87
 
88
88
  Here's an example of how to use the modulate function:
89
89
 
90
90
  ```html
91
- <script src="./path/to/titlecaser.amd.js"></script>
91
+ <script src="./path/to/TitleCaser.amd.js"></script>
92
92
  ```
93
93
 
94
94
  After that, the `toTitleCase()` function can be accessed in your JavaScript code like this:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielhaim/titlecaser",
3
- "version": "1.2.62",
3
+ "version": "1.2.64",
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-package": "webpack --mode production && terser dist/titlecaser.js -o dist/titlecaser.min.js",
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-package && npm run copy-package-to-docs && git add package.json package-lock.json dist/ docs/assets/js && git commit -m 'Bump version and build package for release' && git push",
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",
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
- // console.log(replaceTermsArray);
54
- // console.log(this.wordReplacementsList);
61
+ this.log_warning(`replaceTermsArray: ${replaceTermsArray}`);
62
+ this.log_warning(`this.wordReplacementsList: ${this.wordReplacementsList}`);
55
63
 
56
64
  const map = {
57
65
  "&": "&amp;",
@@ -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
- // console.log("ends with symbol: ", word);
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
- // console.log(splitWord);
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
- // console.log(part);
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
- return TitleCaserUtils.correctTerm(part, correctTitleCasingList);
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
- return replaceTermObj[part];
155
+ const replacement = replaceTermObj[part];
156
+ this.log_warning(`Word is in replaceTermsArray, replacement: ${replacement}`);
157
+ return replacement;
144
158
  } else {
145
- // Apply the correct casing for words not in the list
146
- return part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();
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
- } else {
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
- // Log the updated wordReplacementsList array
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
- // Log the updated wordReplacementsList array
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
- // console.log(this.correctPhraseCasingList);
347
+ this.log_warning(`Log the this.correctPhraseCasingList: ${this.correctPhraseCasingList}`);
335
348
  }
336
349
 
337
350
  setStyle(style) {
@@ -233,9 +233,6 @@ export class TitleCaserUtils {
233
233
  "the",
234
234
  "in",
235
235
  "to",
236
- "from",
237
- "against",
238
- "with",
239
236
  "within",
240
237
  "towards",
241
238
  "into",