@danielhaim/titlecaser 1.2.45 → 1.2.48
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 +27 -43
- package/index.js +11 -12
- package/package.json +16 -14
- package/src/TitleCaser.js +220 -216
- package/src/TitleCaserConsts.js +172 -172
- package/src/TitleCaserUtils.js +565 -564
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Transform any text to proper title case format using popular style guides such a
|
|
|
8
8
|
|
|
9
9
|
## Demo
|
|
10
10
|
|
|
11
|
-
<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"></a>
|
|
11
|
+
<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>
|
|
12
12
|
|
|
13
13
|
## Table of Contents
|
|
14
14
|
|
|
@@ -65,15 +65,11 @@ $ 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 '
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Here's an example of how to use the modulate function:
|
|
68
|
+
import { TitleCaser } from './path/to/@danielhaim/titlecaser';
|
|
72
69
|
|
|
73
|
-
```js
|
|
74
70
|
const options = {
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
style: 'chicago'
|
|
72
|
+
};
|
|
77
73
|
|
|
78
74
|
const titleCaser = new TitleCaser(options);
|
|
79
75
|
|
|
@@ -127,24 +123,13 @@ The `{options}` parameter is an object that contains the settings for the conver
|
|
|
127
123
|
|
|
128
124
|
The example below demonstrates how to use the TitleCaser class to convert a string to title case with custom options.
|
|
129
125
|
|
|
130
|
-
### Basic Usage
|
|
131
|
-
|
|
132
|
-
```js
|
|
133
|
-
// Instantiate a new TitleCaser object with the options
|
|
134
|
-
const titleCaser = new TitleCaser();
|
|
135
|
-
|
|
136
|
-
const input = 'the Book of lIfe';
|
|
137
|
-
const output = titleCaser.toTitleCase(input);
|
|
138
|
-
|
|
139
|
-
console.log(output); // The Book of Life
|
|
140
|
-
```
|
|
141
|
-
|
|
142
126
|
### Customizing Word Replacements Method
|
|
143
127
|
|
|
144
128
|
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.
|
|
145
129
|
|
|
146
130
|
```js
|
|
147
|
-
|
|
131
|
+
import { TitleCaser } from './path/to/@danielhaim/titlecaser';
|
|
132
|
+
|
|
148
133
|
const titleCaser = new TitleCaser({
|
|
149
134
|
style: 'apa'
|
|
150
135
|
});
|
|
@@ -171,6 +156,8 @@ const outputString = titleCaser.toTitleCase(inputString);
|
|
|
171
156
|
The example below demonstrates how to use the TitleCaser class to convert a string to a title case with specific settings.
|
|
172
157
|
|
|
173
158
|
```js
|
|
159
|
+
import { TitleCaser } from './path/to/@danielhaim/titlecaser';
|
|
160
|
+
|
|
174
161
|
// Set the options object
|
|
175
162
|
const options = {
|
|
176
163
|
style: "nyt",
|
|
@@ -192,9 +179,6 @@ const expectedOutput = "The Basics of Node.js Development with MongoDB";
|
|
|
192
179
|
|
|
193
180
|
// Call the toTitleCase method and store the result in actualOutput
|
|
194
181
|
const actualOutput = titleCaser.toTitleCase(input);
|
|
195
|
-
|
|
196
|
-
// Log the actual output
|
|
197
|
-
console.log(actualOutput);
|
|
198
182
|
```
|
|
199
183
|
|
|
200
184
|
### TitleCaser With Default Word Replacement
|
|
@@ -202,6 +186,8 @@ console.log(actualOutput);
|
|
|
202
186
|
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.
|
|
203
187
|
|
|
204
188
|
```js
|
|
189
|
+
import { TitleCaser } from './path/to/@danielhaim/titlecaser';
|
|
190
|
+
|
|
205
191
|
// Instantiate a new TitleCaser object with AP style formatting
|
|
206
192
|
const titleCaser = new TitleCaser({ style: 'ap' });
|
|
207
193
|
|
|
@@ -213,9 +199,6 @@ const expectedOutput = 'Node.js Development on AWS: An In-depth Tutorial on Serv
|
|
|
213
199
|
|
|
214
200
|
// Call the toTitleCase method and store the result in actualOutput
|
|
215
201
|
const actualOutput = titleCaser.toTitleCase(input);
|
|
216
|
-
|
|
217
|
-
// Log the actual output
|
|
218
|
-
console.log(actualOutput);
|
|
219
202
|
```
|
|
220
203
|
|
|
221
204
|
### TitleCaser With Possessive Noun and a Colon
|
|
@@ -223,6 +206,8 @@ console.log(actualOutput);
|
|
|
223
206
|
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.
|
|
224
207
|
|
|
225
208
|
```js
|
|
209
|
+
import { TitleCaser } from './path/to/@danielhaim/titlecaser';
|
|
210
|
+
|
|
226
211
|
// Instantiate a new TitleCaser object with AP style formatting
|
|
227
212
|
const titleCaser = new TitleCaser({ style: "ap" });
|
|
228
213
|
|
|
@@ -234,9 +219,6 @@ const expectedOutput = "The iPhone's Impact on Modern Communication: A Socioling
|
|
|
234
219
|
|
|
235
220
|
// Call the toTitleCase method and store the result in actualOutput
|
|
236
221
|
const actualOutput = titleCaser.toTitleCase(input);
|
|
237
|
-
|
|
238
|
-
// Log the actual output
|
|
239
|
-
console.log(actualOutput);
|
|
240
222
|
```
|
|
241
223
|
|
|
242
224
|
## Build Process
|
|
@@ -254,43 +236,45 @@ $ npm run test
|
|
|
254
236
|
$ npm run test
|
|
255
237
|
```
|
|
256
238
|
|
|
257
|
-
```bash
|
|
239
|
+
```bash
|
|
258
240
|
Test Basic Options
|
|
259
|
-
✓ Default title case conversion
|
|
260
|
-
✓ Customized title case conversion
|
|
261
|
-
✓ AP-style title case conversion with replacements (1 ms)
|
|
241
|
+
✓ Default title case conversion
|
|
242
|
+
✓ Customized title case conversion
|
|
262
243
|
✓ AP-style title case conversion with replacements
|
|
263
|
-
✓
|
|
244
|
+
✓ AP-style title case conversion with replacements
|
|
245
|
+
✓ Capitalize suffix word in sentence
|
|
264
246
|
|
|
265
247
|
Test Methods
|
|
266
248
|
✓ removeReplaceTerm
|
|
267
249
|
✓ setReplaceTerms
|
|
268
250
|
|
|
269
251
|
Test Variation Stability
|
|
270
|
-
✓ Hyphenated, colon, and short word replacements
|
|
252
|
+
✓ Hyphenated, colon, and short word replacements
|
|
271
253
|
✓ Capitalization and word replacements
|
|
272
254
|
✓ AP-style title case with possessive and colon
|
|
273
255
|
✓ AP-style title case with lowercase back/front-end terms
|
|
274
256
|
✓ Chicago style title case with comparison and colon
|
|
275
|
-
✓ APA style title case with colon
|
|
276
|
-
✓ Wikipedia style title case with acronym and hyphen
|
|
257
|
+
✓ APA style title case with colon
|
|
258
|
+
✓ Wikipedia style title case with acronym and hyphen
|
|
277
259
|
✓ APA style title case with colon and apostrophe
|
|
278
260
|
✓ Chicago style title case with custom term replacements
|
|
279
|
-
✓ AP-style capitalization test with special terms and colon
|
|
261
|
+
✓ AP-style capitalization test with special terms and colon
|
|
280
262
|
✓ NYT-style capitalization test with special terms and colon
|
|
281
|
-
✓ APA style capitalization test with short conjunction terms and colon
|
|
263
|
+
✓ APA style capitalization test with short conjunction terms and colon
|
|
282
264
|
✓ Correct phrase casing list testing
|
|
283
|
-
✓ Wikipedia style capitalization test with special term and colon
|
|
265
|
+
✓ Wikipedia style capitalization test with special term and colon
|
|
284
266
|
|
|
285
267
|
Test Reserved Words
|
|
286
268
|
✓ Reserved word
|
|
287
269
|
✓ Reserved word with colon
|
|
288
270
|
✓ Reserved word, posessive
|
|
289
|
-
✓ Hyphenated reserved word
|
|
271
|
+
✓ Hyphenated reserved word
|
|
290
272
|
✓ Hyphenated reserved word, possessive
|
|
291
273
|
✓ HTML line break nl2br, <br /> tag
|
|
274
|
+
✓ HTML line break nl2br, <br /> tag
|
|
275
|
+
✓ HTML line break nl2br, <br /> tag
|
|
292
276
|
✓ Ampersand in a sentence should return & and not &Amp;
|
|
293
|
-
✓ Untrimmed white spaces
|
|
277
|
+
✓ Untrimmed white spaces
|
|
294
278
|
```
|
|
295
279
|
|
|
296
280
|
## Resources
|
package/index.js
CHANGED
|
@@ -6,20 +6,19 @@ import { TitleCaser } from './src/TitleCaser.js';
|
|
|
6
6
|
// Add a new method to the String prototype. This method will be available
|
|
7
7
|
// to all string objects. This is the method that will be used to convert
|
|
8
8
|
// a string to title case.
|
|
9
|
-
if (String.prototype.toTitleCase === undefined) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
if ( String.prototype.toTitleCase === undefined ) {
|
|
10
|
+
String.prototype.toTitleCase = function ( options ) {
|
|
11
|
+
const titleCaser = new TitleCaser ( options );
|
|
12
|
+
return titleCaser.toTitleCase ( this );
|
|
13
|
+
};
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// If the module is being used in a Node environment
|
|
17
|
-
if (typeof module === 'object' && module.exports) {
|
|
18
|
-
|
|
16
|
+
// If the module is being used in a Node environment
|
|
17
|
+
if ( typeof module === 'object' && module.exports ) {
|
|
18
|
+
module.exports = { TitleCaser };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// If the module is being used in a web environment
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
window.TitleCaser = TitleCaser;
|
|
21
|
+
// If the module is being used in a web environment
|
|
22
|
+
if ( typeof window !== 'undefined' && window.document ) {
|
|
23
|
+
window.TitleCaser = TitleCaser;
|
|
25
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielhaim/titlecaser",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.48",
|
|
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",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"name": "Daniel Haim",
|
|
35
35
|
"url": "https://github.com/danielhaim1"
|
|
36
36
|
},
|
|
37
|
-
"main": "./
|
|
37
|
+
"main": "./index.js",
|
|
38
38
|
"files": [
|
|
39
39
|
"LICENSE",
|
|
40
40
|
"README.md",
|
|
@@ -51,11 +51,13 @@
|
|
|
51
51
|
"tree": "tree -I 'node_modules'"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/cli": "^7.21.
|
|
55
|
-
"@babel/core": "^7.
|
|
56
|
-
"@babel/plugin-
|
|
57
|
-
"@babel/
|
|
58
|
-
"@babel/
|
|
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": "^
|
|
67
|
-
"jest-puppeteer": "^
|
|
68
|
-
"puppeteer": "^
|
|
69
|
-
"puppeteer-core": "^
|
|
70
|
-
"terser-webpack-plugin": "^5.3.
|
|
71
|
-
"webpack": "^5.
|
|
72
|
-
"webpack-cli": "^5.
|
|
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": {
|