Skip to content

Commit 1f43e8a

Browse files
BendingBendersindresorhus
authored andcommitted
Refactor TypeScript definition to CommonJS compatible export (#50)
1 parent 3eae33d commit 1f43e8a

File tree

4 files changed

+67
-21
lines changed

4 files changed

+67
-21
lines changed

index.d.ts

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,63 @@
1-
export interface Options {
2-
/**
3-
* Uppercase the first character: `foo-bar` → `FooBar`.
4-
*
5-
* @default false
6-
*/
7-
readonly pascalCase?: boolean;
1+
declare namespace camelcase {
2+
interface Options {
3+
/**
4+
Uppercase the first character: `foo-bar` → `FooBar`.
5+
6+
@default false
7+
*/
8+
readonly pascalCase?: boolean;
9+
}
810
}
911

10-
/**
11-
* Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`.
12-
*
13-
* @param input - String to convert to camel case.
14-
*/
15-
export default function camelcase(
16-
input: string | ReadonlyArray<string>,
17-
options?: Options
18-
): string;
12+
declare const camelcase: {
13+
/**
14+
Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`.
15+
16+
@param input - String to convert to camel case.
17+
18+
@example
19+
```
20+
import camelCase = require('camelcase');
21+
22+
camelCase('foo-bar');
23+
//=> 'fooBar'
24+
25+
camelCase('foo_bar');
26+
//=> 'fooBar'
27+
28+
camelCase('Foo-Bar');
29+
//=> 'fooBar'
30+
31+
camelCase('Foo-Bar', {pascalCase: true});
32+
//=> 'FooBar'
33+
34+
camelCase('--foo.bar', {pascalCase: false});
35+
//=> 'fooBar'
36+
37+
camelCase('foo bar');
38+
//=> 'fooBar'
39+
40+
console.log(process.argv[3]);
41+
//=> '--foo-bar'
42+
camelCase(process.argv[3]);
43+
//=> 'fooBar'
44+
45+
camelCase(['foo', 'bar']);
46+
//=> 'fooBar'
47+
48+
camelCase(['__foo__', '--bar'], {pascalCase: true});
49+
//=> 'FooBar'
50+
```
51+
*/
52+
(input: string | ReadonlyArray<string>, options?: camelcase.Options): string;
53+
54+
// TODO: Remove this for the next major release, refactor the whole definition to:
55+
// declare function camelcase(
56+
// input: string | ReadonlyArray<string>,
57+
// options?: camelcase.Options
58+
// ): string;
59+
// export = camelcase;
60+
default: typeof camelcase;
61+
};
62+
63+
export = camelcase;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ const camelCase = (input, options) => {
7575
};
7676

7777
module.exports = camelCase;
78+
// TODO: Remove this for the next major release
7879
module.exports.default = camelCase;

index.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {expectType} from 'tsd-check';
2-
import camelCase from '.';
1+
import {expectType} from 'tsd';
2+
import camelCase = require('.');
33

44
expectType<string>(camelCase('foo-bar'));
55
expectType<string>(camelCase('Foo-Bar', {pascalCase: true}));

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"node": ">=6"
1414
},
1515
"scripts": {
16-
"test": "xo && ava && tsd-check"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
1919
"index.js",
@@ -36,8 +36,8 @@
3636
"pascal-case"
3737
],
3838
"devDependencies": {
39-
"ava": "^1.2.1",
40-
"tsd-check": "^0.3.0",
39+
"ava": "^1.4.1",
40+
"tsd": "^0.7.1",
4141
"xo": "^0.24.0"
4242
}
4343
}

0 commit comments

Comments
 (0)