@danielhaim/titlecaser 1.2.36 → 1.2.37

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/TitleCaser.js +21 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielhaim/titlecaser",
3
- "version": "1.2.36",
3
+ "version": "1.2.37",
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",
package/src/TitleCaser.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  }
7
7
  from "./TitleCaserConsts.js";
8
8
 
9
- import Utils from "./TitleCaserUtils.js";
9
+ import TitleCaserUtils from "./TitleCaserUtils.js";
10
10
 
11
11
  export class TitleCaser {
12
12
  constructor (options = {}) {
@@ -36,7 +36,7 @@ export class TitleCaser {
36
36
  shortPrepositionsList,
37
37
  neverCapitalizedList,
38
38
  replaceTerms
39
- } = Utils.getTitleCaseOptions(this.options, commonAbbreviationList, wordReplacementsList);
39
+ } = TitleCaserUtils.getTitleCaseOptions(this.options, commonAbbreviationList, wordReplacementsList);
40
40
 
41
41
  // Prerocess the replaceTerms array to make it easier to search for.
42
42
  const replaceTermsArray = replaceTermList.map(term => Object.keys(term)[0].toLowerCase());
@@ -67,54 +67,54 @@ export class TitleCaser {
67
67
 
68
68
  const wordsInTitleCase = words.map((word, i) => {
69
69
  switch (true) {
70
- case Utils.isWordAmpersand(word):
70
+ case TitleCaserUtils.isWordAmpersand(word):
71
71
  // if the word is an ampersand, return it as is.
72
72
  return word;
73
- case Utils.hasHtmlBreak(word):
73
+ case TitleCaserUtils.hasHtmlBreak(word):
74
74
  // If the word is a <br> tag, return it as is.
75
75
  return word;
76
- case Utils.isWordIgnored(word, ignoreList):
76
+ case TitleCaserUtils.isWordIgnored(word, ignoreList):
77
77
  // If the word is in the ignore list, return it as is.
78
78
  return word;
79
79
  case replaceTermsArray.includes(word.toLowerCase()):
80
80
  // If the word is in the replaceTerms array, return the replacement.
81
81
  return replaceTermObj[word.toLowerCase()];
82
- case Utils.isWordInArray(word, correctTitleCasingList):
82
+ case TitleCaserUtils.isWordInArray(word, correctTitleCasingList):
83
83
  // If the word is in the correctTitleCasingList array, return the correct casing.
84
- return Utils.correctTerm(word, correctTitleCasingList);
85
- case Utils.hasSuffix(word, style):
84
+ return TitleCaserUtils.correctTerm(word, correctTitleCasingList);
85
+ case TitleCaserUtils.hasSuffix(word, style):
86
86
  // If the word has a suffix, return the correct casing.
87
- return Utils.correctSuffix(word, correctTitleCasingList);
88
- case Utils.hasHyphen(word):
87
+ return TitleCaserUtils.correctSuffix(word, correctTitleCasingList);
88
+ case TitleCaserUtils.hasHyphen(word):
89
89
  // If the word has a hyphen, return the correct casing.
90
- return Utils.correctTermHyphenated(word, style);
91
- case Utils.hasUppercaseIntentional(word):
90
+ return TitleCaserUtils.correctTermHyphenated(word, style);
91
+ case TitleCaserUtils.hasUppercaseIntentional(word):
92
92
  // If the word has an intentional uppercase letter, return the correct casing.
93
93
  return word;
94
- case Utils.isShortWord(word, style) && i !== 0:
94
+ case TitleCaserUtils.isShortWord(word, style) && i !== 0:
95
95
  // If the word is a short word, return the correct casing.
96
- return (i > 0 && Utils.endsWithSymbol(words[i - 1],
96
+ return (i > 0 && TitleCaserUtils.endsWithSymbol(words[i - 1],
97
97
  [':', '?', '!', '.'])) ? word.charAt(0).toUpperCase() + word.slice(1) : word.toLowerCase();
98
- case Utils.endsWithSymbol(word):
98
+ case TitleCaserUtils.endsWithSymbol(word):
99
99
  // If the word ends with a symbol, return the correct casing.
100
100
  const splitWord = word.split(/([.,\/#!$%\^&\*;:{}=\-_`~()])/g);
101
101
  const processedWords = splitWord.map((splitWord, j) => {
102
102
  // If the word is in the correctTitleCasingList array, return the correct casing.
103
- if (Utils.isWordInArray(splitWord, correctTitleCasingList)) return Utils.correctTerm(splitWord, correctTitleCasingList);
103
+ if (TitleCaserUtils.isWordInArray(splitWord, correctTitleCasingList)) return TitleCaserUtils.correctTerm(splitWord, correctTitleCasingList);
104
104
  // Else return the word with the correct casing.
105
- else return (j > 0 && Utils.endsWithSymbol(splitWord)) ? splitWord.charAt(0)
105
+ else return (j > 0 && TitleCaserUtils.endsWithSymbol(splitWord)) ? splitWord.charAt(0)
106
106
  .toUpperCase() + splitWord.slice(1) : splitWord.charAt(0)
107
107
  .toUpperCase() + splitWord.slice(1);
108
108
  });
109
109
  // Join the processed words and return them.
110
110
  return processedWords.join("");
111
- case Utils.startsWithSymbol(word):
111
+ case TitleCaserUtils.startsWithSymbol(word):
112
112
  // If the word starts with a symbol, return the correct casing.
113
- return !Utils.isWordInArray(word, correctTitleCasingList) ? word : Utils.correctTerm(word);
114
- case Utils.hasRomanNumeral(word):
113
+ return !TitleCaserUtils.isWordInArray(word, correctTitleCasingList) ? word : TitleCaserUtils.correctTerm(word);
114
+ case TitleCaserUtils.hasRomanNumeral(word):
115
115
  // If the word has a roman numeral, return the correct casing.
116
116
  return word.toUpperCase();
117
- case Utils.hasNumbers(word):
117
+ case TitleCaserUtils.hasNumbers(word):
118
118
  // If the word has numbers, return the correct casing.
119
119
  return word;
120
120
  default: