Skip to content

Commit 86c209d

Browse files
committed
Add Typescript definition
1 parent 1564984 commit 86c209d

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
* Repeats a string `n` times and returns the concatenated result.
23+
*
24+
* @param str - string to repeat
25+
* @param n - number of times to repeat the string
26+
* @returns repeated string
27+
*
28+
* @example
29+
* var str = repeat( 'a', 5 );
30+
* // returns 'aaaaa'
31+
*
32+
* @example
33+
* var str = repeat( '', 100 );
34+
* // returns ''
35+
*
36+
* @example
37+
* var str = repeat( 'beep', 0 );
38+
* // returns ''
39+
*/
40+
declare function repeat( str: string, n: number ): string;
41+
42+
43+
// EXPORTS //
44+
45+
export = repeat;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 repeat = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a string...
25+
{
26+
repeat( 'a', 2 ); // $ExpectType string
27+
}
28+
29+
// The function does not compile if provided values other than a string and a number...
30+
{
31+
repeat( true, 3 ); // $ExpectError
32+
repeat( false, 2 ); // $ExpectError
33+
repeat( 3, 1 ); // $ExpectError
34+
repeat( [], 1 ); // $ExpectError
35+
repeat( {}, 2 ); // $ExpectError
36+
repeat( ( x: number ): number => x, 2 ); // $ExpectError
37+
38+
repeat( 'a', true ); // $ExpectError
39+
repeat( 'a', false ); // $ExpectError
40+
repeat( 'a', '5' ); // $ExpectError
41+
repeat( 'a', [] ); // $ExpectError
42+
repeat( 'a', {} ); // $ExpectError
43+
repeat( 'a', ( x: number ): number => x ); // $ExpectError
44+
45+
repeat( [], true ); // $ExpectError
46+
repeat( {}, false ); // $ExpectError
47+
repeat( false, '5' ); // $ExpectError
48+
repeat( {}, [] ); // $ExpectError
49+
repeat( '5', ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The function does not compile if provided insufficient arguments...
53+
{
54+
repeat(); // $ExpectError
55+
repeat( 3 ); // $ExpectError
56+
repeat( 'abc' ); // $ExpectError
57+
}

lib/node_modules/@stdlib/string/repeat/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)