-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
82c5b8f
commit e65ed6b
Showing
8 changed files
with
31 additions
and
52 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
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,26 +1,17 @@ | ||
declare const titleize: { | ||
/** | ||
Capitalize every word in a string: `unicorn cake` → `Unicorn Cake`. | ||
/** | ||
Capitalize every word in a string: `unicorn cake` → `Unicorn Cake`. | ||
@param input - The string to titleize. | ||
@param string - The string to titleize. | ||
@example | ||
``` | ||
import titleize = require('titleize'); | ||
@example | ||
``` | ||
import titleize from 'titleize'; | ||
titleize('foo bar'); | ||
//=> 'Foo Bar' | ||
titleize('foo bar'); | ||
//=> 'Foo Bar' | ||
titleize('foo-bar'); | ||
//=> 'Foo-Bar' | ||
``` | ||
*/ | ||
(input: string): string; | ||
|
||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function titleize(input: string): string; | ||
// export = titleize; | ||
default: typeof titleize; | ||
}; | ||
|
||
export = titleize; | ||
titleize('foo-bar'); | ||
//=> 'Foo-Bar' | ||
``` | ||
*/ | ||
export default function titleize(string: 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,12 +1,7 @@ | ||
'use strict'; | ||
const titleize = input => { | ||
if (typeof input !== 'string') { | ||
export default function titleize(string) { | ||
if (typeof string !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
|
||
return input.toLowerCase().replace(/(?:^|\s|-)\S/g, x => x.toUpperCase()); | ||
}; | ||
|
||
module.exports = titleize; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = titleize; | ||
return string.toLowerCase().replace(/(?:^|\s|-)\S/g, x => x.toUpperCase()); | ||
} |
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,4 @@ | ||
import {expectType} from 'tsd'; | ||
import titleize = require('.'); | ||
import titleize from './index.js'; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) | ||
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
|
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 |
---|---|---|
|
@@ -4,13 +4,16 @@ | |
"description": "Capitalize every word in a string: `unicorn cake` → `Unicorn Cake`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/titleize", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "[email protected]", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
|
@@ -32,8 +35,8 @@ | |
"convert" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.1", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.39.1" | ||
} | ||
} |
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