@danielhaim/titlecaser 1.2.47 → 1.2.49

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
@@ -65,7 +65,7 @@ $ npm i @danielhaim/titlecaser
65
65
  The package can be imported and used in both Node.js and browser environments using the following syntax:
66
66
 
67
67
  ```js
68
- import { TitleCaser } from './path/to/@danielhaim/titlecaser';
68
+ import "./path/to/@danielhaim/titlecaser";
69
69
 
70
70
  const options = {
71
71
  style: 'chicago'
@@ -101,6 +101,33 @@ const output = input.toTitleCase(options);
101
101
  console.log(output); // The Future of DevOps: The Next Era
102
102
  ```
103
103
 
104
+ ### Example 2
105
+
106
+ ```html
107
+ <h2>nodejs development on aws: an in-depth tutorial on server-side javascript deployment</h2>
108
+ <h2>the iphone's impact on modern communication: a sociolinguistic analysis</h2>
109
+ <h2>back-end and front-end</h2>
110
+ ```
111
+
112
+ ```js
113
+ function applyTitleCaseToH2Elements(options = { style: "apa" }) {
114
+ try {
115
+ const h2Elements = document.querySelectorAll("h2");
116
+ h2Elements.forEach((h2) => {
117
+ const innerHTML = h2.innerHTML;
118
+ const modifiedContent = innerHTML.toTitleCase(options);
119
+ h2.innerHTML = modifiedContent;
120
+ });
121
+ } catch (error) {
122
+ console.error(
123
+ "An error occurred while applying title case transformation:",
124
+ error
125
+ );
126
+ }
127
+ }
128
+
129
+ applyTitleCaseToH2Elements();
130
+ ```
104
131
  ## Options
105
132
 
106
133
  The `{options}` parameter is an object that contains the settings for the conversion process.
@@ -128,7 +155,7 @@ The example below demonstrates how to use the TitleCaser class to convert a stri
128
155
  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.
129
156
 
130
157
  ```js
131
- import { TitleCaser } from './path/to/@danielhaim/titlecaser';
158
+ import "./path/to/@danielhaim/titlecaser";
132
159
 
133
160
  const titleCaser = new TitleCaser({
134
161
  style: 'apa'
@@ -156,7 +183,7 @@ const outputString = titleCaser.toTitleCase(inputString);
156
183
  The example below demonstrates how to use the TitleCaser class to convert a string to a title case with specific settings.
157
184
 
158
185
  ```js
159
- import { TitleCaser } from './path/to/@danielhaim/titlecaser';
186
+ import "./path/to/@danielhaim/titlecaser";
160
187
 
161
188
  // Set the options object
162
189
  const options = {
@@ -186,7 +213,7 @@ const actualOutput = titleCaser.toTitleCase(input);
186
213
  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.
187
214
 
188
215
  ```js
189
- import { TitleCaser } from './path/to/@danielhaim/titlecaser';
216
+ import "./path/to/@danielhaim/titlecaser";
190
217
 
191
218
  // Instantiate a new TitleCaser object with AP style formatting
192
219
  const titleCaser = new TitleCaser({ style: 'ap' });
@@ -206,7 +233,7 @@ const actualOutput = titleCaser.toTitleCase(input);
206
233
  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.
207
234
 
208
235
  ```js
209
- import { TitleCaser } from './path/to/@danielhaim/titlecaser';
236
+ import "./path/to/@danielhaim/titlecaser";
210
237
 
211
238
  // Instantiate a new TitleCaser object with AP style formatting
212
239
  const titleCaser = new TitleCaser({ style: "ap" });
@@ -236,43 +263,45 @@ $ npm run test
236
263
  $ npm run test
237
264
  ```
238
265
 
239
- ```bash
266
+ ```bash
240
267
  Test Basic Options
241
- ✓ Default title case conversion (2 ms)
242
- ✓ Customized title case conversion (1 ms)
243
- ✓ AP-style title case conversion with replacements (1 ms)
268
+ ✓ Default title case conversion
269
+ ✓ Customized title case conversion
244
270
  ✓ AP-style title case conversion with replacements
245
- Capitalize suffix word in sentence (1 ms)
271
+ AP-style title case conversion with replacements
272
+ ✓ Capitalize suffix word in sentence
246
273
 
247
274
  Test Methods
248
275
  ✓ removeReplaceTerm
249
276
  ✓ setReplaceTerms
250
277
 
251
278
  Test Variation Stability
252
- ✓ Hyphenated, colon, and short word replacements (1 ms)
279
+ ✓ Hyphenated, colon, and short word replacements
253
280
  ✓ Capitalization and word replacements
254
281
  ✓ AP-style title case with possessive and colon
255
282
  ✓ AP-style title case with lowercase back/front-end terms
256
283
  ✓ Chicago style title case with comparison and colon
257
- ✓ APA style title case with colon (3 ms)
258
- ✓ Wikipedia style title case with acronym and hyphen (1 ms)
284
+ ✓ APA style title case with colon
285
+ ✓ Wikipedia style title case with acronym and hyphen
259
286
  ✓ APA style title case with colon and apostrophe
260
287
  ✓ Chicago style title case with custom term replacements
261
- ✓ AP-style capitalization test with special terms and colon (1 ms)
288
+ ✓ AP-style capitalization test with special terms and colon
262
289
  ✓ NYT-style capitalization test with special terms and colon
263
- ✓ APA style capitalization test with short conjunction terms and colon (1 ms)
290
+ ✓ APA style capitalization test with short conjunction terms and colon
264
291
  ✓ Correct phrase casing list testing
265
- ✓ Wikipedia style capitalization test with special term and colon (1 ms)
292
+ ✓ Wikipedia style capitalization test with special term and colon
266
293
 
267
294
  Test Reserved Words
268
295
  ✓ Reserved word
269
296
  ✓ Reserved word with colon
270
297
  ✓ Reserved word, posessive
271
- ✓ Hyphenated reserved word (1 ms)
298
+ ✓ Hyphenated reserved word
272
299
  ✓ Hyphenated reserved word, possessive
273
300
  ✓ HTML line break nl2br, <br /> tag
301
+ ✓ HTML line break nl2br, <br /> tag
302
+ ✓ HTML line break nl2br, <br /> tag
274
303
  ✓ Ampersand in a sentence should return & and not &Amp;
275
- ✓ Untrimmed white spaces (1 ms)
304
+ ✓ Untrimmed white spaces
276
305
  ```
277
306
 
278
307
  ## Resources
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielhaim/titlecaser",
3
- "version": "1.2.47",
3
+ "version": "1.2.49",
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",
@@ -51,11 +51,13 @@
51
51
  "tree": "tree -I 'node_modules'"
52
52
  },
53
53
  "devDependencies": {
54
- "@babel/cli": "^7.21.0",
55
- "@babel/core": "^7.21.4",
56
- "@babel/plugin-transform-modules-commonjs": "^7.21.2",
57
- "@babel/preset-env": "^7.21.4",
58
- "@babel/runtime-corejs3": "^7.21.0",
54
+ "@babel/cli": "^7.21.5",
55
+ "@babel/core": "^7.22.1",
56
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
57
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
58
+ "@babel/plugin-transform-modules-commonjs": "^7.21.5",
59
+ "@babel/preset-env": "^7.22.4",
60
+ "@babel/runtime-corejs3": "^7.22.3",
59
61
  "@jest/expect": "^29.5.0",
60
62
  "babel-jest": "^29.5.0",
61
63
  "babel-loader": "^9.1.2",
@@ -63,13 +65,13 @@
63
65
  "exports-loader": "^4.0.0",
64
66
  "jest": "^29.5.0",
65
67
  "jest-environment-jsdom": "^29.5.0",
66
- "jest-environment-puppeteer": "^8.0.6",
67
- "jest-puppeteer": "^8.0.6",
68
- "puppeteer": "^19.8.5",
69
- "puppeteer-core": "^19.8.5",
70
- "terser-webpack-plugin": "^5.3.7",
71
- "webpack": "^5.78.0",
72
- "webpack-cli": "^5.0.1",
68
+ "jest-environment-puppeteer": "^9.0.0",
69
+ "jest-puppeteer": "^9.0.0",
70
+ "puppeteer": "^20.5.0",
71
+ "puppeteer-core": "^20.5.0",
72
+ "terser-webpack-plugin": "^5.3.9",
73
+ "webpack": "^5.86.0",
74
+ "webpack-cli": "^5.1.4",
73
75
  "webpack-node-externals": "^3.0.0"
74
76
  },
75
77
  "publishConfig": {
@@ -78,7 +78,7 @@ export const correctTitleCasingList = [
78
78
  'ProTools', 'QuickTime', 'AdWords', 'AdSense', 'TikTok', 'Slack', 'Trello',
79
79
  'Zoom', 'Twitch', 'Snapchat', 'WhatsApp', 'Telegram', 'Discord', 'Reddit',
80
80
  'Quora', 'StackOverflow', 'StackExchange', 'Coca-Cola',
81
- 'AWS', 'GCP', 'VMware', 'CVS', 'ESL', 'EE',
81
+ 'AWS', 'GCP', 'VMware', 'CVS', 'ESL', 'EE', 'CW', 'EE',
82
82
 
83
83
  // Sports
84
84
  'NBA', 'NCAA', 'NFL', 'WWE', 'WWF', 'FIFA',