Skip to content

Commit 2e7f7dc

Browse files
committed
Add Typescript definitions
1 parent bd8ce00 commit 2e7f7dc

File tree

12 files changed

+354
-0
lines changed

12 files changed

+354
-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 `Buffer`.
23+
*
24+
* @param key - key
25+
* @param value - value
26+
* @returns value or Buffer
27+
*
28+
* @example
29+
* var parseJSON = require( `@stdlib/utils/parse-json` );
30+
*
31+
* var str = '{"type":"Buffer","data":[5,3]}';
32+
*
33+
* var buf = parseJSON( str, reviver );
34+
* // returns <Buffer>[ 5, 3 ]
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":"Buffer","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( '{"type":"Buffer","data":[5,3]}' ); // $ExpectError
45+
}

lib/node_modules/@stdlib/buffer/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": {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
/// <reference types="node"/>
22+
23+
import { Buffer } from 'buffer';
24+
25+
/**
26+
* Returns a JSON representation of a `Buffer`.
27+
*
28+
* @param buffer - buffer to serialize
29+
* @throws first argument must be a `Buffer`
30+
* @returns JSON representation
31+
*
32+
* @example
33+
* var array2buffer = require( `@stdlib/buffer/from-array` );
34+
*
35+
* var buf = array2buffer( [ 1, 2 ] );
36+
* // returns <Buffer>
37+
*
38+
* var json = toJSON( buf );
39+
* // returns { 'type': 'Buffer', 'data': [ 1, 2 ] }
40+
*/
41+
declare function toJSON( buffer: Buffer ): any;
42+
43+
44+
// EXPORTS //
45+
46+
export = toJSON;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 array2buffer = require( '@stdlib/buffer/from-array' );
20+
import toJSON = require( './index' );
21+
22+
23+
// TESTS //
24+
25+
// The function returns an object...
26+
{
27+
const buf = array2buffer( [ 1, 2 ] );
28+
toJSON( buf ); // $ExpectType any
29+
}
30+
31+
// The function does not compile if provided a value other than a buffer...
32+
{
33+
toJSON( 'abc' ); // $ExpectError
34+
toJSON( true ); // $ExpectError
35+
toJSON( false ); // $ExpectError
36+
toJSON( null ); // $ExpectError
37+
toJSON( undefined ); // $ExpectError
38+
toJSON( 5 ); // $ExpectError
39+
toJSON( [] ); // $ExpectError
40+
toJSON( {} ); // $ExpectError
41+
toJSON( ( x: number ): number => x ); // $ExpectError
42+
}
43+
44+
// The function does not compile if provided insufficient arguments...
45+
{
46+
toJSON(); // $ExpectError
47+
}

lib/node_modules/@stdlib/buffer/to-json/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": {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 error object.
23+
*
24+
* @param key - key
25+
* @param value - value
26+
* @returns value or error object
27+
*
28+
* @example
29+
* var str = '{"type":"TypeError","message":"beep"}';
30+
* var err = JSON.parse( str, reviver );
31+
* // returns <TypeError>
32+
*/
33+
declare function reviver( key: string, value: any ): any;
34+
35+
36+
// EXPORTS //
37+
38+
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( '{"beep":"boop"}', 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/error/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": {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
* Returns a JSON representation of an error object.
23+
*
24+
* @param err - error to serialize
25+
* @returns JSON representation
26+
*
27+
* @example
28+
* var err = new Error( 'beep' );
29+
* var json = toJSON( err );
30+
* // returns {...}
31+
*/
32+
declare function toJSON( err: Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError ): any; // tslint-disable-line max-line-length
33+
34+
35+
// EXPORTS //
36+
37+
export = toJSON;

0 commit comments

Comments
 (0)