Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50483ce
commit 9408184
Showing
7 changed files
with
29 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Capitalize every word in a string: `unicorn cake` → `Unicorn Cake`. | ||
* | ||
* @param input - The string to titleize. | ||
*/ | ||
export default function titleize(input: string): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
'use strict'; | ||
module.exports = input => { | ||
const titleize = input => { | ||
if (typeof input !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
|
||
return input.toLowerCase().replace(/(?:^|\s|-)\S/g, x => x.toUpperCase()); | ||
}; | ||
|
||
module.exports = titleize; | ||
module.exports.default = titleize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {expectType} from 'tsd-check'; | ||
import titleize from '.'; | ||
|
||
expectType<string>(titleize('foo bar')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import test from 'ava'; | ||
import m from '.'; | ||
import titleize from '.'; | ||
|
||
test('main', t => { | ||
t.is(m(''), ''); | ||
t.is(m('unicorns and rainbows'), 'Unicorns And Rainbows'); | ||
t.is(m('UNICORNS AND RAINBOWS'), 'Unicorns And Rainbows'); | ||
t.is(m('unicorns-and-rainbows'), 'Unicorns-And-Rainbows'); | ||
t.is(m('UNICORNS-AND-RAINBOWS'), 'Unicorns-And-Rainbows'); | ||
t.is(m('unicorns and rainbows'), 'Unicorns And Rainbows'); | ||
t.is(titleize(''), ''); | ||
t.is(titleize('unicorns and rainbows'), 'Unicorns And Rainbows'); | ||
t.is(titleize('UNICORNS AND RAINBOWS'), 'Unicorns And Rainbows'); | ||
t.is(titleize('unicorns-and-rainbows'), 'Unicorns-And-Rainbows'); | ||
t.is(titleize('UNICORNS-AND-RAINBOWS'), 'Unicorns-And-Rainbows'); | ||
t.is(titleize('unicorns and rainbows'), 'Unicorns And Rainbows'); | ||
}); |