
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
@stdlib/array-base-accessor-getter
Advanced tools
Return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.
Return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.
npm install @stdlib/array-base-accessor-getter
var accessorGetter = require( '@stdlib/array-base-accessor-getter' );
Returns an accessor function for retrieving an element from an array-like object supporting the get/set protocol.
var Complex64Array = require( '@stdlib/array-complex64' );
var realf = require( '@stdlib/complex-realf' );
var imagf = require( '@stdlib/complex-imagf' );
var arr = new Complex64Array( [ 1, 2, 3, 4 ] );
var get = accessorGetter( 'complex64' );
var v = get( arr, 1 );
// returns <Complex64>
var re = realf( v );
// returns 3.0
var im = imagf( v );
// returns 4.0
The returned accessor function accepts the following arguments:
dtype, the function returns a default accessor function for accessing elements from any indexed array-like object supporting the get/set protocol; otherwise, the function returns an accessor function which should only be provided an array instance corresponding to dtype (e.g., if dtype is 'complex64', the returned accessor function should only be provided instances of Complex64Array).dtype, as doing so would introduce performance overhead. If array instances corresponding to other data types are provided to an accessor function, JavaScript runtimes will consider the function polymorphic, potentially triggering de-optimization. In order to ensure maximum performance, always ensure that an accessor function is monomorphic.get and set methods (e.g., Complex64Array and Complex128Array).var Complex128Array = require( '@stdlib/array-complex128' );
var Complex64Array = require( '@stdlib/array-complex64' );
var zeroTo = require( '@stdlib/array-base-zero-to' );
var dtype = require( '@stdlib/array-dtype' );
var accessorGetter = require( '@stdlib/array-base-accessor-getter' );
var arr = new Complex128Array( zeroTo( 10 ) );
var v = accessorGetter( dtype( arr ) )( arr, 2 );
// returns <Complex128>
console.log( v.toString() );
// => '4 + 5i'
arr = new Complex64Array( zeroTo( 10 ) );
v = accessorGetter( dtype( arr ) )( arr, 4 );
// returns <Complex64>
console.log( v.toString() );
// => '8 + 9i'
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2023. The Stdlib Authors.
FAQs
Return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.
The npm package @stdlib/array-base-accessor-getter receives a total of 30,574 weekly downloads. As such, @stdlib/array-base-accessor-getter popularity was classified as popular.
We found that @stdlib/array-base-accessor-getter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.