@stdlib/array-index 0.1.0 → 0.2.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/README.md +10 -4
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/docs/types/index.d.ts +3 -253
- package/lib/main.js +13 -9
- package/package.json +20 -39
package/README.md
CHANGED
|
@@ -371,7 +371,7 @@ var o = idx.toJSON();
|
|
|
371
371
|
|
|
372
372
|
```javascript
|
|
373
373
|
var Uint8Array = require( '@stdlib/array-uint8' );
|
|
374
|
-
|
|
374
|
+
|
|
375
375
|
var data = new Uint8Array( [ 1, 0, 0, 0 ] );
|
|
376
376
|
var idx = new ArrayIndex( data );
|
|
377
377
|
|
|
@@ -388,7 +388,7 @@ var o = idx.toJSON();
|
|
|
388
388
|
|
|
389
389
|
```javascript
|
|
390
390
|
var Uint8Array = require( '@stdlib/array-uint8' );
|
|
391
|
-
|
|
391
|
+
|
|
392
392
|
var data = new Uint8Array( [ 1, 0, 0, 0 ] );
|
|
393
393
|
var idx = new ArrayIndex( data );
|
|
394
394
|
|
|
@@ -475,6 +475,12 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype );
|
|
|
475
475
|
|
|
476
476
|
<section class="related">
|
|
477
477
|
|
|
478
|
+
* * *
|
|
479
|
+
|
|
480
|
+
## See Also
|
|
481
|
+
|
|
482
|
+
- <span class="package-name">[`@stdlib/array-to-fancy`][@stdlib/array/to-fancy]</span><span class="delimiter">: </span><span class="description">convert an array to an object supporting fancy indexing.</span>
|
|
483
|
+
|
|
478
484
|
</section>
|
|
479
485
|
|
|
480
486
|
<!-- /.related -->
|
|
@@ -518,8 +524,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
518
524
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-index.svg
|
|
519
525
|
[npm-url]: https://npmjs.org/package/@stdlib/array-index
|
|
520
526
|
|
|
521
|
-
[test-image]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml/badge.svg?branch=v0.1
|
|
522
|
-
[test-url]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml?query=branch:v0.1
|
|
527
|
+
[test-image]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml/badge.svg?branch=v0.2.1
|
|
528
|
+
[test-url]: https://github.com/stdlib-js/array-index/actions/workflows/test.yml?query=branch:v0.2.1
|
|
523
529
|
|
|
524
530
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-index/main.svg
|
|
525
531
|
[coverage-url]: https://codecov.io/github/stdlib-js/array-index?branch=main
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var c=u(function(Z,p){
|
|
2
2
|
function A(){return{persist:!1}}p.exports=A
|
|
3
|
-
});var g=
|
|
4
|
-
var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('
|
|
5
|
-
});var v=
|
|
3
|
+
});var g=u(function($,h){
|
|
4
|
+
var I=require('@stdlib/assert-is-plain-object/dist'),S=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,y=require('@stdlib/error-tools-fmtprodmsg/dist');function N(r,e){return I(e)?S(e,"persist")&&(r.persist=e.persist,!j(r.persist))?new TypeError(y('1rz2o',"persist",r.persist)):null:new TypeError(y('1rz2V',e));}h.exports=N
|
|
5
|
+
});var v=u(function(ee,m){
|
|
6
6
|
var P=require('@stdlib/utils-linked-list/dist'),k=new P;m.exports=k
|
|
7
|
-
});var q=
|
|
7
|
+
});var q=u(function(re,w){
|
|
8
8
|
var C=v();function F(r){for(var e=C.first();e;){if(e.value.id===r)return e;e=e.next}return null}w.exports=F
|
|
9
|
-
});var x=
|
|
9
|
+
});var x=u(function(te,_){
|
|
10
10
|
var b=-1;function R(){return b+=1,b.toString()}_.exports=R
|
|
11
|
-
});var O=
|
|
12
|
-
var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,
|
|
11
|
+
});var O=u(function(ae,T){
|
|
12
|
+
var d=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),s=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=require('@stdlib/utils-define-nonenumerable-property/dist'),J=require('@stdlib/assert-is-collection/dist'),L=require('@stdlib/assert-is-boolean/dist').isPrimitive,V=require('@stdlib/assert-is-integer/dist').isPrimitive,G=require('@stdlib/array-base-assert-is-accessor-array/dist'),U=require('@stdlib/array-to-json/dist'),z=require('@stdlib/array-dtype/dist'),D=require('@stdlib/array-base-copy/dist'),H=require('@stdlib/array-base-resolve-getter/dist'),K=require('@stdlib/error-tools-fmtprodmsg/dist'),M=c(),Q=g(),f=v(),E=q(),W=x();function a(r){var e,t,n,i,o,l;if(!(this instanceof a))return arguments.length>1?new a(r,arguments[1]):new a(r);if(!J(r))throw new TypeError(K('1rz2O',r));if(i=z(r),i==="generic"||i===null)if(r.length>0)if(n=H(r),l=n(r,0),L(l))o="bool";else if(V(l))o="int";else throw new TypeError(K('1rzFV'));else o="int";else if(i==="int32")o="int";else if(i==="uint8")o="mask";else throw new TypeError(K('1rzFV'));if(e=M(),arguments.length>1&&(t=Q(e,arguments[1]),t))throw t;return f.push({id:W(),ref:this,data:r,type:o,dtype:i,persist:e.persist}),s(this,"_node",f.last()),B(this,"_invalidated",!1),this}s(a,"name","ArrayIndex");s(a,"free",function(e){var t,n;return t=E(e),t===null?!1:(n=t.value,s(n.ref,"_invalidated",!0),f.remove(t),n.data=null,!0)});s(a,"get",function(e){var t,n,i;return t=E(e),t===null?null:(i=t.value,n={data:i.data,type:i.type,dtype:i.dtype},i.persist||a.free(e),n)});d(a.prototype,"data",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.data});d(a.prototype,"dtype",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.dtype});d(a.prototype,"id",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.id});d(a.prototype,"isCached",function(){return!this._invalidated});d(a.prototype,"type",function(){if(this._invalidated)throw new Error(K('1rzFW'));return this._node.value.type});s(a.prototype,"toString",function(){var e;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,"ArrayIndex<"+e.id+">"});s(a.prototype,"toJSON",function(){var e,t;if(this._invalidated)throw new Error(K('1rzFW'));return e=this._node.value,e.dtype==="generic"||e.dtype===null?G(e.data)?t=D(e.data):t=e.data:t=U(e.data),{type:"ArrayIndex",data:t}});T.exports=a
|
|
13
13
|
});var X=O();module.exports=X;
|
|
14
14
|
/** @license Apache-2.0 */
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/defaults.js", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns <string>\n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tget = resolveGetter( x );\n\t\tv = get( x, 0 );\n\n\t\t// Infer the \"type\" of index array from the first element...\n\t\tif ( isBoolean( v ) ) {\n\t\t\tt = 'bool';\n\t\t} else if ( isInteger( v ) ) {\n\t\t\tt = 'int';\n\t\t} else {\n\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var v = idx.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var id = idx.id;\n* // returns <string>\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC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AAS,8BAA+B,EACvDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAa,QAAS,uBAAwB,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAO,QAAS,yBAA0B,EAC1CC,EAAgB,QAAS,mCAAoC,EAC7DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IACRC,EAAiB,IACjBC,EAAa,IAyBjB,SAASC,EAAYC,EAAI,CACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,EAAE,gBAAgBP,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAYC,EAAG,UAAW,CAAE,CAAE,EAEnC,IAAID,EAAYC,CAAE,EAE1B,GAAK,CAACf,EAAce,CAAE,EACrB,MAAM,IAAI,UAAWP,EAAQ,8EAA+EO,CAAE,CAAE,EAKjH,GAHAI,EAAKd,EAAOU,CAAE,EAGTI,IAAO,WAAaA,IAAO,
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index arrays.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index arrays\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} array index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns <string>\n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar array2json = require( '@stdlib/array-to-json' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar resolveGetter = require( '@stdlib/array-base-resolve-getter' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findArrayIndex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* Array index constructor.\n*\n* @param {Collection} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} first argument must be a valid index array\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ArrayIndex} ArrayIndex instance\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\nfunction ArrayIndex( x ) {\n\tvar opts;\n\tvar err;\n\tvar get;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ArrayIndex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ArrayIndex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ArrayIndex( x );\n\t}\n\tif ( !isCollection( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );\n\t}\n\tdt = dtype( x );\n\n\t// When provided a \"generic\" array or an array of an unknown data type, attempt to infer the type of index array...\n\tif ( dt === 'generic' || dt === null ) {\n\t\tif ( x.length > 0 ) {\n\t\t\tget = resolveGetter( x );\n\t\t\tv = get( x, 0 );\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t\t\t}\n\t\t} else {\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index array.' );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Add the array index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': x,\n\t\t'type': t,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an array index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ArrayIndex\n* @readonly\n* @type {string}\n* @default 'ArrayIndex'\n*\n* @example\n* var str = ArrayIndex.name;\n* // returns 'ArrayIndex'\n*/\nsetReadOnly( ArrayIndex, 'name', 'ArrayIndex' );\n\n/**\n* Frees an array index object associated with a provided identifier.\n*\n* @name free\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an array index object was successfully freed\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var out = ArrayIndex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ArrayIndex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the array instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the array instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the original array:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the array associated with a provided identifier.\n*\n* @name get\n* @memberof ArrayIndex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing array index data\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ), {\n* 'persist': true\n* });\n* // returns <ArrayIndex>\n*\n* // ...\n*\n* var o = ArrayIndex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ArrayIndex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the array index object with the specified identifier:\n\tnode = findArrayIndex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the array index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tArrayIndex.free( id ); // note: this should come last, after having retrieved all desired array index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying array data of array index object.\n*\n* @name data\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {Collection}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var v = idx.data;\n* // returns <Uint8Array>[ 1, 0, 1, 0 ]\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying array data type of array index object.\n*\n* @name dtype\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an array index object.\n*\n* @name id\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var id = idx.id;\n* // returns <string>\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an array index is actively cached.\n*\n* @name isCached\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the type of array index object.\n*\n* @name type\n* @memberof ArrayIndex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} array index is no longer valid\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ArrayIndex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an array index object to a string.\n*\n* @name toString\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {string} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var str = idx.toString();\n* // e.g., 'ArrayIndex<0>'\n*/\nsetReadOnly( ArrayIndex.prototype, 'toString', function toString() {\n\tvar v;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\treturn 'ArrayIndex<' + v.id + '>';\n});\n\n/**\n* Serializes an array index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ArrayIndex` instance.\n*\n* @name toJSON\n* @memberof ArrayIndex.prototype\n* @type {Function}\n* @throws {Error} array index is no longer valid\n* @returns {Object} serialized array index object\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n*\n* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );\n* // returns <ArrayIndex>\n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ArrayIndex', 'data': { 'type': 'Uint8Array', 'data': [ 1, 0, 1, 0 ] } }\n*/\nsetReadOnly( ArrayIndex.prototype, 'toJSON', function toJSON() {\n\tvar v;\n\tvar o;\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This array index instance has already been freed and can no longer be used.' );\n\t}\n\tv = this._node.value;\n\tif ( v.dtype === 'generic' || v.dtype === null ) {\n\t\tif ( isAccessorArray( v.data ) ) {\n\t\t\to = copy( v.data );\n\t\t} else {\n\t\t\to = v.data;\n\t\t}\n\t} else {\n\t\to = array2json( v.data );\n\t}\n\treturn {\n\t\t'type': 'ArrayIndex',\n\t\t'data': o\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ArrayIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Array index constructor.\n*\n* @module @stdlib/array-index\n*\n* @example\n* var Uint8Array = require( '@stdlib/array-uint8' );\n* var ArrayIndex = require( '@stdlib/array-index' );\n*\n* var x = new Uint8Array( [ 1, 0, 1, 0 ] );\n*\n* var idx = new ArrayIndex( x );\n* // returns <ArrayIndex>\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,EACZ,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACJ,EAAWG,EAAK,OAAQ,GACtB,IA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EAEjBI,EAAIJ,EAAE,KAGPI,EAAIrB,EAAYiB,EAAE,IAAK,EAEjB,CACN,KAAQ,aACR,KAAQI,CACT,CACD,CAAC,EAKD7B,EAAO,QAAUkB,ICzZjB,IAAIY,EAAO,IAKX,OAAO,QAAUA",
|
|
6
6
|
"names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "format", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isCollection", "isBoolean", "isInteger", "isAccessorArray", "array2json", "dtype", "copy", "resolveGetter", "format", "defaults", "validate", "cache", "findArrayIndex", "generateId", "ArrayIndex", "x", "opts", "err", "get", "dt", "t", "v", "id", "node", "out", "o", "main"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -20,22 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
/// <reference types="@stdlib/types"/>
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Boolean index array.
|
|
27
|
-
*/
|
|
28
|
-
type BooleanIndexArray = Collection<boolean> | AccessorArrayLike<boolean>;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Integer index array.
|
|
32
|
-
*/
|
|
33
|
-
type IntegerIndexArray = Collection<number> | AccessorArrayLike<number>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Index array.
|
|
37
|
-
*/
|
|
38
|
-
type IndexArray = BooleanIndexArray | IntegerIndexArray;
|
|
23
|
+
import { BooleanIndexArray, IntegerIndexArray, IndexArray, MaskArrayIndex, Int32ArrayIndex, BooleanArrayIndex, IntegerArrayIndex, ArrayIndex, BaseIndexArrayObject, IndexArrayObject } from '@stdlib/types/array';
|
|
39
24
|
|
|
40
25
|
/**
|
|
41
26
|
* Interface describing function options.
|
|
@@ -47,242 +32,6 @@ interface Options {
|
|
|
47
32
|
persist?: boolean;
|
|
48
33
|
}
|
|
49
34
|
|
|
50
|
-
/**
|
|
51
|
-
* Interface describing an object containing array index data.
|
|
52
|
-
*/
|
|
53
|
-
interface BaseArrayObject {
|
|
54
|
-
/**
|
|
55
|
-
* The underlying array associated with an array index.
|
|
56
|
-
*/
|
|
57
|
-
data: IndexArray;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The type of array index.
|
|
61
|
-
*/
|
|
62
|
-
type: 'int' | 'bool' | 'mask';
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The data type of the underlying array.
|
|
66
|
-
*/
|
|
67
|
-
dtype: DataType;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Interface describing an object containing mask array data.
|
|
72
|
-
*/
|
|
73
|
-
interface MaskArrayObject extends BaseArrayObject {
|
|
74
|
-
/**
|
|
75
|
-
* The underlying array associated with an array index.
|
|
76
|
-
*/
|
|
77
|
-
data: Uint8Array;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The type of array index.
|
|
81
|
-
*/
|
|
82
|
-
type: 'mask';
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* The data type of the underlying array.
|
|
86
|
-
*/
|
|
87
|
-
dtype: 'uint8';
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Interface describing an object containing integer array data.
|
|
92
|
-
*/
|
|
93
|
-
interface Int32ArrayObject extends BaseArrayObject {
|
|
94
|
-
/**
|
|
95
|
-
* The underlying array associated with an array index.
|
|
96
|
-
*/
|
|
97
|
-
data: Int32Array;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The type of array index.
|
|
101
|
-
*/
|
|
102
|
-
type: 'int';
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* The data type of the underlying array.
|
|
106
|
-
*/
|
|
107
|
-
dtype: 'int32';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Interface describing an object containing integer array data.
|
|
112
|
-
*/
|
|
113
|
-
interface IntegerArrayObject extends BaseArrayObject {
|
|
114
|
-
/**
|
|
115
|
-
* The underlying array associated with an array index.
|
|
116
|
-
*/
|
|
117
|
-
data: IntegerIndexArray;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* The type of array index.
|
|
121
|
-
*/
|
|
122
|
-
type: 'int';
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* The data type of the underlying array.
|
|
126
|
-
*/
|
|
127
|
-
dtype: 'generic';
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Interface describing an object containing boolean array data.
|
|
132
|
-
*/
|
|
133
|
-
interface BooleanArrayObject extends BaseArrayObject {
|
|
134
|
-
/**
|
|
135
|
-
* The underlying array associated with an array index.
|
|
136
|
-
*/
|
|
137
|
-
data: BooleanIndexArray;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* The type of array index.
|
|
141
|
-
*/
|
|
142
|
-
type: 'bool';
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* The data type of the underlying array.
|
|
146
|
-
*/
|
|
147
|
-
dtype: 'generic';
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Array object data.
|
|
152
|
-
*/
|
|
153
|
-
type ArrayObject = MaskArrayObject | Int32ArrayObject | BooleanArrayObject | IntegerArrayObject | null;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Interface describing an array index object.
|
|
157
|
-
*/
|
|
158
|
-
interface BaseArrayIndex {
|
|
159
|
-
/**
|
|
160
|
-
* Read-only property returning the data associated with an `ArrayIndex` instance.
|
|
161
|
-
*/
|
|
162
|
-
data: IndexArray;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Read-only property returning the underlying array index data type.
|
|
166
|
-
*/
|
|
167
|
-
dtype: DataType;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Read-only property returning the unique identifier associated with an `ArrayIndex` instance.
|
|
171
|
-
*/
|
|
172
|
-
id: string;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Boolean indicating if an `ArrayIndex` instance is actively cached.
|
|
176
|
-
*/
|
|
177
|
-
isCached: boolean;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Read-only property returning the array index type.
|
|
181
|
-
*/
|
|
182
|
-
type: 'int' | 'bool' | 'mask';
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Serializes an `ArrayIndex` to a string.
|
|
186
|
-
*
|
|
187
|
-
* @returns serialized string
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* var Uint8Array = require( '@stdlib/array-uint8' );
|
|
191
|
-
*
|
|
192
|
-
* var idx = new ArrayIndex( new Uint8Array( [ 1, 0, 1, 0 ] ) );
|
|
193
|
-
* // returns <ArrayIndex>
|
|
194
|
-
*
|
|
195
|
-
* var str = idx.toString();
|
|
196
|
-
* // e.g., 'ArrayIndex<0>'
|
|
197
|
-
*/
|
|
198
|
-
toString(): string;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Interface describing a mask array index object.
|
|
203
|
-
*/
|
|
204
|
-
interface MaskArrayIndex extends BaseArrayIndex {
|
|
205
|
-
/**
|
|
206
|
-
* Read-only property returning the array index type.
|
|
207
|
-
*/
|
|
208
|
-
type: 'mask';
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Read-only property returning the underlying array index data type.
|
|
212
|
-
*/
|
|
213
|
-
dtype: 'uint8';
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Read-only property returning the underlying array data.
|
|
217
|
-
*/
|
|
218
|
-
data: Uint8Array;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Interface describing an integer array index object.
|
|
223
|
-
*/
|
|
224
|
-
interface Int32ArrayIndex extends BaseArrayIndex {
|
|
225
|
-
/**
|
|
226
|
-
* Read-only property returning the array index type.
|
|
227
|
-
*/
|
|
228
|
-
type: 'int';
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Read-only property returning the underlying array index data type.
|
|
232
|
-
*/
|
|
233
|
-
dtype: 'int32';
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Read-only property returning the underlying array data.
|
|
237
|
-
*/
|
|
238
|
-
data: Int32Array;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Interface describing a boolean array index object.
|
|
243
|
-
*/
|
|
244
|
-
interface BooleanArrayIndex extends BaseArrayIndex {
|
|
245
|
-
/**
|
|
246
|
-
* Read-only property returning the array index type.
|
|
247
|
-
*/
|
|
248
|
-
type: 'bool';
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Read-only property returning the underlying array index data type.
|
|
252
|
-
*/
|
|
253
|
-
dtype: 'generic';
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Read-only property returning the underlying array data.
|
|
257
|
-
*/
|
|
258
|
-
data: BooleanIndexArray;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Interface describing an integer array index object.
|
|
263
|
-
*/
|
|
264
|
-
interface IntegerArrayIndex extends BaseArrayIndex {
|
|
265
|
-
/**
|
|
266
|
-
* Read-only property returning the array index type.
|
|
267
|
-
*/
|
|
268
|
-
type: 'int';
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Read-only property returning the underlying array index data type.
|
|
272
|
-
*/
|
|
273
|
-
dtype: 'generic';
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Read-only property returning the underlying array data.
|
|
277
|
-
*/
|
|
278
|
-
data: IntegerIndexArray;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Array index object.
|
|
283
|
-
*/
|
|
284
|
-
type ArrayIndex = MaskArrayIndex | Int32ArrayIndex | BooleanArrayIndex | IntegerArrayIndex;
|
|
285
|
-
|
|
286
35
|
/**
|
|
287
36
|
* Interface defining an `ArrayIndex` constructor which is both "newable" and "callable".
|
|
288
37
|
*/
|
|
@@ -372,6 +121,7 @@ interface Constructor {
|
|
|
372
121
|
* // returns <ArrayIndex>
|
|
373
122
|
*/
|
|
374
123
|
new( x: IndexArray, options?: Options ): ArrayIndex;
|
|
124
|
+
|
|
375
125
|
/**
|
|
376
126
|
* Array index constructor.
|
|
377
127
|
*
|
|
@@ -512,7 +262,7 @@ interface Constructor {
|
|
|
512
262
|
* var dt = o.dtype;
|
|
513
263
|
* // returns 'uint8'
|
|
514
264
|
*/
|
|
515
|
-
get<T extends
|
|
265
|
+
get<T extends BaseIndexArrayObject = IndexArrayObject>( id: string ): T | null;
|
|
516
266
|
}
|
|
517
267
|
|
|
518
268
|
/**
|
package/lib/main.js
CHANGED
|
@@ -83,16 +83,20 @@ function ArrayIndex( x ) {
|
|
|
83
83
|
|
|
84
84
|
// When provided a "generic" array or an array of an unknown data type, attempt to infer the type of index array...
|
|
85
85
|
if ( dt === 'generic' || dt === null ) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
if ( x.length > 0 ) {
|
|
87
|
+
get = resolveGetter( x );
|
|
88
|
+
v = get( x, 0 );
|
|
89
|
+
|
|
90
|
+
// Infer the "type" of index array from the first element...
|
|
91
|
+
if ( isBoolean( v ) ) {
|
|
92
|
+
t = 'bool';
|
|
93
|
+
} else if ( isInteger( v ) ) {
|
|
94
|
+
t = 'int';
|
|
95
|
+
} else {
|
|
96
|
+
throw new TypeError( 'invalid argument. First argument must be a valid index array.' );
|
|
97
|
+
}
|
|
94
98
|
} else {
|
|
95
|
-
|
|
99
|
+
t = 'int';
|
|
96
100
|
}
|
|
97
101
|
} else if ( dt === 'int32' ) {
|
|
98
102
|
t = 'int';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/array-index",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Array index constructor.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -15,19 +15,12 @@
|
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
17
|
"directories": {
|
|
18
|
-
"benchmark": "./benchmark",
|
|
19
18
|
"doc": "./docs",
|
|
20
|
-
"example": "./examples",
|
|
21
19
|
"lib": "./lib",
|
|
22
|
-
"
|
|
20
|
+
"dist": "./dist"
|
|
23
21
|
},
|
|
24
22
|
"types": "./docs/types",
|
|
25
|
-
"scripts": {
|
|
26
|
-
"test": "make test",
|
|
27
|
-
"test-cov": "make test-cov",
|
|
28
|
-
"examples": "make examples",
|
|
29
|
-
"benchmark": "make benchmark"
|
|
30
|
-
},
|
|
23
|
+
"scripts": {},
|
|
31
24
|
"homepage": "https://stdlib.io",
|
|
32
25
|
"repository": {
|
|
33
26
|
"type": "git",
|
|
@@ -37,36 +30,24 @@
|
|
|
37
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
31
|
},
|
|
39
32
|
"dependencies": {
|
|
40
|
-
"@stdlib/array-base-assert-is-accessor-array": "^0.1
|
|
41
|
-
"@stdlib/array-base-copy": "^0.1
|
|
42
|
-
"@stdlib/array-base-resolve-getter": "^0.
|
|
43
|
-
"@stdlib/array-dtype": "^0.1
|
|
44
|
-
"@stdlib/array-to-json": "^0.1
|
|
45
|
-
"@stdlib/assert-has-own-property": "^0.
|
|
46
|
-
"@stdlib/assert-is-boolean": "^0.
|
|
47
|
-
"@stdlib/assert-is-collection": "^0.1
|
|
48
|
-
"@stdlib/assert-is-integer": "^0.1
|
|
49
|
-
"@stdlib/assert-is-plain-object": "^0.
|
|
50
|
-
"@stdlib/string-format": "^0.
|
|
51
|
-
"@stdlib/
|
|
52
|
-
"@stdlib/utils-define-nonenumerable-
|
|
53
|
-
"@stdlib/utils-define-nonenumerable-read-only-
|
|
54
|
-
"@stdlib/utils-
|
|
55
|
-
"@stdlib/
|
|
56
|
-
"@stdlib/error-tools-fmtprodmsg": "^0.1.1"
|
|
57
|
-
},
|
|
58
|
-
"devDependencies": {
|
|
59
|
-
"@stdlib/array-base-to-accessor-array": "^0.1.0",
|
|
60
|
-
"@stdlib/array-int32": "^0.1.1",
|
|
61
|
-
"@stdlib/array-uint8": "^0.1.1",
|
|
62
|
-
"@stdlib/assert-instance-of": "^0.1.1",
|
|
63
|
-
"@stdlib/assert-is-string": "^0.1.1",
|
|
64
|
-
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
65
|
-
"istanbul": "^0.4.1",
|
|
66
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
67
|
-
"@stdlib/bench-harness": "^0.1.2",
|
|
68
|
-
"@stdlib/bench": "^0.3.1"
|
|
33
|
+
"@stdlib/array-base-assert-is-accessor-array": "^0.2.1",
|
|
34
|
+
"@stdlib/array-base-copy": "^0.2.1",
|
|
35
|
+
"@stdlib/array-base-resolve-getter": "^0.2.0",
|
|
36
|
+
"@stdlib/array-dtype": "^0.2.1",
|
|
37
|
+
"@stdlib/array-to-json": "^0.2.1",
|
|
38
|
+
"@stdlib/assert-has-own-property": "^0.2.1",
|
|
39
|
+
"@stdlib/assert-is-boolean": "^0.2.1",
|
|
40
|
+
"@stdlib/assert-is-collection": "^0.2.1",
|
|
41
|
+
"@stdlib/assert-is-integer": "^0.2.1",
|
|
42
|
+
"@stdlib/assert-is-plain-object": "^0.2.1",
|
|
43
|
+
"@stdlib/string-format": "^0.2.1",
|
|
44
|
+
"@stdlib/utils-define-nonenumerable-property": "^0.2.1",
|
|
45
|
+
"@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2",
|
|
46
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",
|
|
47
|
+
"@stdlib/utils-linked-list": "^0.2.1",
|
|
48
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.1"
|
|
69
49
|
},
|
|
50
|
+
"devDependencies": {},
|
|
70
51
|
"engines": {
|
|
71
52
|
"node": ">=0.10.0",
|
|
72
53
|
"npm": ">2.7.0"
|