Skip to content

Commit

Permalink
feat: title case following The Chicago Manual of Style
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Dec 15, 2023
1 parent fac29ed commit 7d33c91
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 10 deletions.
8 changes: 2 additions & 6 deletions lib/utils/common-utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const { parseDate } = require('@/utils/parse-date');
const title = require('title');

// convert a string into title case
const toTitleCase = (str) =>
str
.toLowerCase()
.split(' ')
.map((word) => word.replace(word[0], word[0].toUpperCase()))
.join(' ');
const toTitleCase = (str) => title(str);

const rWhiteSpace = /\s+/;
const rAllWhiteSpace = /\s+/g;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"socks-proxy-agent": "8.0.2",
"source-map": "0.7.4",
"tiny-async-pool": "2.1.0",
"title": "3.5.3",
"tough-cookie": "4.1.3",
"twitter-api-v2": "1.15.2",
"winston": "3.11.0",
Expand Down
141 changes: 138 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/utils/common-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const utils = require('../../lib/utils/common-utils');

describe('common-utils', () => {
it('toTitleCase', () => {
expect(utils.toTitleCase('RSSHub IS AS aweSOme aS henry')).toBe('Rsshub Is As Awesome As Henry');
expect(utils.toTitleCase('RSSHub IS AS aweSOme aS henry')).toBe('Rsshub Is as Awesome as Henry');
});

it('convertDateToISO8601', () => {
Expand Down

0 comments on commit 7d33c91

Please sign in to comment.