Skip to content

Commit 1564984

Browse files
committed
Add Typescript definition
1 parent 1203729 commit 1564984

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/**
22+
* Reverses a string.
23+
*
24+
* @param str - input string
25+
* @returns reversed string
26+
*
27+
* @example
28+
* var out = reverse( 'last man standing' );
29+
* // returns 'gnidnats nam tsal'
30+
*
31+
* @example
32+
* var out = reverse( 'presidential election' );
33+
* // returns 'noitcele laitnediserp'
34+
*
35+
* @example
36+
* var out = reverse( 'javaScript' );
37+
* // returns 'tpircSavaj'
38+
*
39+
* @example
40+
* var out = reverse( 'Hidden Treasures' );
41+
* // returns 'serusaerT neddiH'
42+
*/
43+
declare function reverse( str: string ): string;
44+
45+
46+
// EXPORTS //
47+
48+
export = reverse;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import reverse = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a string...
25+
{
26+
reverse( 'last man standing' ); // $ExpectType string
27+
}
28+
29+
// The function does not compile if provided a value other than a number...
30+
{
31+
reverse( true ); // $ExpectError
32+
reverse( false ); // $ExpectError
33+
reverse( null ); // $ExpectError
34+
reverse( undefined ); // $ExpectError
35+
reverse( 5 ); // $ExpectError
36+
reverse( [] ); // $ExpectError
37+
reverse( {} ); // $ExpectError
38+
reverse( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided insufficient arguments...
42+
{
43+
reverse(); // $ExpectError
44+
}

lib/node_modules/@stdlib/string/reverse/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"lib": "./lib",
2626
"test": "./test"
2727
},
28+
"types": "./docs/types",
2829
"scripts": {},
2930
"homepage": "https://github.com/stdlib-js/stdlib",
3031
"repository": {

0 commit comments

Comments
 (0)