Skip to content

Commit 867e525

Browse files
committed
Add TypeScript declarations
1 parent 611bb99 commit 867e525

File tree

5 files changed

+469
-20
lines changed

5 files changed

+469
-20
lines changed

lib/node_modules/@stdlib/array/filled/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,17 @@ var arr2 = filledarray( 1, 5, 'uint8' );
8383

8484
#### filledarray( value, array\[, dtype] )
8585

86-
Creates a filled array from another array.
86+
Creates a filled array from another array (or array-like object).
8787

8888
```javascript
89-
var arr1 = filledarray( 1.0, [ 5.0, -3.0, 2.0 ] );
89+
var arr0 = {
90+
'0': 0.5,
91+
'1': 0.5,
92+
'2': 0.5,
93+
'length': 3
94+
};
95+
96+
var arr1 = filledarray( 1.0, arr0 );
9097
// returns <Float64Array>[ 1.0, 1.0, 1.0 ]
9198

9299
var arr2 = filledarray( 2.0, arr1 );
@@ -96,15 +103,20 @@ var arr3 = filledarray( 3, arr1, 'int32' );
96103
// returns <Int32Array>[ 3, 3, 3 ]
97104
```
98105

99-
#### filledarray( value, obj\[, dtype] )
106+
#### filledarray( value, iterable\[, dtype] )
100107

101-
Creates a filled array from an array-like `object` or iterable.
108+
Creates a filled array from an iterable.
102109

103110
```javascript
104-
var arr1 = filledarray( 1.0, [ 0.5, 0.5, 0.5 ] );
111+
var iterConstant = require( '@stdlib/iter/constant' );
112+
113+
var it = iterConstant( 3.0, {
114+
'iter': 3
115+
});
116+
var arr1 = filledarray( 1.0, it );
105117
// returns <Float64Array>[ 1.0, 1.0, 1.0 ]
106118

107-
var arr2 = filledarray( 1.0, [ 0.5, 0.5, 0.5 ], 'float32' );
119+
var arr2 = filledarray( 1.0, it, 'float32' );
108120
// returns <Float32Array>[ 1.0, 1.0, 1.0 ]
109121
```
110122

lib/node_modules/@stdlib/array/filled/docs/repl.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
{{alias}}( value, [dtype] )
2+
{{alias}}( value[, dtype] )
33
Creates a filled array.
44

55
The function supports the following data types:
@@ -66,14 +66,14 @@
6666

6767

6868
{{alias}}( value, array[, dtype] )
69-
Creates a filled array from another array.
69+
Creates a filled array from another array (or array-like object).
7070

7171
Parameters
7272
----------
7373
value: any
7474
Fill value.
7575

76-
array: TypedArray|Array
76+
array: ArrayLikeObject
7777
Array from which to generate another array.
7878

7979
dtype: string (optional)
@@ -92,16 +92,16 @@
9292
<Float32Array>[ 1.0, 1.0, 1.0 ]
9393

9494

95-
{{alias}}( value, obj[, dtype] )
96-
Creates a filled array from an array-like object or iterable.
95+
{{alias}}( value, iterable[, dtype] )
96+
Creates a filled array from an iterable.
9797

9898
Parameters
9999
----------
100100
value: any
101101
Fill value.
102102

103-
obj: Object
104-
Array-like object or iterable from which to generate an array.
103+
iterable: Object
104+
Iterable from which to generate an array.
105105

106106
dtype: string (optional)
107107
Data type. Default: 'float64'.
@@ -113,7 +113,7 @@
113113

114114
Examples
115115
--------
116-
> var arr1 = [ 0.5, 0.5, 0.5 ];
116+
> var arr1 = {{alias:@stdlib/iter/constant}}( 3.0, {'iter': 3} );
117117
> var arr2 = {{alias}}( 1.0, arr1, 'float32' )
118118
<Float32Array>[ 1.0, 1.0, 1.0 ]
119119

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 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 { TypedArray } from '@stdlib/types/array';
24+
import { Collection } from '@stdlib/types/object';
25+
import { IterableIterator } from '@stdlib/types/iter';
26+
27+
/**
28+
* Array or typed array.
29+
*/
30+
type ArrayOrTypedArray = Array<any> | TypedArray;
31+
32+
/**
33+
* Creates a filled array.
34+
*
35+
* The function recognizes the following data types:
36+
*
37+
* - `float64`: double-precision floating-point numbers (IEEE 754)
38+
* - `float32`: single-precision floating-point numbers (IEEE 754)
39+
* - `int32`: 32-bit two's complement signed integers
40+
* - `uint32`: 32-bit unsigned integers
41+
* - `int16`: 16-bit two's complement signed integers
42+
* - `uint16`: 16-bit unsigned integers
43+
* - `int8`: 8-bit two's complement signed integers
44+
* - `uint8`: 8-bit unsigned integers
45+
* - `uint8c`: 8-bit unsigned integers clamped to `0-255`
46+
* - `generic`: generic JavaScript values
47+
*
48+
* @param value - fill value
49+
* @param dtype - data type (default: 'float64')
50+
* @throws must provide a recognized data type
51+
* @returns filled array
52+
*
53+
* @example
54+
* var arr = filledarray( 1.0 );
55+
* // returns <Float64Array>
56+
*
57+
* @example
58+
* var arr = filledarray( 1.0, 'float32' );
59+
* // returns <Float32Array>
60+
*/
61+
declare function filledarray( value: any, dtype?: string ): ArrayOrTypedArray;
62+
63+
/**
64+
* Creates a filled array having a specified `length`.
65+
*
66+
* @param value - fill value
67+
* @param length - array length
68+
* @param dtype - data type (default: 'float64')
69+
* @throws must provide a recognized data type
70+
* @returns filled array
71+
*
72+
* @example
73+
* var arr = filledarray( 1.0, 5 );
74+
* // returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]
75+
*
76+
* @example
77+
* var arr = filledarray( 1.0, 5, 'float32' );
78+
* // returns <Float32Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]
79+
*/
80+
declare function filledarray( value: any, length: number, dtype?: string ): ArrayOrTypedArray; // tslint:disable-line:max-line-length
81+
82+
/**
83+
* Creates a filled array from another `array`.
84+
*
85+
* @param value - fill value
86+
* @param array - typed array or array-like object
87+
* @param dtype - data type (default: 'float64')
88+
* @throws must provide a recognized data type
89+
* @returns filled array
90+
*
91+
* @example
92+
* var arr = filledarray( 1.0, [ 5.0, -3.0, 2.0 ] );
93+
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
94+
*
95+
* @example
96+
* var arr = filledarray( 1.0, [ 5.0, -3.0, 2.0 ], 'float32' );
97+
* // returns <Float32Array>[ 1.0, 1.0, 1.0 ]
98+
*/
99+
declare function filledarray( value: any, array: Collection, dtype?: string ): ArrayOrTypedArray; // tslint:disable-line:max-line-length unified-signatures
100+
101+
/**
102+
* Creates a filled array from an iterable.
103+
*
104+
* @param value - fill value
105+
* @param iterable - iterable
106+
* @param dtype - data type (default: 'float64')
107+
* @throws must provide a recognized data type
108+
* @returns filled array
109+
*
110+
* @example
111+
* var iterConstant = require( `@stdlib/iter/constant` );
112+
*
113+
* var it = iterConstant( 3.0, {
114+
* 'iter': 3
115+
* });
116+
* var arr = filledarray( 1.0, it );
117+
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
118+
*
119+
* @example
120+
* var iterConstant = require( `@stdlib/iter/constant` );
121+
*
122+
* var it = iterConstant( 3.0, {
123+
* 'iter': 3
124+
* });
125+
* var arr = filledarray( 1.0, it, 'float32' );
126+
* // returns <Float32Array>[ 1.0, 1.0, 1.0 ]
127+
*/
128+
declare function filledarray( value: any, iterable: IterableIterator, dtype?: string ): ArrayOrTypedArray; // tslint:disable-line:max-line-length unified-signatures
129+
130+
/**
131+
* Returns a filled typed array view of an `ArrayBuffer`.
132+
*
133+
* ## Notes
134+
*
135+
* - Creating a generic array from an `ArrayBuffer` is **not** supported.
136+
*
137+
* @param value - fill value
138+
* @param buffer - `ArrayBuffer`
139+
* @param byteOffset - byte offset
140+
* @param length - view length
141+
* @param dtype - data type (default: 'float64')
142+
* @throws must provide a recognized data type
143+
* @returns filled array
144+
*
145+
* @example
146+
* var ArrayBuffer = require( `@stdlib/array/buffer` );
147+
*
148+
* var buf = new ArrayBuffer( 32 );
149+
* var arr = filledarray( 1.0, buf, 8, 2 );
150+
* // returns <Float64Array>[ 1.0, 1.0 ]
151+
*
152+
* @example
153+
* var ArrayBuffer = require( `@stdlib/array/buffer` );
154+
*
155+
* var buf = new ArrayBuffer( 32 );
156+
* var arr = filledarray( 1.0, buf, 8, 2, 'float32' );
157+
* // returns <Float32Array>[ 1.0, 1.0 ]
158+
*
159+
*/
160+
declare function filledarray( value: any, buffer: ArrayBuffer, byteOffset: number, length: number, dtype?: string ): TypedArray; // tslint:disable-line:max-line-length
161+
162+
/**
163+
* Returns a filled typed array view of an `ArrayBuffer`.
164+
*
165+
* ## Notes
166+
*
167+
* - Creating a generic array from an `ArrayBuffer` is **not** supported.
168+
*
169+
* @param value - fill value
170+
* @param buffer - `ArrayBuffer`
171+
* @param byteOffset - byte offset
172+
* @param dtype - data type (default: 'float64')
173+
* @throws must provide a recognized data type
174+
* @returns filled array
175+
*
176+
* @example
177+
* var ArrayBuffer = require( `@stdlib/array/buffer` );
178+
*
179+
* var buf = new ArrayBuffer( 32 );
180+
* var arr = filledarray( 1.0, buf, 8 );
181+
* // returns <Float64Array>[ 1.0, 1.0, 1.0 ]
182+
*
183+
* @example
184+
* var ArrayBuffer = require( `@stdlib/array/buffer` );
185+
*
186+
* var buf = new ArrayBuffer( 32 );
187+
* var arr = filledarray( 1.0, buf, 8, 'float32' );
188+
* // returns <Float32Array>[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]
189+
*
190+
*/
191+
declare function filledarray( value: any, buffer: ArrayBuffer, byteOffset: number, dtype?: string ): TypedArray; // tslint:disable-line:max-line-length
192+
193+
/**
194+
* Returns a filled typed array view of an `ArrayBuffer`.
195+
*
196+
* ## Notes
197+
*
198+
* - Creating a generic array from an `ArrayBuffer` is **not** supported.
199+
*
200+
* @param value - fill value
201+
* @param buffer - `ArrayBuffer`
202+
* @param dtype - data type (default: 'float64')
203+
* @throws must provide a recognized data type
204+
* @returns filled array
205+
*
206+
* @example
207+
* var ArrayBuffer = require( `@stdlib/array/buffer` );
208+
*
209+
* var buf = new ArrayBuffer( 32 );
210+
* var arr = filledarray( 1.0, buf );
211+
* // returns <Float64Array>[ 1.0, 1.0, 1.0, 1.0 ]
212+
*
213+
* @example
214+
* var ArrayBuffer = require( `@stdlib/array/buffer` );
215+
*
216+
* var buf = new ArrayBuffer( 32 );
217+
* var arr = filledarray( 1.0, buf, 'float32' );
218+
* // returns <Float32Array>[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]
219+
*
220+
*/
221+
declare function filledarray( value: any, buffer: ArrayBuffer, dtype?: string ): TypedArray; // tslint:disable-line:max-line-length unified-signatures
222+
223+
224+
// EXPORTS //
225+
226+
export = filledarray;

0 commit comments

Comments
 (0)