@danielhaim/titlecaser 1.2.57 → 1.2.59
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 +52 -29
- package/package.json +3 -3
- package/src/TitleCaser.js +341 -231
- package/src/TitleCaserConsts.js +138 -234
- package/src/TitleCaserUtils.js +830 -601
- package/src/data/brandList.json +118 -0
- package/src/data/businessFinanceLegalTerms.json +28 -0
- package/src/data/eCommerceDigitalTerms.json +7 -0
- package/src/data/globalGeography.json +49 -0
- package/src/data/marketingMediaTerms.json +19 -0
- package/src/data/miscSpecializedTerms.json +6 -0
- package/src/data/techComputingConcepts.json +36 -0
- package/src/data/timeAcademicTerms.json +10 -0
package/README.md
CHANGED
|
@@ -145,9 +145,10 @@ The `{options}` parameter is an object that contains the settings for the conver
|
|
|
145
145
|
|
|
146
146
|
## Methods
|
|
147
147
|
|
|
148
|
-
- `setReplaceTerms(terms
|
|
149
|
-
- `removeReplaceTerm(term
|
|
150
|
-
- `addReplaceTerm(term
|
|
148
|
+
- `setReplaceTerms(terms)`: Updates the `wordReplacementsList` with new term-replacement pairs. It accepts an array of objects, each containing a single key-value pair representing the term and its replacement.
|
|
149
|
+
- `removeReplaceTerm(term)`: Removes a replaced term from the `wordReplacementsList` array in the option object of the `TitleCaser` instance. Throws an error if the term is not found in the array, otherwise removes it from the array and updates the option object.
|
|
150
|
+
- `addReplaceTerm(term, replacement)`: Adds a single term-replacement pair to the `wordReplacementsList`. If the term already exists, it updates the replacement value.
|
|
151
|
+
- `addExactPhraseReplacements(newPhrases)` - This method allows adding an array of exact phrase replacements to the `TitleCaser` class. Each item in the array should be an object with a single key-value pair, where the key is the phrase to be replaced and the value is the desired replacement.
|
|
151
152
|
- `setStyle(style: string)`: Sets the style option in the object of the TitleCaser instance. The method takes a string argument style that specifies the style to use for the title casing. If the argument is not a string, the method throws a TypeError. Otherwise, it updates the style option in the object.
|
|
152
153
|
- `smartQuotes(smartQuotes: boolean)`: Specifies whether to replace straight quotes with smart quotes during title casing. Provide a boolean argument smartQuotes to enable or disable this feature.
|
|
153
154
|
|
|
@@ -292,43 +293,65 @@ $ npm run test
|
|
|
292
293
|
```
|
|
293
294
|
|
|
294
295
|
```bash
|
|
296
|
+
Testing Acronym/Pronoun of Alpha2/3 Country Codes
|
|
297
|
+
✓ Capitalizes country code "US" correctly in a geopolitical context (4 ms)
|
|
298
|
+
✓ Does not capitalize "us" when used as a pronoun (2 ms)
|
|
299
|
+
✓ Capitalizes country code "UK" with preceding indicator and trailing comma (2 ms)
|
|
300
|
+
✓ Handles multiple instances of country codes and pronouns (2 ms)
|
|
301
|
+
✓ Does not capitalize "us" when used in common phrases (2 ms)
|
|
302
|
+
✓ Capitalizes "USA" in a formal context (1 ms)
|
|
303
|
+
✓ Capitalizes "US" before a government-related word (1 ms)
|
|
304
|
+
✓ Does not capitalize "us" before a government-related word (1 ms)
|
|
305
|
+
✓ Capitalizes "UK" with preceding indicator before a government-related word (2 ms)
|
|
306
|
+
✓ Handles multiple instances of country codes and pronouns before government-related words (1 ms)
|
|
307
|
+
✓ Capitalizes "US" before a military-related word (1 ms)
|
|
308
|
+
✓ Does not capitalize "us" before a military-related word (1 ms)
|
|
309
|
+
✓ Capitalizes "UK" with preceding indicator before a territory-related word (2 ms)
|
|
310
|
+
✓ Handles multiple instances of country codes and pronouns before talks-related words (3 ms)
|
|
311
|
+
✓ Does not capitalize "us" before a talks-related word (1 ms)
|
|
312
|
+
✓ Capitalizes "USA" in a formal context before a bill-related word (1 ms)
|
|
313
|
+
✓ Handles multiple instances of country codes and pronouns before a bill-related word (2 ms)
|
|
314
|
+
|
|
295
315
|
Test Basic Options
|
|
296
316
|
✓ Default title case conversion
|
|
297
|
-
✓ Customized title case conversion
|
|
298
|
-
✓ AP-style title case conversion with replacements
|
|
299
|
-
✓
|
|
300
|
-
✓
|
|
317
|
+
✓ Customized title case conversion (1 ms)
|
|
318
|
+
✓ AP-style title case conversion with replacements (3 ms)
|
|
319
|
+
✓ Testing Word Replacement (Kellogs -> Kellogg\'s)
|
|
320
|
+
✓ AP-style title case conversion with replacements (1 ms)
|
|
321
|
+
✓ Capitalize suffix word in sentence (1 ms)
|
|
301
322
|
|
|
302
323
|
Test Methods
|
|
303
|
-
✓ removeReplaceTerm
|
|
304
|
-
✓ setReplaceTerms
|
|
324
|
+
✓ removeReplaceTerm (1 ms)
|
|
325
|
+
✓ setReplaceTerms (1 ms)
|
|
305
326
|
|
|
306
327
|
Test Variation Stability
|
|
307
|
-
✓ Hyphenated, colon, and short word replacements
|
|
308
328
|
✓ Capitalization and word replacements
|
|
309
|
-
✓ AP-style title case with possessive and colon
|
|
329
|
+
✓ AP-style title case with possessive and colon (1 ms)
|
|
310
330
|
✓ AP-style title case with lowercase back/front-end terms
|
|
311
|
-
✓ Chicago style title case with comparison and colon
|
|
312
|
-
✓ APA style title case with colon
|
|
313
|
-
✓ Wikipedia style title case with acronym and hyphen
|
|
314
|
-
✓
|
|
331
|
+
✓ Chicago style title case with comparison and colon (1 ms)
|
|
332
|
+
✓ APA style title case with colon (2 ms)
|
|
333
|
+
✓ Wikipedia style title case with acronym and hyphen (1 ms)
|
|
334
|
+
✓ Hyphenated, colon, and short word replacements (2 ms)
|
|
335
|
+
✓ I Love Connecting with My Online Friends, but Sometimes I Prefer to Hang Out with My Friends IRL (2 ms)
|
|
336
|
+
✓ Test Smart Quotes (1 ms)
|
|
337
|
+
✓ Wikipedia style capitalization test with special term and colon (1 ms)
|
|
338
|
+
✓ APA style title case with colon and apostrophe (2 ms)
|
|
315
339
|
✓ Chicago style title case with custom term replacements
|
|
316
|
-
✓ AP-style capitalization test with special terms and colon
|
|
317
|
-
✓ NYT-style capitalization test with special terms and colon
|
|
318
|
-
✓ APA style capitalization test with short conjunction terms and colon
|
|
319
|
-
✓ Correct phrase casing list testing
|
|
320
|
-
✓ Wikipedia style capitalization test with special term and colon
|
|
340
|
+
✓ AP-style capitalization test with special terms and colon (1 ms)
|
|
341
|
+
✓ NYT-style capitalization test with special terms and colon (1 ms)
|
|
342
|
+
✓ APA style capitalization test with short conjunction terms and colon (2 ms)
|
|
343
|
+
✓ Correct phrase casing list testing (1 ms)
|
|
321
344
|
|
|
322
345
|
Test Reserved Words
|
|
323
|
-
✓
|
|
324
|
-
✓
|
|
325
|
-
✓
|
|
326
|
-
✓
|
|
327
|
-
✓
|
|
328
|
-
✓
|
|
329
|
-
✓ HTML line break nl2br
|
|
330
|
-
✓ HTML line break nl2br
|
|
331
|
-
✓ Ampersand in a sentence should return & and not &Amp;
|
|
346
|
+
✓ Title case transformation for a single reserved word
|
|
347
|
+
✓ Title case transformation for a sentence with a reserved word and colon (1 ms)
|
|
348
|
+
✓ Title case transformation for a reserved word with a possessive form (1 ms)
|
|
349
|
+
✓ Title case transformation for specific brand names
|
|
350
|
+
✓ Title case transformation for a sentence with HTML line break (nl2br) using <br> tag (1 ms)
|
|
351
|
+
✓ Title case transformation for a sentence with untrimmed white spaces
|
|
352
|
+
✓ Title case transformation for a sentence with HTML line break (nl2br) using <br> tag (1 ms)
|
|
353
|
+
✓ Title case transformation for a sentence with HTML line break (nl2br) without space after colon using <br> tag (1 ms)
|
|
354
|
+
✓ Ampersand in a sentence should return & and not &Amp; (1 ms)
|
|
332
355
|
✓ Untrimmed white spaces
|
|
333
356
|
```
|
|
334
357
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielhaim/titlecaser",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.59",
|
|
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",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"jest-environment-jsdom": "^29.5.0",
|
|
68
68
|
"jest-environment-puppeteer": "^9.0.0",
|
|
69
69
|
"jest-puppeteer": "^9.0.0",
|
|
70
|
-
"puppeteer": "^
|
|
71
|
-
"puppeteer-core": "^
|
|
70
|
+
"puppeteer": "^21.5.2",
|
|
71
|
+
"puppeteer-core": "^21.5.2",
|
|
72
72
|
"terser-webpack-plugin": "^5.3.9",
|
|
73
73
|
"webpack": "^5.86.0",
|
|
74
74
|
"webpack-cli": "^5.1.4",
|