@stdlib/ndarray-safe-casts 0.0.4 → 0.0.8
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/NOTICE +1 -1
- package/README.md +46 -4
- package/docs/repl.txt +2 -2
- package/docs/types/index.d.ts +2 -2
- package/docs/types/test.ts +0 -10
- package/lib/main.js +3 -1
- package/package.json +4 -2
- package/CHANGELOG.md +0 -5
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2022 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
20
20
|
|
|
21
21
|
# Safe Casts
|
|
22
22
|
|
|
23
|
-
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
|
|
23
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
24
24
|
|
|
25
25
|
> Return a list of ndarray [data types][@stdlib/ndarray/dtypes] to which a provided ndarray [data type][@stdlib/ndarray/dtypes] can be safely cast.
|
|
26
26
|
|
|
@@ -131,6 +131,22 @@ for ( i = 0; i < DTYPES.length; i++ ) {
|
|
|
131
131
|
|
|
132
132
|
<!-- /.references -->
|
|
133
133
|
|
|
134
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
135
|
+
|
|
136
|
+
<section class="related">
|
|
137
|
+
|
|
138
|
+
* * *
|
|
139
|
+
|
|
140
|
+
## See Also
|
|
141
|
+
|
|
142
|
+
- <span class="package-name">[`@stdlib/ndarray/casting-modes`][@stdlib/ndarray/casting-modes]</span><span class="delimiter">: </span><span class="description">list of ndarray casting modes.</span>
|
|
143
|
+
- <span class="package-name">[`@stdlib/ndarray/dtypes`][@stdlib/ndarray/dtypes]</span><span class="delimiter">: </span><span class="description">list of ndarray data types.</span>
|
|
144
|
+
- <span class="package-name">[`@stdlib/ndarray/same-kind-casts`][@stdlib/ndarray/same-kind-casts]</span><span class="delimiter">: </span><span class="description">return a list of ndarray data types to which a provided ndarray data type can be safely cast or cast within the same kind.</span>
|
|
145
|
+
|
|
146
|
+
</section>
|
|
147
|
+
|
|
148
|
+
<!-- /.related -->
|
|
149
|
+
|
|
134
150
|
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
135
151
|
|
|
136
152
|
|
|
@@ -144,6 +160,10 @@ This package is part of [stdlib][stdlib], a standard library for JavaScript and
|
|
|
144
160
|
|
|
145
161
|
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
146
162
|
|
|
163
|
+
#### Community
|
|
164
|
+
|
|
165
|
+
[![Chat][chat-image]][chat-url]
|
|
166
|
+
|
|
147
167
|
---
|
|
148
168
|
|
|
149
169
|
## License
|
|
@@ -153,7 +173,7 @@ See [LICENSE][stdlib-license].
|
|
|
153
173
|
|
|
154
174
|
## Copyright
|
|
155
175
|
|
|
156
|
-
Copyright © 2016-
|
|
176
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
157
177
|
|
|
158
178
|
</section>
|
|
159
179
|
|
|
@@ -172,16 +192,38 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
172
192
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-safe-casts/main.svg
|
|
173
193
|
[coverage-url]: https://codecov.io/github/stdlib-js/ndarray-safe-casts?branch=main
|
|
174
194
|
|
|
175
|
-
|
|
195
|
+
<!--
|
|
196
|
+
|
|
197
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/ndarray-safe-casts.svg
|
|
176
198
|
[dependencies-url]: https://david-dm.org/stdlib-js/ndarray-safe-casts/main
|
|
177
199
|
|
|
200
|
+
-->
|
|
201
|
+
|
|
202
|
+
[umd]: https://github.com/umdjs/umd
|
|
203
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
204
|
+
|
|
205
|
+
[deno-url]: https://github.com/stdlib-js/ndarray-safe-casts/tree/deno
|
|
206
|
+
[umd-url]: https://github.com/stdlib-js/ndarray-safe-casts/tree/umd
|
|
207
|
+
[esm-url]: https://github.com/stdlib-js/ndarray-safe-casts/tree/esm
|
|
208
|
+
|
|
209
|
+
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
210
|
+
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
211
|
+
|
|
178
212
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
179
213
|
|
|
180
214
|
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
181
215
|
|
|
182
216
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-safe-casts/main/LICENSE
|
|
183
217
|
|
|
184
|
-
|
|
218
|
+
<!-- <related-links> -->
|
|
219
|
+
|
|
220
|
+
[@stdlib/ndarray/casting-modes]: https://www.npmjs.com/package/@stdlib/ndarray-casting-modes
|
|
221
|
+
|
|
222
|
+
[@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
|
|
223
|
+
|
|
224
|
+
[@stdlib/ndarray/same-kind-casts]: https://www.npmjs.com/package/@stdlib/ndarray-same-kind-casts
|
|
225
|
+
|
|
226
|
+
<!-- </related-links> -->
|
|
185
227
|
|
|
186
228
|
</section>
|
|
187
229
|
|
package/docs/repl.txt
CHANGED
package/docs/types/index.d.ts
CHANGED
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
* - If not provided an ndarray data type, the function returns a casting table.
|
|
27
27
|
* - If provided an unrecognized ndarray data type, the function returns `null`.
|
|
28
28
|
*
|
|
29
|
-
* @param dtype - ndarray data type
|
|
29
|
+
* @param dtype - ndarray data type value
|
|
30
30
|
* @returns list of ndarray data types or null
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* var list = safeCasts( 'float32' );
|
|
34
34
|
* // returns [...]
|
|
35
35
|
*/
|
|
36
|
-
declare function safeCasts( dtype?:
|
|
36
|
+
declare function safeCasts( dtype?: any ): any;
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
// EXPORTS //
|
package/docs/types/test.ts
CHANGED
|
@@ -28,16 +28,6 @@ import safeCasts = require( './index' );
|
|
|
28
28
|
safeCasts( 'float' ); // $ExpectType any
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// The function does not compile if provided a value other than a string...
|
|
32
|
-
{
|
|
33
|
-
safeCasts( 123 ); // $ExpectError
|
|
34
|
-
safeCasts( true ); // $ExpectError
|
|
35
|
-
safeCasts( false ); // $ExpectError
|
|
36
|
-
safeCasts( null ); // $ExpectError
|
|
37
|
-
safeCasts( {} ); // $ExpectError
|
|
38
|
-
safeCasts( ( x: number ): number => x ); // $ExpectError
|
|
39
|
-
}
|
|
40
|
-
|
|
41
31
|
// The function does not compile if provided more than one argument...
|
|
42
32
|
{
|
|
43
33
|
safeCasts( 'float32', 123 ); // $ExpectError
|
package/lib/main.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
var objectKeys = require( '@stdlib/utils-keys' );
|
|
24
24
|
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
|
+
var resolve = require( '@stdlib/ndarray-base-dtype-resolve-str' );
|
|
25
26
|
var SAFE_CASTS = require( './safe_casts.json' );
|
|
26
27
|
|
|
27
28
|
|
|
@@ -106,7 +107,7 @@ function generateTable() {
|
|
|
106
107
|
/**
|
|
107
108
|
* Returns a list of ndarray data types to which a provided ndarray data type can be safely cast.
|
|
108
109
|
*
|
|
109
|
-
* @param {
|
|
110
|
+
* @param {*} [dtype] - ndarray data type value
|
|
110
111
|
* @returns {(Object|StringArray|null)} list of ndarray data types or null
|
|
111
112
|
*
|
|
112
113
|
* @example
|
|
@@ -121,6 +122,7 @@ function safeCasts( dtype ) {
|
|
|
121
122
|
// Lazily generate table...
|
|
122
123
|
TABLE = generateTable();
|
|
123
124
|
}
|
|
125
|
+
dtype = resolve( dtype );
|
|
124
126
|
if ( hasOwnProp( TABLE, dtype ) ) {
|
|
125
127
|
return TABLE[ dtype ].slice();
|
|
126
128
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/ndarray-safe-casts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Return a list of ndarray data types to which a provided ndarray data type can be safely cast.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"benchmark": "./benchmark",
|
|
19
19
|
"doc": "./docs",
|
|
20
20
|
"example": "./examples",
|
|
21
|
+
"include": "./include",
|
|
21
22
|
"lib": "./lib",
|
|
22
23
|
"test": "./test"
|
|
23
24
|
},
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"examples": "make examples",
|
|
29
30
|
"benchmark": "make benchmark"
|
|
30
31
|
},
|
|
31
|
-
"homepage": "https://
|
|
32
|
+
"homepage": "https://stdlib.io",
|
|
32
33
|
"repository": {
|
|
33
34
|
"type": "git",
|
|
34
35
|
"url": "git://github.com/stdlib-js/ndarray-safe-casts.git"
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@stdlib/assert-has-own-property": "^0.0.x",
|
|
42
|
+
"@stdlib/ndarray-base-dtype-resolve-str": "^0.0.x",
|
|
41
43
|
"@stdlib/ndarray-dtypes": "^0.0.x",
|
|
42
44
|
"@stdlib/utils-keys": "^0.0.x",
|
|
43
45
|
"@stdlib/utils-library-manifest": "^0.0.x"
|