Skip to content

Commit 88f33da

Browse files
committed
Add Typescript definition
1 parent 8f62eb5 commit 88f33da

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
import { Collection } from '@stdlib/types/object';
24+
25+
/**
26+
* Adds elements from one collection to the end of another collection.
27+
*
28+
* @param collection1 - collection
29+
* @param collection2 - collection containing elements to add
30+
* @returns updated collection
31+
*
32+
* @example
33+
* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
34+
*
35+
* arr = append( arr, [ 6.0, 7.0 ] );
36+
* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
37+
*
38+
* @example
39+
* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
40+
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
41+
*
42+
* arr = append( arr, [ 6.0, 7.0 ] );
43+
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
44+
*/
45+
declare function append( collection1: Collection, collection2 ): Collection;
46+
47+
48+
// EXPORTS //
49+
50+
export = append;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 append = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a collection...
25+
{
26+
append( [ 0, 0 ], [ 1, 1 ] ); // $ExpectType Collection
27+
append( [ false, true ], [ 0, 1 ] ); // $ExpectType Collection
28+
append( [ 'abc', 'abc' ], [ 0, 1 ] ); // $ExpectType Collection
29+
append( [ true, true ], [ false, false ] ); // $ExpectType Collection
30+
}
31+
32+
// The compiler throws an error if the function is provided a first argument which is not a collection...
33+
{
34+
append( true, [] ); // $ExpectError
35+
append( false, [] ); // $ExpectError
36+
append( 5, [] ); // $ExpectError
37+
}
38+
39+
// The compiler throws an error if the function is provided a second argument which is not a collection...
40+
{
41+
append( [], true ); // $ExpectError
42+
append( [], false ); // $ExpectError
43+
append( [], 5 ); // $ExpectError
44+
}
45+
46+
// The compiler throws an error if the function is not provided two arguments...
47+
{
48+
append(); // $ExpectError
49+
append( [ true, true ] ); // $ExpectError
50+
append( [ true, true ], [ true, false ], 3 ); // $ExpectError
51+
}

lib/node_modules/@stdlib/utils/append/package.json

+1
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)