Skip to content

Commit 5a8540b

Browse files
BendingBendersindresorhus
authored andcommittedMar 5, 2019
Add TypeScript definition (#48)
1 parent 134172c commit 5a8540b

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed
 

‎index.d.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export interface Options {
2+
/**
3+
* Uppercase the first character: `foo-bar` → `FooBar`.
4+
*
5+
* @default false
6+
*/
7+
readonly pascalCase?: boolean;
8+
}
9+
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;

‎index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const preserveCamelCase = string => {
2929
return string;
3030
};
3131

32-
module.exports = (input, options) => {
32+
const camelCase = (input, options) => {
3333
if (!(typeof input === 'string' || Array.isArray(input))) {
3434
throw new TypeError('Expected the input to be `string | string[]`');
3535
}
@@ -73,3 +73,6 @@ module.exports = (input, options) => {
7373

7474
return postProcess(input);
7575
};
76+
77+
module.exports = camelCase;
78+
module.exports.default = camelCase;

‎index.test-d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {expectType} from 'tsd-check';
2+
import camelCase from '.';
3+
4+
expectType<string>(camelCase('foo-bar'));
5+
expectType<string>(camelCase('Foo-Bar', {pascalCase: true}));
6+
expectType<string>(camelCase(['foo', 'bar']));
7+
expectType<string>(camelCase(['__foo__', '--bar'], {pascalCase: true}));

‎package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=6"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd-check"
1717
},
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"index.d.ts"
2021
],
2122
"keywords": [
2223
"camelcase",
@@ -36,6 +37,7 @@
3637
],
3738
"devDependencies": {
3839
"ava": "^1.2.1",
40+
"tsd-check": "^0.3.0",
3941
"xo": "^0.24.0"
4042
}
4143
}

0 commit comments

Comments
 (0)
Please sign in to comment.