@stdlib/array-empty-like 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ 'use strict';
20
+
21
+ /**
22
+ * Create an uninitialized array having the same length and data type as a provided input array.
23
+ *
24
+ * @module @stdlib/array-empty-like
25
+ *
26
+ * @example
27
+ * var emptyLike = require( '@stdlib/array-empty-like' );
28
+ *
29
+ * var arr = emptyLike( [ 0.0, 0.0 ] );
30
+ * // returns [ 0.0, 0.0 ]
31
+ *
32
+ * @example
33
+ * var emptyLike = require( '@stdlib/array-empty-like' );
34
+ *
35
+ * var arr = emptyLike( [ 0.0, 0.0 ], 'float32' );
36
+ * // returns <Float32Array>
37
+ */
38
+
39
+ // MODULES //
40
+
41
+ var main = require( './main.js' );
42
+
43
+
44
+ // EXPORTS //
45
+
46
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var dtype = require( '@stdlib/array-dtype' );
24
+ var empty = require( '@stdlib/array-empty' );
25
+ var format = require( '@stdlib/string-format' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Creates an uninitialized array having the same length and data type as a provided input array.
32
+ *
33
+ * @param {(Array|TypedArray|ComplexArray)} x - input array
34
+ * @param {string} [dtype] - data type
35
+ * @throws {TypeError} first argument must be an array or typed array
36
+ * @throws {TypeError} second argument must be a recognized data type
37
+ * @returns {(TypedArray|Array|ComplexArray)} array or typed array
38
+ *
39
+ * @example
40
+ * var arr = emptyLike( [ 0.0, 0.0 ] );
41
+ * // returns [ 0.0, 0.0 ]
42
+ *
43
+ * @example
44
+ * var arr = emptyLike( [ 0.0, 0.0 ], 'float32' );
45
+ * // returns <Float32Array>
46
+ */
47
+ function emptyLike( x ) {
48
+ var dt = dtype( x ); // delegate input argument validation to dtype resolution
49
+ if ( dt === null ) {
50
+ throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or complex typed array. Value: `%s`.', x ) );
51
+ }
52
+ if ( arguments.length > 1 ) {
53
+ dt = arguments[ 1 ];
54
+ }
55
+ return empty( x.length, dt );
56
+ }
57
+
58
+
59
+ // EXPORTS //
60
+
61
+ module.exports = emptyLike;
package/package.json ADDED
@@ -0,0 +1,142 @@
1
+ {
2
+ "name": "@stdlib/array-empty-like",
3
+ "version": "0.0.1",
4
+ "description": "Create an uninitialized array having the same length and data type as a provided array.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {
26
+ "test": "make test",
27
+ "test-cov": "make test-cov",
28
+ "examples": "make examples",
29
+ "benchmark": "make benchmark"
30
+ },
31
+ "homepage": "https://stdlib.io",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git://github.com/stdlib-js/array-empty-like.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/stdlib-js/stdlib/issues"
38
+ },
39
+ "dependencies": {
40
+ "@stdlib/array-dtype": "^0.0.6",
41
+ "@stdlib/array-empty": "github:stdlib-js/array-empty#main",
42
+ "@stdlib/string-format": "^0.0.3",
43
+ "@stdlib/types": "^0.0.14"
44
+ },
45
+ "devDependencies": {
46
+ "@stdlib/array-complex128": "^0.0.6",
47
+ "@stdlib/array-complex64": "^0.0.6",
48
+ "@stdlib/array-dtypes": "^0.0.6",
49
+ "@stdlib/array-float32": "^0.0.6",
50
+ "@stdlib/array-float64": "^0.0.6",
51
+ "@stdlib/array-int16": "^0.0.6",
52
+ "@stdlib/array-int32": "^0.0.6",
53
+ "@stdlib/array-int8": "^0.0.6",
54
+ "@stdlib/array-uint16": "^0.0.6",
55
+ "@stdlib/array-uint32": "^0.0.6",
56
+ "@stdlib/array-uint8": "^0.0.7",
57
+ "@stdlib/array-uint8c": "^0.0.8",
58
+ "@stdlib/array-zeros": "^0.0.1",
59
+ "@stdlib/assert-instance-of": "^0.0.8",
60
+ "@stdlib/assert-is-array": "^0.0.7",
61
+ "@stdlib/assert-is-typed-array": "^0.0.6",
62
+ "@stdlib/assert-is-typed-array-like": "^0.0.8",
63
+ "@stdlib/bench": "^0.0.12",
64
+ "@stdlib/math-base-special-pow": "^0.0.7",
65
+ "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
66
+ "istanbul": "^0.4.1",
67
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
68
+ },
69
+ "engines": {
70
+ "node": ">=0.10.0",
71
+ "npm": ">2.7.0"
72
+ },
73
+ "os": [
74
+ "aix",
75
+ "darwin",
76
+ "freebsd",
77
+ "linux",
78
+ "macos",
79
+ "openbsd",
80
+ "sunos",
81
+ "win32",
82
+ "windows"
83
+ ],
84
+ "keywords": [
85
+ "stdlib",
86
+ "stdtypes",
87
+ "types",
88
+ "data",
89
+ "structure",
90
+ "typed",
91
+ "array",
92
+ "typed array",
93
+ "typed-array",
94
+ "vector",
95
+ "ndarray",
96
+ "matrix",
97
+ "float64array",
98
+ "float32array",
99
+ "int32array",
100
+ "uint32array",
101
+ "int16array",
102
+ "uint16array",
103
+ "int8array",
104
+ "uint8array",
105
+ "uint8clampedarray",
106
+ "complex128array",
107
+ "complex64array",
108
+ "complex128",
109
+ "complex64",
110
+ "complex",
111
+ "cmplx",
112
+ "float64",
113
+ "double",
114
+ "precision",
115
+ "double-precision",
116
+ "single",
117
+ "float",
118
+ "single-precision",
119
+ "float32",
120
+ "ieee754",
121
+ "integer",
122
+ "int32",
123
+ "signed",
124
+ "unsigned",
125
+ "uint32",
126
+ "int16",
127
+ "uint16",
128
+ "int8",
129
+ "uint8",
130
+ "uint8c",
131
+ "clamped",
132
+ "short",
133
+ "long",
134
+ "generic",
135
+ "empty",
136
+ "empty-like"
137
+ ],
138
+ "funding": {
139
+ "type": "opencollective",
140
+ "url": "https://opencollective.com/stdlib"
141
+ }
142
+ }