Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 22, 2021
1 parent 82c5b8f commit e65ed6b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 52 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
- 6
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
35 changes: 13 additions & 22 deletions index.d.ts
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;
13 changes: 4 additions & 9 deletions index.js
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());
}
2 changes: 1 addition & 1 deletion index.test-d.ts
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'));
2 changes: 1 addition & 1 deletion license
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:

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
}
10 changes: 1 addition & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

> Capitalize every word in a string: `unicorn cake``Unicorn Cake`

## Install

```
$ npm install titleize
```


## Usage

```js
const titleize = require('titleize');
import titleize from 'titleize';

titleize('foo bar');
//=> 'Foo Bar'
Expand All @@ -22,12 +20,6 @@ titleize('foo-bar');
//=> 'Foo-Bar'
```


## Related

- [camelcase](https://github.com/sindresorhus/camelcase) - Convert a dash/dot/underscore/space separated string to camelcase


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import titleize from '.';
import titleize from './index.js';

test('main', t => {
t.is(titleize(''), '');
Expand Down

0 comments on commit e65ed6b

Please sign in to comment.