@stdlib/array-base-accessor-getter
Advanced tools
| { | ||
| "version": 3, | ||
| "sources": ["../lib/main.js", "../lib/index.js"], | ||
| "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 GETTERS = {\n\t'complex128': getComplex128,\n\t'complex64': getComplex64,\n\t'default': getArrayLike\n};\n\n\n// FUNCTIONS //\n\n/**\n* Returns an element from a `Complex128Array`.\n*\n* @private\n* @param {Complex128Array} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @returns {number} element value\n*\n* @example\n* var Complex128Array = require( '@stdlib/array-complex128' );\n* var real = require( '@stdlib/complex-float64-real' );\n* var imag = require( '@stdlib/complex-float64-imag' );\n*\n* var arr = new Complex128Array( [ 1, 2, 3, 4 ] );\n*\n* var v = getComplex128( arr, 1 );\n* // returns <Complex128>\n*\n* var re = real( v );\n* // returns 3.0\n*\n* var im = imag( v );\n* // returns 4.0\n*/\nfunction getComplex128( arr, idx ) {\n\treturn arr.get( idx );\n}\n\n/**\n* Returns an element from a `Complex64Array`.\n*\n* @private\n* @param {Complex64Array} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @returns {number} element value\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var v = getComplex64( arr, 1 );\n* // returns <Complex64>\n*\n* var re = realf( v );\n* // returns 3.0\n*\n* var im = imagf( v );\n* // returns 4.0\n*/\nfunction getComplex64( arr, idx ) {\n\treturn arr.get( idx );\n}\n\n/**\n* Returns an element from an array-like object supporting the get/set protocol.\n*\n* @private\n* @param {Collection} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @returns {*} element value\n*\n* @example\n* var arr = [ 1, 2, 3, 4 ];\n*\n* function get( idx ) {\n* return arr[ idx ];\n* }\n*\n* function set( value, idx ) {\n* arr[ idx ] = value;\n* }\n*\n* arr.get = get;\n* arr.set = set;\n*\n* var v = getArrayLike( arr, 2 );\n* // returns 3\n*/\nfunction getArrayLike( arr, idx ) {\n\treturn arr.get( idx );\n}\n\n\n// MAIN //\n\n/**\n* Returns an accessor function for retrieving an element from an array-like object supporting the get/set protocol.\n*\n* @param {string} dtype - array dtype\n* @returns {Function} accessor\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var dtype = require( '@stdlib/array-dtype' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var get = getter( dtype( arr ) );\n* var v = get( arr, 1 );\n* // returns <Complex64>\n*\n* var re = realf( v );\n* // returns 3.0\n*\n* var im = imagf( v );\n* // returns 4.0\n*/\nfunction getter( dtype ) {\n\tvar f = GETTERS[ dtype ];\n\tif ( typeof f === 'function' ) {\n\t\treturn f;\n\t}\n\treturn GETTERS.default;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getter;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.\n*\n* @module @stdlib/array-base-accessor-getter\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var dtype = require( '@stdlib/array-dtype' );\n* var getter = require( '@stdlib/array-base-accessor-getter' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var get = getter( dtype( arr ) );\n* var v = get( arr, 1 );\n* // returns <Complex64>\n*\n* var re = realf( v );\n* // returns 3.0\n*\n* var im = imagf( v );\n* // returns 4.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], | ||
| "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,CACb,WAAcC,EACd,UAAaC,EACb,QAAWC,CACZ,EA6BA,SAASF,EAAeG,EAAKC,EAAM,CAClC,OAAOD,EAAI,IAAKC,CAAI,CACrB,CA0BA,SAASH,EAAcE,EAAKC,EAAM,CACjC,OAAOD,EAAI,IAAKC,CAAI,CACrB,CA2BA,SAASF,EAAcC,EAAKC,EAAM,CACjC,OAAOD,EAAI,IAAKC,CAAI,CACrB,CA6BA,SAASC,EAAQC,EAAQ,CACxB,IAAIC,EAAIR,EAASO,CAAM,EACvB,OAAK,OAAOC,GAAM,WACVA,EAEDR,EAAQ,OAChB,CAKAD,EAAO,QAAUO,IC3GjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", | ||
| "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 GETTERS = {\n\t'complex128': getComplex128,\n\t'complex64': getComplex64,\n\t'default': getArrayLike\n};\n\n\n// FUNCTIONS //\n\n/**\n* Returns an element from a `Complex128Array`.\n*\n* @private\n* @param {Complex128Array} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @returns {number} element value\n*\n* @example\n* var Complex128Array = require( '@stdlib/array-complex128' );\n*\n* var arr = new Complex128Array( [ 1, 2, 3, 4 ] );\n*\n* var v = getComplex128( arr, 1 );\n* // returns <Complex128>[ 3.0, 4.0 ]\n*/\nfunction getComplex128( arr, idx ) {\n\treturn arr.get( idx );\n}\n\n/**\n* Returns an element from a `Complex64Array`.\n*\n* @private\n* @param {Complex64Array} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @returns {number} element value\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var v = getComplex64( arr, 1 );\n* // returns <Complex64>[ 3.0, 4.0 ]\n*/\nfunction getComplex64( arr, idx ) {\n\treturn arr.get( idx );\n}\n\n/**\n* Returns an element from an array-like object supporting the get/set protocol.\n*\n* @private\n* @param {Collection} arr - input array\n* @param {NonNegativeInteger} idx - element index\n* @returns {*} element value\n*\n* @example\n* var arr = [ 1, 2, 3, 4 ];\n*\n* function get( idx ) {\n* return arr[ idx ];\n* }\n*\n* function set( value, idx ) {\n* arr[ idx ] = value;\n* }\n*\n* arr.get = get;\n* arr.set = set;\n*\n* var v = getArrayLike( arr, 2 );\n* // returns 3\n*/\nfunction getArrayLike( arr, idx ) {\n\treturn arr.get( idx );\n}\n\n\n// MAIN //\n\n/**\n* Returns an accessor function for retrieving an element from an array-like object supporting the get/set protocol.\n*\n* @param {string} dtype - array dtype\n* @returns {Function} accessor\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var dtype = require( '@stdlib/array-dtype' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var get = getter( dtype( arr ) );\n* var v = get( arr, 1 );\n* // returns <Complex64>[ 3.0, 4.0 ]\n*/\nfunction getter( dtype ) {\n\tvar f = GETTERS[ dtype ];\n\tif ( typeof f === 'function' ) {\n\t\treturn f;\n\t}\n\treturn GETTERS.default;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getter;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.\n*\n* @module @stdlib/array-base-accessor-getter\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var dtype = require( '@stdlib/array-dtype' );\n* var getter = require( '@stdlib/array-base-accessor-getter' );\n*\n* var arr = new Complex64Array( [ 1, 2, 3, 4 ] );\n*\n* var get = getter( dtype( arr ) );\n* var v = get( arr, 1 );\n* // returns <Complex64>[ 3.0, 4.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], | ||
| "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,CACb,WAAcC,EACd,UAAaC,EACb,QAAWC,CACZ,EAqBA,SAASF,EAAeG,EAAKC,EAAM,CAClC,OAAOD,EAAI,IAAKC,CAAI,CACrB,CAkBA,SAASH,EAAcE,EAAKC,EAAM,CACjC,OAAOD,EAAI,IAAKC,CAAI,CACrB,CA2BA,SAASF,EAAcC,EAAKC,EAAM,CACjC,OAAOD,EAAI,IAAKC,CAAI,CACrB,CAqBA,SAASC,EAAQC,EAAQ,CACxB,IAAIC,EAAIR,EAASO,CAAM,EACvB,OAAK,OAAOC,GAAM,WACVA,EAEDR,EAAQ,OAChB,CAKAD,EAAO,QAAUO,IC3FjB,IAAIG,EAAO,IAKX,OAAO,QAAUA", | ||
| "names": ["require_main", "__commonJSMin", "exports", "module", "GETTERS", "getComplex128", "getComplex64", "getArrayLike", "arr", "idx", "getter", "dtype", "f", "main"] | ||
| } |
@@ -61,4 +61,2 @@ /* | ||
| * var Complex128Array = require( '@stdlib/array-complex128' ); | ||
| * var real = require( '@stdlib/array-real' ); | ||
| * var imag = require( '@stdlib/array-imag' ); | ||
| * | ||
@@ -69,9 +67,3 @@ * var arr = new Complex128Array( [ 1, 2, 3, 4 ] ); | ||
| * var v = get( arr, 1 ); | ||
| * // returns <Complex128> | ||
| * | ||
| * var re = real( v ); | ||
| * // returns 3.0 | ||
| * | ||
| * var im = imag( v ); | ||
| * // returns 4.0 | ||
| * // returns <Complex128>[ 3.0, 4.0 ] | ||
| */ | ||
@@ -88,4 +80,2 @@ declare function getter( dtype: 'complex128' ): GetComplex128; | ||
| * var Complex64Array = require( '@stdlib/array-complex64' ); | ||
| * var realf = require( '@stdlib/array-realf' ); | ||
| * var imagf = require( '@stdlib/array-imagf' ); | ||
| * | ||
@@ -96,9 +86,3 @@ * var arr = new Complex64Array( [ 1, 2, 3, 4 ] ); | ||
| * var v = get( arr, 1 ); | ||
| * // returns <Complex64> | ||
| * | ||
| * var re = realf( v ); | ||
| * // returns 3.0 | ||
| * | ||
| * var im = imagf( v ); | ||
| * // returns 4.0 | ||
| * // returns <Complex64>[ 3.0, 4.0 ] | ||
| */ | ||
@@ -105,0 +89,0 @@ declare function getter( dtype: 'complex64' ): GetComplex64; |
+1
-9
@@ -28,4 +28,2 @@ /** | ||
| * var Complex64Array = require( '@stdlib/array-complex64' ); | ||
| * var realf = require( '@stdlib/complex-float32-real' ); | ||
| * var imagf = require( '@stdlib/complex-float32-imag' ); | ||
| * var dtype = require( '@stdlib/array-dtype' ); | ||
@@ -38,9 +36,3 @@ * var getter = require( '@stdlib/array-base-accessor-getter' ); | ||
| * var v = get( arr, 1 ); | ||
| * // returns <Complex64> | ||
| * | ||
| * var re = realf( v ); | ||
| * // returns 3.0 | ||
| * | ||
| * var im = imagf( v ); | ||
| * // returns 4.0 | ||
| * // returns <Complex64>[ 3.0, 4.0 ] | ||
| */ | ||
@@ -47,0 +39,0 @@ |
+3
-27
@@ -42,4 +42,2 @@ /** | ||
| * var Complex128Array = require( '@stdlib/array-complex128' ); | ||
| * var real = require( '@stdlib/complex-float64-real' ); | ||
| * var imag = require( '@stdlib/complex-float64-imag' ); | ||
| * | ||
@@ -49,9 +47,3 @@ * var arr = new Complex128Array( [ 1, 2, 3, 4 ] ); | ||
| * var v = getComplex128( arr, 1 ); | ||
| * // returns <Complex128> | ||
| * | ||
| * var re = real( v ); | ||
| * // returns 3.0 | ||
| * | ||
| * var im = imag( v ); | ||
| * // returns 4.0 | ||
| * // returns <Complex128>[ 3.0, 4.0 ] | ||
| */ | ||
@@ -72,4 +64,2 @@ function getComplex128( arr, idx ) { | ||
| * var Complex64Array = require( '@stdlib/array-complex64' ); | ||
| * var realf = require( '@stdlib/complex-float32-real' ); | ||
| * var imagf = require( '@stdlib/complex-float32-imag' ); | ||
| * | ||
@@ -79,9 +69,3 @@ * var arr = new Complex64Array( [ 1, 2, 3, 4 ] ); | ||
| * var v = getComplex64( arr, 1 ); | ||
| * // returns <Complex64> | ||
| * | ||
| * var re = realf( v ); | ||
| * // returns 3.0 | ||
| * | ||
| * var im = imagf( v ); | ||
| * // returns 4.0 | ||
| * // returns <Complex64>[ 3.0, 4.0 ] | ||
| */ | ||
@@ -132,4 +116,2 @@ function getComplex64( arr, idx ) { | ||
| * var Complex64Array = require( '@stdlib/array-complex64' ); | ||
| * var realf = require( '@stdlib/complex-float32-real' ); | ||
| * var imagf = require( '@stdlib/complex-float32-imag' ); | ||
| * var dtype = require( '@stdlib/array-dtype' ); | ||
@@ -141,9 +123,3 @@ * | ||
| * var v = get( arr, 1 ); | ||
| * // returns <Complex64> | ||
| * | ||
| * var re = realf( v ); | ||
| * // returns 3.0 | ||
| * | ||
| * var im = imagf( v ); | ||
| * // returns 4.0 | ||
| * // returns <Complex64>[ 3.0, 4.0 ] | ||
| */ | ||
@@ -150,0 +126,0 @@ function getter( dtype ) { |
+1
-1
@@ -1,1 +0,1 @@ | ||
| Copyright (c) 2016-2024 The Stdlib Authors. | ||
| Copyright (c) 2016-2026 The Stdlib Authors. |
+1
-1
| { | ||
| "name": "@stdlib/array-base-accessor-getter", | ||
| "version": "0.2.2", | ||
| "version": "0.2.3", | ||
| "description": "Return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
+8
-16
@@ -72,4 +72,2 @@ <!-- | ||
| var Complex64Array = require( '@stdlib/array-complex64' ); | ||
| var realf = require( '@stdlib/complex-float32-real' ); | ||
| var imagf = require( '@stdlib/complex-float32-imag' ); | ||
@@ -80,9 +78,3 @@ var arr = new Complex64Array( [ 1, 2, 3, 4 ] ); | ||
| var v = get( arr, 1 ); | ||
| // returns <Complex64> | ||
| var re = realf( v ); | ||
| // returns 3.0 | ||
| var im = imagf( v ); | ||
| // returns 4.0 | ||
| // returns <Complex64>[ 3.0, 4.0 ] | ||
| ``` | ||
@@ -132,3 +124,3 @@ | ||
| var v = accessorGetter( dtype( arr ) )( arr, 2 ); | ||
| // returns <Complex128> | ||
| // returns <Complex128>[ 4.0, 5.0 ] | ||
@@ -140,3 +132,3 @@ console.log( v.toString() ); | ||
| v = accessorGetter( dtype( arr ) )( arr, 4 ); | ||
| // returns <Complex64> | ||
| // returns <Complex64>[ 8.0, 9.0 ] | ||
@@ -193,3 +185,3 @@ console.log( v.toString() ); | ||
| Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. | ||
| Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. | ||
@@ -207,4 +199,4 @@ </section> | ||
| [test-image]: https://github.com/stdlib-js/array-base-accessor-getter/actions/workflows/test.yml/badge.svg?branch=v0.2.2 | ||
| [test-url]: https://github.com/stdlib-js/array-base-accessor-getter/actions/workflows/test.yml?query=branch:v0.2.2 | ||
| [test-image]: https://github.com/stdlib-js/array-base-accessor-getter/actions/workflows/test.yml/badge.svg?branch=v0.2.3 | ||
| [test-url]: https://github.com/stdlib-js/array-base-accessor-getter/actions/workflows/test.yml?query=branch:v0.2.3 | ||
@@ -221,4 +213,4 @@ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-accessor-getter/main.svg | ||
| [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg | ||
| [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im | ||
| [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg | ||
| [chat-url]: https://stdlib.zulipchat.com | ||
@@ -225,0 +217,0 @@ [stdlib]: https://github.com/stdlib-js/stdlib |
33014
-5.75%266
-15.29%232
-3.33%