@danielhaim/titlecaser 1.7.10 → 1.7.13

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
@@ -4,415 +4,272 @@
4
4
  [![Downloads](https://img.shields.io/npm/dt/@danielhaim/titlecaser.svg)](https://www.npmjs.com/package/@danielhaim/titlecaser)
5
5
  ![GitHub](https://img.shields.io/github/license/danielhaim1/titlecaser)
6
6
 
7
- A powerful utility for converting text to title case with support for multiple style guides and extensive customization options.
7
+ A style-guide–aware title case engine for JavaScript that implements **AP**, **APA**, **Chicago**, **NYT**, **Wikipedia**, and **British** styles with contextual acronym disambiguation and 1,000+ curated domain terms.
8
8
 
9
9
  <a target="_blank" href="https://danielhaim1.github.io/TitleCaser/"><img src="https://raw.githubusercontent.com/danielhaim1/TitleCaser/main/docs/assets/demo.png" width="100%" height="auto" alt="TitleCaser Demo"></a>
10
10
 
11
- - [TitleCaser](#titlecaser)
12
- * [Demo](https://danielhaim1.github.io/TitleCaser/)
13
- * [CodePen Demo 1](https://codepen.io/danielhaim/pen/oNQgjBv)
14
- * [CodePen Demo 2](https://codepen.io/danielhaim/pen/oNPGzKw)
15
- * [Table of Contents](#table-of-contents)
16
- * [Introduction](#introduction)
17
- * [Key Features:](#key-features)
18
- * [Installation](#installation)
19
- * [Usage](#usage)
20
- * [Usage in the Browser](#usage-in-the-browser)
21
- * [Options](#options)
22
- * [Methods](#methods)
23
- * [Examples](#examples)
24
- + [Basic Usage](#basic-usage)
25
- + [Customizing Word Replacements Method](#customizing-word-replacements-method)
26
- + [Customizing TitleCaser](#customizing-titlecaser)
27
- + [TitleCaser with Default Word Replacement](#titlecaser-with-default-word-replacement)
28
- + [TitleCaser with Possessive Noun and a Colon](#titlecaser-with-possessive-noun-and-a-colon)
29
- * [Build Process](#build-process)
30
- * [Test](#test)
31
- * [Resources](#resources)
32
- * [Report Bugs](#report-bugs)
33
- * [Contributing](CONTRIBUTING.md)
34
- * [Changelog](CHANGELOG.md)
35
-
36
- ## Overview
37
-
38
- TitleCaser is a comprehensive solution for converting text to title case according to various style guides (AP, APA, Chicago, NYT, Wikipedia, British). It handles special cases like hyphens, apostrophes, Roman numerals, and acronyms, and provides extensive customization options.
39
-
40
- ## Language Conventions and Style Library
41
-
42
- **The comprehensive Language Conventions and Style Library (LCSL)** is specifically designed to assist web content developers in adhering to the latest style guides and English language conventions. This all-inclusive library has various features, including support for numerous style guides such as **AP, APA, Chicago, NY Times, Wikipedia, and British styles** and customizable preferences to tailor to individual needs. **TitleCaser is a component of this library**, and LCSL is set to be open-sourced by the end of 2025.
43
-
44
- ### Streamlined Workflow
45
- To streamline workflow, modules are available in both **browser and node environment versions** and include a command-line interface for building, testing, and minimizing the module. Additionally, it features a **filter ability** that allows users to ignore certain phrases containing short words, preventing the module from mistakenly flagging instances where short words are used as part of a larger term or phrase.
46
-
47
- ### Comprehensive Capitalization Handling
48
- The module has been designed to handle various capitalization scenarios, including:
49
- - **Hyphenated words**
50
- - **Prefixes and suffixes**
51
- - **Reserved words**
52
- - **Roman numerals**
53
- - **Proper nouns** that contain lowercase letters
54
- - **Words that require capitalization** in specific contexts
55
-
56
- This ensures that your content meets the appropriate style and formatting guidelines, regardless of the context. It also offers **word replacement capabilities**, as well as **ignored phrases** to create consistency in cases where certain terms may be capitalized differently depending on the context.
57
-
58
- ### Essential Tool for Content Developers
59
- Whether you're developing web content for a major news organization or simply looking to improve your writing skills, this module is an **essential tool** that can help ensure your work is accurate, consistent, and conforms to the latest style guidelines.
60
-
61
- ### Key Features:
62
- - **Support for popular style guides** and customizable preferences
63
- - **Advanced capitalization handling** for suffixes, prefixes, hyphenated words, and reserved words
64
- - **Support for proper capitalization** of Roman numerals and exclusion of specific words and phrases from title capitalization
65
- - **Word replacement capabilities** for consistency in capitalization
66
- - **Command-line interface** for building, testing, and minimizing the module
67
- - **Pre-defined word lists** for articles, conjunctions, prepositions, and non-capitalized words in titles
68
- - **Exclusion of common phrases** from title capitalization
69
-
70
- ## Features
71
-
72
- - **Multiple Style Support**: AP, APA, Chicago, NYT, Wikipedia, and British title case styles
73
- - **Special Case Handling**: Hyphens, apostrophes, Roman numerals, acronyms, and more
74
- - **Word Replacement**: Replace specific words with their correct forms
75
- - **Exact Phrase Replacement**: Replace exact phrases with their correct forms
76
- - **Smart Quotes**: Optional conversion to smart quotes
77
- - **Extensive Term Lists**: Includes extensive lists of correctly cased terms
78
- - **Customizable Options**: Customize word lists, replacements, and other options
79
-
80
- ## Installation
11
+ ---
81
12
 
82
- ```bash
83
- npm install @danielhaim/titlecaser
84
- ```
85
-
86
- ## Usage
13
+ ## Links
87
14
 
88
- The package can be imported and used in both Node.js and browser environments:
15
+ - [Demo](https://danielhaim1.github.io/TitleCaser/)
16
+ - [CodePen Demo 1](https://codepen.io/danielhaim/pen/oNQgjBv)
17
+ - [CodePen Demo 2](https://codepen.io/danielhaim/pen/oNPGzKw)
18
+ - [Contributing](CONTRIBUTING.md)
19
+ - [Changelog](CHANGELOG.md)
89
20
 
90
- ```javascript
91
- import { TitleCaser } from '@danielhaim/titlecaser';
92
-
93
- // Basic usage with Chicago style
94
- const titleCaser = new TitleCaser({
95
- style: 'chicago'
96
- });
97
- const result = titleCaser.toTitleCase('the book of life');
98
- console.log(result); // "The Book of Life"
21
+ ---
99
22
 
100
- // With custom options
101
- const customTitleCaser = new TitleCaser({
102
- style: 'ap',
103
- smartQuotes: true,
104
- ignoredWords: ['a', 'an', 'the'],
105
- acronyms: ['API', 'JSON', 'XML']
106
- });
23
+ ## Introduction
107
24
 
108
- const customResult = customTitleCaser.toTitleCase('the api and json data');
109
- console.log(customResult); // "The API and JSON Data"
25
+ TitleCaser is a deterministic, style-guide–aware title casing engine built for production publishing systems. It implements major editorial standards with rule-driven capitalization logic, including acronym disambiguation, hyphenated compounds, possessives, punctuation sensitivity, and curated domain-specific term normalization across finance, marketing, academia, military, and technology.
110
26
 
111
- // Add custom word replacements
112
- titleCaser.addReplaceTerm('js', 'JavaScript');
113
- const jsResult = titleCaser.toTitleCase('js development');
114
- console.log(jsResult); // "JavaScript Development"
27
+ Its multi-pass processing architecture ensures consistent output while supporting custom word overrides, exact phrase preservation, brand enforcement, and controlled vocabulary rules. Designed for both Node.js and browser environments, TitleCaser integrates cleanly into CMS pipelines, build systems, and automated content workflows where precision and repeatability are required.
115
28
 
116
- // Add exact phrase replacements
117
- titleCaser.addExactPhraseReplacements([
118
- { 'the correct phrase': 'The Correct Phrase' }
119
- ]);
120
- const phraseResult = titleCaser.toTitleCase('this is the correct phrase');
121
- console.log(phraseResult); // "This Is The Correct Phrase"
122
- ```
29
+ ---
123
30
 
124
- ## Usage in the Browser
31
+ ## Key Features
125
32
 
126
- The function can also be used in a browser environment by including the `TitleCaser.amd.js` script in your HTML file:
33
+ ### Multi-Style Editorial Engine
34
+ Built-in rule systems for **AP**, **APA**, **Chicago**, **NYT**, **Wikipedia** (sentence case), and **British** styles. Each style applies its own logic for minor words, hyphenated compounds, possessives, colon capitalization, and acronym handling, producing deterministic and repeatable output.
127
35
 
128
- ```html
129
- <script src="./path/to/TitleCaser.amd.js"></script>
130
- ```
36
+ ### Contextual Acronym & Pronoun Disambiguation
37
+ Distinguishes regional acronyms from identical lowercase words using positional and surrounding-word heuristics.
131
38
 
132
- After that, the `toTitleCase()` function can be accessed in your JavaScript code like this:
39
+ For example:
133
40
 
134
41
  ```javascript
135
- const options = {
136
- style: 'apa'
137
- };
138
- const input = 'the future of devops: the next era';
139
- const output = input.toTitleCase(options);
42
+ "It’s up to us in the US military to decide."
43
+ "It’s Up to Us in the US Military to Decide."
140
44
 
141
- console.log(output); // The Future of DevOps: The Next Era
45
+ "us-uk-led coalition"
46
+ → "US-UK-Led Coalition"
142
47
  ```
143
48
 
144
- ### Example with HTML Elements
145
-
146
- ```html
147
- <h2>nodejs development on aws: an in-depth tutorial on server-side javascript deployment</h2>
148
- <h2>the iphone's impact on modern communication: a sociolinguistic analysis</h2>
149
- <h2>back-end and front-end</h2>
150
- ```
49
+ - Supports US, UK, EU, USA (dotted and undotted forms)
50
+ - Handles hyphenated compounds (US-Backed, US-UK-Led)
51
+ - Works in parenthetical and comma-separated contexts
52
+ - Detects end-of-sentence acronyms
53
+ - Avoids false positives inside longer words
151
54
 
152
- ```javascript
153
- function applyTitleCaseToH2Elements(options = { style: "apa" }) {
154
- try {
155
- const h2Elements = document.querySelectorAll("h2");
156
- h2Elements.forEach((h2) => {
157
- const innerHTML = h2.innerHTML;
158
- const modifiedContent = innerHTML.toTitleCase(options);
159
- h2.innerHTML = modifiedContent;
160
- });
161
- } catch (error) {
162
- console.error(
163
- "An error occurred while applying title case transformation:",
164
- error
165
- );
166
- }
167
- }
55
+ ### Structured Vocabulary Normalization
56
+ Includes **1,000+ curated terms** across brands, technology, geography, business, marketing, defense, academia, finance, and legal domains.
168
57
 
169
- applyTitleCaseToH2Elements();
170
- ```
58
+ - Mixed-case normalization (`GOOGle → Google`)
59
+ - Intentional lowercase brands (`iPhone`, `eBay`)
60
+ - Roman numerals (`Louis-IV`)
61
+ - Unicode names (`Škoda`)
62
+ - Possessive handling (`GOOGle's tensorflow → Google's TensorFlow`)
63
+ - Runtime custom term overrides
64
+ - Exact phrase replacements
171
65
 
172
- ## Options
66
+ ### Advanced Hyphenation & Compound Handling
67
+ Intelligent processing of hyphenated compounds with style-specific rules:
173
68
 
174
- The `{options}` parameter is an object that contains the settings for the conversion process.
69
+ - Multi-hyphen compounds (`US-UK-Led Coalition`)
70
+ - Style-specific compound rules (AP vs Chicago)
71
+ - En dash and em dash normalization
72
+ - Acronym-first compound logic
73
+ - Roman numerals inside compounds
74
+ - Brand casing preservation inside compounds
175
75
 
176
- - `style`: determines the specific title case style to be applied. Permissible values include: `['ap', 'apa', 'british', 'chicago', 'nyt', 'wikipedia']`
177
- - `articlesList` refers to the words that should be treated as articles in title case.
178
- - `shortConjunctionsList` pertains to the words that should be treated as short conjunctions in title case.
179
- - `shortPrepositionsList` relates to the words that should be treated as short prepositions in title case.
180
- - `neverCapitalizedList` contains the words that should never be capitalized in title case.
181
- - `wordReplacementsList` is a map of terms that will be replaced during the title case conversion process.
182
- - `smartQuotes` boolean value that determines whether quotes should be replaced with smart quotes.
76
+ ### Multi-Pass Deterministic Processing
77
+ Layered multi-pass processing for stable handling of complex inputs:
183
78
 
184
- ## Methods
79
+ - Input normalization (spacing and `<br>` handling)
80
+ - Style-aware casing pass
81
+ - Acronym resolution pass
82
+ - Short-word correction pass
83
+ - Final contextual correction pass
84
+ - Optional smart quote conversion
85
+ - Exact phrase override pass
185
86
 
186
- - `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.
187
- - `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.
188
- - `addReplaceTerm(term, replacement)`: Adds a single term-replacement pair to the `wordReplacementsList`. If the term already exists, it updates the replacement value.
189
- - `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.
190
- - `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.
191
- - `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.
87
+ ### HTML-Safe & CMS-Ready
88
+ Designed for integration into publishing workflows, CMS pipelines, and automated content systems.
192
89
 
193
- ## Examples
90
+ - Preserves `<br>` tags
91
+ - Normalizes spacing around colon + `<br>`
92
+ - Retains ampersands and symbols
93
+ - Handles excessive whitespace safely
194
94
 
195
- ### Basic Usage
95
+ ### Runtime & Build Support
96
+ The AMD/browser build extends `String.prototype.toTitleCase()` for direct string usage in client environments.
196
97
 
197
- ```javascript
198
- import { TitleCaser } from '@danielhaim/titlecaser';
98
+ - Node.js (ES modules)
99
+ - Browser (prototype extension via AMD build)
100
+ - AMD distribution build
101
+ - CLI build and test scripts
199
102
 
200
- const titleCaser = new TitleCaser();
201
- const result = titleCaser.toTitleCase('hello world');
202
- console.log(result); // "Hello World"
203
- ```
103
+ ---
204
104
 
205
- ### Customizing Word Replacements Method
105
+ ## Quick Start
206
106
 
207
- In the example below, we create a new instance of the `TitleCaser` class with the `APA` style option. We then set multiple replacement terms using two separate calls to the `setReplaceTerms()` method. Descriptive variable names are used for the input string and expected output. We call `toTitleCase()` to convert the input string to a title case.
208
-
209
- ```javascript
210
- import { TitleCaser } from '@danielhaim/titlecaser';
211
-
212
- const titleCaser = new TitleCaser({
213
- style: 'apa'
214
- });
215
-
216
- // Set multiple replacement terms using two separate calls to setReplaceTerms()
217
- titleCaser.setReplaceTerms({
218
- 'hello world': 'Hello World',
219
- 'replace me': 'Replace Me'
220
- });
221
- titleCaser.setReplaceTerms({
222
- 'apa': 'APA'
223
- });
224
-
225
- // Use descriptive variable names for the input and expected output
226
- const inputString = "hello world, replace me!";
227
- const expectedOutput = "Hello World, Replace Me!";
228
-
229
- // Call toTitleCase() to convert the input string to title case
230
- const outputString = titleCaser.toTitleCase(inputString);
107
+ ```bash
108
+ npm install @danielhaim/titlecaser
231
109
  ```
232
110
 
233
- ### Customizing TitleCaser
234
-
235
- The example below demonstrates how to use the TitleCaser class to convert a string to a title case with specific settings.
236
-
237
111
  ```javascript
238
112
  import { TitleCaser } from '@danielhaim/titlecaser';
239
113
 
240
- // Set the options object
241
- const options = {
242
- style: "nyt",
243
- wordReplacementsList: {
244
- "nodejs": "Node.js",
245
- "javascript": "JavaScript",
246
- "mongodb": "MongoDB"
247
- }
248
- };
249
-
250
- // Instantiate a new TitleCaser object with the options
251
- const titleCaser = new TitleCaser(options);
252
-
253
- // Set the input string to be tested
254
- const input = "the basics of nodejs development with mongodb";
255
-
256
- // Set the expected output
257
- const expectedOutput = "The Basics of Node.js Development with MongoDB";
114
+ const titleCaser = new TitleCaser({ style: 'ap' });
258
115
 
259
- // Call the toTitleCase method and store the result in actualOutput
260
- const actualOutput = titleCaser.toTitleCase(input);
116
+ titleCaser.toTitleCase('the quick brown fox'); // "The Quick Brown Fox"
117
+ titleCaser.toTitleCase('nodejs development on aws'); // → "Node.js Development on AWS"
118
+ titleCaser.toTitleCase('let us know about the us military'); // → "Let Us Know About the US Military"
261
119
  ```
262
120
 
263
- ### TitleCaser with Default Word Replacement
121
+ ## Core Usage
264
122
 
265
- The example below demonstrates how to use the TitleCaser class to convert a string to a title case with AP style formatting, including hyphenated words and word/brand replacement.
123
+ ### Editorial-Grade Transformation (AP Example)
124
+ Handles brand normalization, acronyms, hyphenation, possessives, and colon rules:
266
125
 
267
126
  ```javascript
268
127
  import { TitleCaser } from '@danielhaim/titlecaser';
269
128
 
270
- // Instantiate a new TitleCaser object with AP style formatting
271
129
  const titleCaser = new TitleCaser({ style: 'ap' });
272
130
 
273
- // Set the input string to be tested
274
- const input = 'nodejs development on aws: an in-depth tutorial on server-side javascript deployment';
275
-
276
- // Set the expected output
277
- const expectedOutput = 'Node.js Development on AWS: An In-depth Tutorial on Server-side JavaScript Deployment';
278
-
279
- // Call the toTitleCase method and store the result in actualOutput
280
- const actualOutput = titleCaser.toTitleCase(input);
131
+ titleCaser.toTitleCase(
132
+ "nodejs development on aws: an in-depth tutorial on server-side javascript deployment"
133
+ ); // → "Node.js Development on AWS: An In-depth Tutorial on Server-side JavaScript Deployment"
281
134
  ```
282
135
 
283
- ### TitleCaser with Possessive Noun and a Colon
284
-
285
- The example below demonstrates how to use the TitleCaser class to convert a string to title case with AP style formatting, including a possessive noun and a colon.
286
-
136
+ ### Custom Term Normalization
287
137
  ```javascript
288
- import { TitleCaser } from '@danielhaim/titlecaser';
289
-
290
- // Instantiate a new TitleCaser object with AP style formatting
291
- const titleCaser = new TitleCaser({ style: "ap" });
292
-
293
- // Set the input string to be tested
294
- const input = "the iphone's impact on modern communication: a sociolinguistic analysis";
295
-
296
- // Set the expected output
297
- const expectedOutput = "The iPhone's Impact on Modern Communication: A Sociolinguistic Analysis";
298
-
299
- // Call the toTitleCase method and store the result in actualOutput
300
- const actualOutput = titleCaser.toTitleCase(input);
138
+ titleCaser.addReplaceTerm('js', 'JavaScript');
139
+ titleCaser.toTitleCase('js development'); // → "JavaScript Development"
301
140
  ```
302
141
 
303
- ### TitleCaser with Smart Quotes
142
+ ### Exact Phrase Replacement
143
+ ```javascript
144
+ titleCaser.addExactPhraseReplacements([
145
+ { 'the correct phrase': 'The Correct Phrase' }
146
+ ]);
304
147
 
305
- The example below demonstrates how to use the TitleCaser with smart quotes.
148
+ titleCaser.toTitleCase('this is the correct phrase'); // "This Is The Correct Phrase"
149
+ ```
306
150
 
151
+ ### Smart Quotes
307
152
  ```javascript
308
- import { TitleCaser } from '@danielhaim/titlecaser';
309
-
310
- // Instantiate a new TitleCaser object with AP style formatting and smart quotes enabled
311
- const titleCaser = new TitleCaser({
153
+ const tc = new TitleCaser({
312
154
  style: 'ap',
313
155
  smartQuotes: true
314
156
  });
315
157
 
316
- // Set the input string to be tested
317
- const input = '"Never underestimate the power O\' persistence,"';
318
-
319
- // Set the expected output
320
- const expectedOutput = '"Never Underestimate the Power O' Persistence,"';
158
+ tc.toTitleCase('"never underestimate the power o\' persistence,"'); // → “Never Underestimate the Power O’ Persistence,”
159
+ ```
321
160
 
322
- // Call the toTitleCase method and store the result in actualOutput
323
- const actualOutput = titleCaser.toTitleCase(input);
161
+ ### Browser Usage
162
+ ```html
163
+ <script src="./path/to/TitleCaser.amd.js"></script>
324
164
  ```
325
165
 
326
- ## Architecture
166
+ ```javascript
167
+ const output = "the future of devops: the next era"
168
+ .toTitleCase({ style: 'apa' });
327
169
 
328
- TitleCaser is structured into three main components:
170
+ console.log(output); // "The Future of DevOps: The Next Era"
171
+ ```
329
172
 
330
- 1. **TitleCaser.js** - The main class that provides the public API
331
- 2. **TitleCaserConsts.js** - Contains constants, configuration, and data structures
332
- 3. **TitleCaserUtils.js** - Contains utility functions for text processing
173
+ ### Real-World DOM Example
174
+ Automatically normalize editorial headings in a publishing workflow:
175
+
176
+ ```html
177
+ <h2>nodejs development on aws: an in-depth tutorial on server-side javascript deployment</h2>
178
+ <h2>the iphone's impact on modern communication: a sociolinguistic analysis</h2>
179
+ <h2>back-end and front-end</h2>
180
+ ```
181
+ ```javascript
182
+ function applyTitleCaseToH2Elements(options = { style: "apa" }) {
183
+ const h2Elements = document.querySelectorAll("h2");
333
184
 
334
- ### Data Structure
185
+ h2Elements.forEach((h2) => {
186
+ h2.innerHTML = h2.innerHTML.toTitleCase(options);
187
+ });
188
+ }
335
189
 
336
- The package uses several JSON files to store specialized terms:
190
+ applyTitleCaseToH2Elements();
191
+ ```
337
192
 
338
- - **brandList.json**: Brand names and trademarks
339
- - **businessFinanceLegalTerms.json**: Business and legal terminology
340
- - **eCommerceDigitalTerms.json**: E-commerce and digital terms
341
- - **globalGeography.json**: Geographic terms
342
- - **marketingMediaTerms.json**: Marketing and media terms
343
- - **miscSpecializedTerms.json**: Miscellaneous specialized terms
344
- - **techComputingConcepts.json**: Technology and computing terms
345
- - **timeAcademicTerms.json**: Time and academic terms
193
+ ---
346
194
 
347
195
  ## API Reference
348
-
349
196
  ### Constructor
350
-
351
197
  ```javascript
352
198
  new TitleCaser(options)
353
199
  ```
354
200
 
355
- #### Options
201
+ ### Options
202
+
203
+ | Option | Type | Default | Description |
204
+ |------------------------|------------|---------|-------------|
205
+ | `style` | string | `'ap'` | Editorial style: `'ap' \| 'apa' \| 'chicago' \| 'nyt' \| 'wikipedia' \| 'british'` |
206
+ | `smartQuotes` | boolean | `false` | Converts straight quotes (`' "`) to typographic curly quotes |
207
+ | `neverCapitalize` | string[] | `[]` | Additional words that should remain lowercase (merged with style defaults) |
208
+ | `wordReplacementsList` | object[] | internal defaults | Array of `{ 'term': 'replacement' }` objects used for term normalization |
209
+ | `debug` | boolean | `false` | Enables internal warning logs during processing |
356
210
 
357
- - `style` (string): Title case style ('ap', 'apa', 'chicago', 'nyt', 'wikipedia', 'british')
358
- - `smartQuotes` (boolean): Convert straight quotes to curly quotes
359
- - `ignoredWords` (array): Words to ignore in title casing
360
- - `acronyms` (array): Words to treat as acronyms
211
+ ---
361
212
 
362
213
  ### Methods
363
214
 
364
215
  #### toTitleCase(text)
365
-
366
- Converts text to title case according to the selected style.
367
-
368
216
  ```javascript
369
- const result = titleCaser.toTitleCase('hello world');
370
- ```
371
-
372
- #### setReplaceTerms(replaceTerms)
373
-
374
- Sets the word replacement list.
375
-
376
- ```javascript
377
- titleCaser.setReplaceTerms([
378
- { 'js': 'JavaScript' },
379
- { 'api': 'API' }
380
- ]);
217
+ titleCaser.toTitleCase('hello world'); // → "Hello World"
381
218
  ```
382
219
 
383
220
  #### addReplaceTerm(term, replacement)
384
-
385
- Adds a single term replacement.
386
-
387
221
  ```javascript
388
222
  titleCaser.addReplaceTerm('js', 'JavaScript');
389
223
  ```
390
224
 
391
225
  #### removeReplaceTerm(term)
392
-
393
- Removes a term from the replacement list.
394
-
395
226
  ```javascript
396
227
  titleCaser.removeReplaceTerm('js');
397
228
  ```
398
229
 
399
- #### addExactPhraseReplacements(phrases)
400
-
401
- Adds exact phrase replacements.
230
+ #### setReplaceTerms(terms)
231
+ ```javascript
232
+ titleCaser.setReplaceTerms([
233
+ { 'js': 'JavaScript' },
234
+ { 'aws': 'AWS' }
235
+ ]);
236
+ ```
402
237
 
238
+ #### addExactPhraseReplacements(phrases)
403
239
  ```javascript
404
240
  titleCaser.addExactPhraseReplacements([
405
- { 'the correct phrase': 'The Correct Phrase' }
241
+ { 'the correct phrase': 'The Correct Phrase' },
242
+ { 'another phrase': 'Another Phrase' }
406
243
  ]);
407
244
  ```
408
245
 
409
246
  #### setStyle(style)
410
-
411
- Sets the title case style.
412
-
413
247
  ```javascript
414
248
  titleCaser.setStyle('chicago');
415
- ```
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Architecture
254
+ TitleCaser is structured into three main components:
255
+
256
+ - `TitleCaser.js` — Public API
257
+ - `TitleCaserConsts.js` — Style rules and data sets
258
+ - `TitleCaserUtils.js` — Processing and normalization engine
259
+
260
+ ## Data Sets
261
+ Curated structured term libraries power normalization:
262
+
263
+ - Brand and trademarks
264
+ - Business, finance, and legal terminology
265
+ - E-commerce and digital terms
266
+ - Global geography
267
+ - Marketing and media terms
268
+ - Defense and geopolitical terminology
269
+ - Technology and computing concepts
270
+ - Academic and temporal terminology
271
+
272
+ ---
416
273
 
417
274
  ## Build Process
418
275
 
@@ -423,23 +280,29 @@ npm run copy-package-to-docs
423
280
  npm run test
424
281
  ```
425
282
 
426
- ## Test
283
+ ## Test Coverage
427
284
 
428
285
  ```bash
429
286
  npm run test
430
287
  ```
431
288
 
289
+ - Extensive unit test coverage
290
+ - Cross-style validation (AP, Chicago, APA, NYT, Wikipedia)
291
+ - Acronym disambiguation edge cases
292
+ - Hyphenation edge cases
293
+ - Brand normalization
294
+
432
295
  ## Resources
433
296
 
434
297
  Useful materials for improving your knowledge of writing and language style guides. These resources include various books and manuals, such as the Publication Manual of the American Psychological Association, the Chicago Manual of Style, and the AP Stylebook, which are widely recognized as authoritative sources on grammar, punctuation, and capitalization rules.
435
298
 
436
299
  - [AP Stylebook, 56th Edition](https://store.stylebooks.com/ap-stylebook-56th-edition-print.html)
437
300
  - [Publication Manual of the American Psychological Association, Seventh Edition (2020)](https://apastyle.apa.org/products/publication-manual-7th-edition)
438
- - [Chicago Manual of Style: Capitalization](https://chat.openai.com/chat/643828ec-d4b5-4f21-b035-62946dd2cec3#:~:text=Chicago%20Manual%20of%20Style%3A%20Capitalization)
301
+ - [Chicago Manual of Style: Capitalization](https://www.chicagomanualofstyle.org/book/ed17/part2/ch08/psec022.html)
439
302
  - [The Bluebook: A Uniform System of Citation. 21st ed. Cambridge: Harvard Law Review Association, 2020](https://open.mitchellhamline.edu/cgi/viewcontent.cgi?article=2782&context=wmlr)
440
303
  - [The Chicago Manual of Style, 17th Edition](https://press.uchicago.edu/ucp/books/book/chicago/C/bo25956703.html)
441
304
  - [The New York Times Manual of Style and Usage](https://www.worldcat.org/title/946964415)
442
- - [Wikipedia: Letter case](https://chat.openai.com/chat/643828ec-d4b5-4f21-b035-62946dd2cec3#:~:text=Wikipedia%3A%20Letter%20case)
305
+ - [Wikipedia: Letter case](https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Capital_letters)
443
306
  - [Wikipedia:Manual of Style/Titles of works](https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Titles_of_works#Capital_letters)
444
307
 
445
308
  ## Report Bugs
@@ -459,99 +322,3 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS
459
322
  ## Changelog
460
323
 
461
324
  See [CHANGELOG.md](CHANGELOG.md) for a list of changes and version history.
462
-
463
- ## Tests
464
-
465
- ```bash
466
- TitleCaser – Combined Words Ending with Symbol
467
- ✓ should preserve punctuation in "Championing Self-Acceptance: Landmark Initiative" (4 ms)
468
- TitleCaser – Disambiguation of Acronym vs. Pronoun (AP Style)
469
- ✓ should capitalize "US" when preceded by "the" (1 ms)
470
- ✓ should capitalize "US" in geopolitical context (with comma) (1 ms)
471
- ✓ should capitalize "US" and "UK" together
472
- ✓ should capitalize "US" after "from the" (1 ms)
473
- ✓ should capitalize "US" after "via" (1 ms)
474
- ✓ should capitalize "US" before "Military"
475
- ✓ should capitalize "US" in geopolitical context (repeated case) (1 ms)
476
- ✓ should capitalize pronoun "us" (case #1) (1 ms)
477
- ✓ should capitalize pronoun "us" (case #2)
478
- ✓ should capitalize pronoun "us" (case #3) (1 ms)
479
- ✓ should capitalize "UK" in geopolitical context (with comma)
480
- ✓ should handle multiple country codes in same sentence (1 ms)
481
- ✓ should capitalize pronoun "us" in a parenthetical phrase (1 ms)
482
- ✓ should capitalize "USA" in formal context
483
- ✓ should capitalize "US" before "government" (AP style) (1 ms)
484
- ✓ should capitalize "US" before "military" (AP style)
485
- ✓ should capitalize "US" in geopolitical context (policy mention)
486
- ✓ should capitalize "US" before "Military" (repeat case) (1 ms)
487
- ✓ should capitalize "US" at the end of a sentence
488
- ✓ should capitalize pronoun "us" in casual speech
489
- ✓ should capitalize pronoun "us" in emotional context (1 ms)
490
- ✓ should capitalize pronoun "us" in passive voice
491
- ✓ should capitalize pronoun "us" with a compound verb
492
- ✓ should capitalize pronoun "us" in an inverted clause (1 ms)
493
- ✓ should capitalize pronoun "us" (repeat case #1)
494
- ✓ should capitalize pronoun "us" (repeat case #2) (1 ms)
495
- ✓ should capitalize pronoun "us" before "US Military"
496
- ✓ should capitalize pronoun "us" before "military" (1 ms)
497
- ✓ should capitalize pronoun "us" in a comma-separated clause
498
- ✓ should capitalize "UK" at end of sentence (1 ms)
499
- ✓ should capitalize "UK" in geopolitical context (repeat with comma)
500
- ✓ should capitalize "UK" before government mention (1 ms)
501
- ✓ should capitalize "UK" before territory mention
502
- ✓ should handle multiple country codes and pronouns in one sentence (2 ms)
503
- ✓ should handle multiple codes and pronouns with mention of military
504
- ✓ should handle multiple codes and pronouns with mention of talks (1 ms)
505
- ✓ should handle multiple codes and pronouns with mention of a bill (1 ms)
506
- ✓ should capitalize "USA" in formal context (repeat case)
507
- ✓ should capitalize "USA" before a bill mention (1 ms)
508
- ✓ should handle AP-style acronym "U.S." in uppercase context
509
- ✓ should handle "On & Off" phrases #1 (1 ms)
510
- ✓ should handle "On & Off" phrases #2
511
- TitleCaser – Hyphenated & Apostrophized Words
512
- ✓ should capitalize both parts of "t-mobile"
513
- ✓ should capitalize "coca-cola"
514
- ✓ should capitalize general hyphenated term "e-commerce" (1 ms)
515
- ✓ should capitalize apostrophe word "o'connor"
516
- TitleCaser – Basic Title Casing Options (Default Style)
517
- ✓ should convert a basic lowercase phrase to title case
518
- ✓ should handle excessive spacing and lowercase articles
519
- ✓ should handle brand casing with AP-style logic (1 ms)
520
- ✓ should preserve correct casing in hyphenated names like "louis-iv"
521
- ✓ should properly capitalize prepositions beyond 3 letters (1 ms)
522
- TitleCaser – Class Methods (setReplaceTerms, addExactPhraseReplacements, etc.)
523
- ✓ should apply Wikipedia style to an entire sentence (1 ms)
524
- ✓ should apply multiple term replacements via setReplaceTerms()
525
- ✓ should apply exact phrase replacements (1 ms)
526
- ✓ should remove a single replacement rule via removeReplaceTerm()
527
- TitleCaser – Variation Stability Tests (AP, Chicago, APA, NYT, Wikipedia)
528
- ✓ should correctly handle brand names with "ap" style
529
- ✓ should handle brand name "NERDs Candy" with AP style
530
- ✓ should handle possessives and colons (AP style)
531
- ✓ should handle hyphenated "BACK-end" with AP style
532
- ✓ should handle acronym with colon (AP style) (1 ms)
533
- ✓ should handle colon + comparison phrase (Chicago)
534
- ✓ should capitalize hyphenated terms (Chicago) (1 ms)
535
- ✓ should apply custom replacements for brand names (Chicago) (1 ms)
536
- ✓ Smart quotes enabled
537
- ✓ should keep acronyms in uppercase (Chicago)
538
- ✓ should capitalize after colon (APA) (1 ms)
539
- ✓ should handle colon and apostrophes (APA)
540
- ✓ should handle short conjunctions and brand normalization (APA) (1 ms)
541
- ✓ should handle acronym + colon usage (NYT) (1 ms)
542
- ✓ should preserve sentence case for Wikipedia style (DevOps example) (1 ms)
543
- ✓ should handle Wikipedia style with colon usage (1 ms)
544
- TitleCaser – Reserved Words & Special Handling
545
- ✓ should transform a single reserved word correctly
546
- ✓ should transform sentence with reserved word + colon
547
- ✓ should handle possessive form of reserved word
548
- ✓ should apply brand replacements (e.g., "mcdonalds" → "McDonald's") (1 ms)
549
- ✓ should handle HTML <br> with colon (spaced)
550
- ✓ should handle HTML <br> with full sentence split (1 ms)
551
- ✓ should handle <br> with no space after colon
552
- ✓ should handle ampersand "&" symbol (1 ms)
553
- ✓ should handle excessive whitespace
554
- TitleCaser – addReplaceTerm Method
555
- ✓ should add a new replacement term
556
- ✓ should update an existing replacement term
557
- ```