Skip to content

Commit a4fbb1d

Browse files
committed
Add Typescript definitions
1 parent fb05454 commit a4fbb1d

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
* Inserts supplied variable values into a format string.
23+
*
24+
* @param str - input string
25+
* @param ...args - variable values
26+
* @throws invalid flags
27+
* @returns formatted string
28+
*
29+
* @example
30+
* var str = format( 'Hello %s!', 'world' );
31+
* // returns 'Hello world!'
32+
*
33+
* @example
34+
* var str = format( 'Pi: ~%.2f', 3.141592653589793 );
35+
* // returns 'Pi: ~3.14'
36+
*/
37+
declare function format( str: string, ...args: Array<any> ): string;
38+
39+
40+
// EXPORTS //
41+
42+
export = format;
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) 2022 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 format = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a string...
25+
{
26+
format( 'Hello World!' ); // $ExpectType string
27+
format( 'Hello, %s!', 'Jane' ); // $ExpectType string
28+
}
29+
30+
// The function does not compile if provided a first argument other than a string...
31+
{
32+
format( true ); // $ExpectError
33+
format( false ); // $ExpectError
34+
format( null ); // $ExpectError
35+
format( undefined ); // $ExpectError
36+
format( 5 ); // $ExpectError
37+
format( [] ); // $ExpectError
38+
format( {} ); // $ExpectError
39+
format( ( x: number ): number => x ); // $ExpectError
40+
}
41+
42+
// The function does not compile if provided insufficient arguments...
43+
{
44+
format(); // $ExpectError
45+
}

0 commit comments

Comments
 (0)