Skip to content

Commit 815c133

Browse files
committed
Add Typescript definition
1 parent 9340097 commit 815c133

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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+
* Revives a JSON-serialized typed array.
23+
*
24+
* @param key - key
25+
* @param value - value
26+
* @returns value or typed array
27+
*
28+
* @example
29+
* var parseJSON = require( `@stdlib/utils/parse-json` );
30+
*
31+
* var str = '{"type":"Float64Array","data":[5,3]}';
32+
*
33+
* var arr = parseJSON( str, reviver );
34+
* // returns <Float64Array>[ 5.0, 3.0 ]
35+
*/
36+
declare function reviver( key: string, value: any ): any;
37+
38+
39+
// EXPORTS //
40+
41+
export = reviver;
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) 2021 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 reviver = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function can be used to revive a serialized object...
25+
{
26+
JSON.parse( '{"type":"Float64Array","data":[5,3]}', reviver ); // $ExpectType any
27+
}
28+
29+
// The function does not compile if provided a first argument that is not a string...
30+
{
31+
reviver( true, 1 ); // $ExpectError
32+
reviver( false, 1 ); // $ExpectError
33+
reviver( null, 1 ); // $ExpectError
34+
reviver( undefined, 1 ); // $ExpectError
35+
reviver( 5, 1 ); // $ExpectError
36+
reviver( [], 1 ); // $ExpectError
37+
reviver( {}, 1 ); // $ExpectError
38+
reviver( ( x: number ): number => x, 1 ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided insufficient arguments...
42+
{
43+
reviver(); // $ExpectError
44+
reviver( 'beep' ); // $ExpectError
45+
}

lib/node_modules/@stdlib/array/reviver/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)