@danielhaim/titlecaser 1.2.48 → 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.
Files changed (2) hide show
  1. package/README.md +32 -5
  2. package/package.json +1 -1
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" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielhaim/titlecaser",
3
- "version": "1.2.48",
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",