@stdlib/ndarray-safe-casts 0.0.7 → 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2021 The Stdlib Authors.
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
 
@@ -157,7 +173,7 @@ See [LICENSE][stdlib-license].
157
173
 
158
174
  ## Copyright
159
175
 
160
- Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
176
+ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
161
177
 
162
178
  </section>
163
179
 
@@ -176,9 +192,20 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
176
192
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-safe-casts/main.svg
177
193
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-safe-casts?branch=main
178
194
 
195
+ <!--
196
+
179
197
  [dependencies-image]: https://img.shields.io/david/stdlib-js/ndarray-safe-casts.svg
180
198
  [dependencies-url]: https://david-dm.org/stdlib-js/ndarray-safe-casts/main
181
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
+
182
209
  [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
183
210
  [chat-url]: https://gitter.im/stdlib-js/stdlib/
184
211
 
@@ -188,8 +215,16 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
188
215
 
189
216
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-safe-casts/main/LICENSE
190
217
 
218
+ <!-- <related-links> -->
219
+
220
+ [@stdlib/ndarray/casting-modes]: https://www.npmjs.com/package/@stdlib/ndarray-casting-modes
221
+
191
222
  [@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes
192
223
 
224
+ [@stdlib/ndarray/same-kind-casts]: https://www.npmjs.com/package/@stdlib/ndarray-same-kind-casts
225
+
226
+ <!-- </related-links> -->
227
+
193
228
  </section>
194
229
 
195
230
  <!-- /.links -->
package/docs/repl.txt CHANGED
@@ -9,8 +9,8 @@
9
9
 
10
10
  Parameters
11
11
  ----------
12
- dtype: string (optional)
13
- ndarray data type.
12
+ dtype: any (optional)
13
+ ndarray data type value.
14
14
 
15
15
  Returns
16
16
  -------
@@ -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?: string ): any;
36
+ declare function safeCasts( dtype?: any ): any;
37
37
 
38
38
 
39
39
  // EXPORTS //
@@ -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 {string} [dtype] - ndarray data type
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.7",
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": {
@@ -39,6 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@stdlib/assert-has-own-property": "^0.0.x",
42
+ "@stdlib/ndarray-base-dtype-resolve-str": "^0.0.x",
42
43
  "@stdlib/ndarray-dtypes": "^0.0.x",
43
44
  "@stdlib/utils-keys": "^0.0.x",
44
45
  "@stdlib/utils-library-manifest": "^0.0.x"