Installations
npm install @stdlib/utils-async-map-keys
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=0.10.0
Node Version
16.20.2
NPM Version
8.19.4
Score
68.6
Supply Chain
83.7
Quality
82.3
Maintenance
100
Vulnerability
87.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
4,507
Last Day
1
Last Week
13
Last Month
82
Last Year
826
GitHub Statistics
Apache-2.0 License
2 Stars
67 Commits
3 Watchers
5 Branches
11 Contributors
Updated on Dec 01, 2024
Sponsor this package
Package Meta Information
Latest Version
0.2.2
Package Id
@stdlib/utils-async-map-keys@0.2.2
Unpacked Size
77.80 kB
Size
15.80 kB
File Count
14
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 28, 2024
Total Downloads
Cumulative downloads
Total Downloads
4,507
Last Day
-50%
1
Compared to previous day
Last Week
8.3%
13
Compared to previous week
Last Month
6.5%
82
Compared to previous month
Last Year
-38.1%
826
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
11
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
mapKeysAsync
Map keys from one object to a new object having the same values.
Installation
1npm install @stdlib/utils-async-map-keys
Usage
1var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );
mapKeysAsync( obj, [options,] transform, done )
Map keys from one object
to a new object
having the same values.
1function transform( key, next ) { 2 setTimeout( onTimeout, 0 ); 3 function onTimeout() { 4 next( null, key+':beep' ); 5 } 6} 7 8function done( error, out ) { 9 if ( error ) { 10 throw error; 11 } 12 console.log( out ); 13 // => { 'a:beep': 1, 'b:beep': 2 } 14} 15 16var obj = { 17 'a': 1, 18 'b': 2 19}; 20 21mapKeysAsync( obj, transform, done );
The next
callback accepts two arguments: error
and key
. The second argument to the next
callback is the transformed property name. If a transform
function calls the next
callback with a truthy error argument, the function stops processing any additional own properties and calls the done
callback for error processing.
1function transform( key, value, next ) { 2 setTimeout( onTimeout, value ); 3 function onTimeout() { 4 if ( value === 1 ) { 5 return next( new Error( 'boop' ) ); 6 } 7 next( null, key+':beep' ); 8 } 9} 10 11function done( error ) { 12 if ( error ) { 13 console.error( error.message ); 14 // => 'boop' 15 } 16} 17 18var obj = { 19 'a': 1, 20 'b': 2 21}; 22 23mapKeysAsync( obj, transform, done );
The function accepts the following options
:
limit
: the maximum number of pending invocations at any one time. Default:infinity
.series
:boolean
indicating whether to sequentially invoke thetransform
function for each own property. Iftrue
, the function setsoptions.limit=1
. Default:false
.thisArg
: the execution context forfcn
.
By default, all properties are processed concurrently, which means that the function does not guarantee completion order. To process each property sequentially, set the series
option to true
.
1function transform( key, value, next ) { 2 setTimeout( onTimeout, value ); 3 function onTimeout() { 4 next( null, key+':beep' ); 5 } 6} 7 8function done( error, out ) { 9 if ( error ) { 10 throw error; 11 } 12 console.log( out ); 13 // => { 'a:beep': 1, 'b:beep': 2 } 14} 15 16var obj = { 17 'a': 1, 18 'b': 2 19}; 20 21var opts = { 22 'series': true 23}; 24 25mapKeysAsync( obj, opts, transform, done );
To limit the maximum number of pending function invocations, set the limit
option.
1function transform( key, value, next ) { 2 setTimeout( onTimeout, value ); 3 function onTimeout() { 4 next( null, key+':beep' ); 5 } 6} 7 8function done( error, out ) { 9 if ( error ) { 10 throw error; 11 } 12 console.log( out ); 13 // => { 'a:beep': 1, 'b:beep': 2, 'c:beep': 3 } 14} 15 16var obj = { 17 'a': 1, 18 'b': 2, 19 'c': 3 20}; 21 22var opts = { 23 'limit': 2 24}; 25 26mapKeysAsync( obj, opts, transform, done );
To set the execution context of the transform
function, set the thisArg
option.
1function transform( key, value, next ) { 2 this.count += 1; 3 setTimeout( onTimeout, value ); 4 function onTimeout() { 5 next( null, key+':beep' ); 6 } 7} 8 9var obj = { 10 'a': 1, 11 'b': 2, 12 'c': 3 13}; 14 15var context = { 16 'count': 0 17}; 18 19var opts = { 20 'thisArg': context 21}; 22 23mapKeysAsync( obj, opts, transform, done ); 24 25function done( error, out ) { 26 if ( error ) { 27 throw error; 28 } 29 console.log( out ); 30 // => { 'a:beep': 1, 'b:beep': 2, 'c:beep': 3 } 31 32 console.log( context.count ); 33 // => 3 34}
When invoked, the transform
function is provided a maximum of four arguments:
key
: object key.value
: object value corresponding tokey
.obj
: source object.next
: a callback which should be called once thetransform
function has finished processing a property.
The actual number of provided arguments depends on function length
. If the transform
function accepts two arguments, the transform
function is provided key
and next
. If the transform
function accepts three arguments, the transform
function is provided key
, value
, and next
. For every other transform
function signature, the transform
function is provided all four arguments.
1function transform( key, value, obj, next ) { 2 console.log( 'obj: %s. %s: %d', JSON.stringify( obj ), key, value ); 3 setTimeout( onTimeout, value ); 4 function onTimeout() { 5 next( null, key+':'+value ); 6 } 7} 8 9function done( error, out ) { 10 if ( error ) { 11 throw error; 12 } 13 console.log( out ); 14} 15 16var obj = { 17 'a': 1, 18 'b': 2 19}; 20 21mapKeysAsync( obj, transform, done ); 22/* => e.g., 23 obj: {"a": 1, "b": 2}. a: 1 24 obj: {"a": 1, "b": 2}. b: 2 25 { 'a:1': 1, 'b:2': 2 } 26*/
mapKeysAsync.factory( [options,] transform )
Returns a function
which invokes a transform
function once for each own property.
1function transform( key, value, next ) { 2 setTimeout( onTimeout, value ); 3 function onTimeout() { 4 next( null, key+':beep' ); 5 } 6} 7 8function done( error, out ) { 9 if ( error ) { 10 throw error; 11 } 12 console.log( out ); 13} 14 15var f = mapKeysAsync.factory( transform ); 16 17var obj1 = { 18 'a': 1, 19 'b': 2 20}; 21 22f( obj1, done ); 23// => { 'a:beep': 1, 'b:beep': 2 } 24 25var obj2 = { 26 'c': 3, 27 'd': 4 28}; 29 30f( obj2, done ); 31// => { 'c:beep': 3, 'd:beep': 4 }
The function accepts the same options
as mapKeysAsync()
.
Notes
- If a provided function calls the
next
callback with a truthyerror
argument, the function suspends execution and immediately calls thedone
callback for subsequenterror
handling. - If provided an empty
object
, the function calls thedone
callback with an emptyobject
. - Key iteration order is not guaranteed, as
object
key enumeration is not specified according to the ECMAScript specification. In practice, however, most engines use insertion order to sort anobject
's keys, thus allowing for iteration order. - Key insertion order is not guaranteed.
- The value returned by a
transform
function should be a value which can be serialized as anobject
key. - The function only maps own properties. Hence, the function does not map inherited properties.
- The function shallow copies key values.
- Neither
mapKeysAsync
nor the function returned by thefactory
method guarantee asynchronous execution. To guarantee asynchrony, wrap thedone
callback in a function which either executes at the end of the current stack (e.g.,nextTick
) or during a subsequent turn of the event loop (e.g.,setImmediate
,setTimeout
).
Examples
1var resolve = require( 'path' ).resolve; 2var readFile = require( '@stdlib/fs-read-file' ); 3var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); 4 5var files = { 6 'file1': resolve( __dirname, 'package.json' ), 7 'file2': resolve( __dirname, 'README.md' ) 8}; 9 10function read( key, value, next ) { 11 var opts = { 12 'encoding': 'utf8' 13 }; 14 readFile( value, opts, onFile ); 15 16 function onFile( error ) { 17 if ( error ) { 18 return next( error, key+':unreadable' ); 19 } 20 next( null, key+':readable' ); 21 } 22} 23 24function done( error, out ) { 25 if ( error ) { 26 throw error; 27 } 28 console.log( out ); 29} 30 31mapKeysAsync( files, read, done );
See Also
@stdlib/utils-map-keys
: map keys from one object to a new object having the same values.@stdlib/utils-async/map-values
: map values from one object to a new object having the same keys.
Notice
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.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:623: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-async-map-keys/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-async-map-keys/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:275: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-async-map-keys/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:449: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-async-map-keys/productionize.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/productionize.yml:457: update your workflow using https://app.stepsecurity.io/secureworkflow/stdlib-js/utils-async-map-keys/productionize.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/examples.yml:58
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:269
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:436
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:617
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:157
- Warn: npmCommand not pinned by hash: .github/workflows/productionize.yml:165
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:76
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:83
- Warn: npmCommand not pinned by hash: .github/workflows/test_bundles.yml:72
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:67
- Warn: npmCommand not pinned by hash: .github/workflows/test_coverage.yml:74
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_install.yml:75
- Warn: npmCommand not pinned by hash: .github/workflows/test_published_package.yml:93
- Info: 33 out of 33 GitHub-owned GitHubAction dependencies pinned
- Info: 19 out of 24 third-party GitHubAction dependencies pinned
- Info: 0 out of 32 npmCommand dependencies pinned
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/cancel.yml:1
- Warn: no topLevel permission defined: .github/workflows/close_pull_requests.yml:1
- Warn: no topLevel permission defined: .github/workflows/examples.yml:1
- Warn: no topLevel permission defined: .github/workflows/npm_downloads.yml:1
- Warn: no topLevel permission defined: .github/workflows/productionize.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_bundles.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_coverage.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_install.yml:1
- Warn: no topLevel permission defined: .github/workflows/test_published_package.yml:1
- Info: no jobLevel write permissions found
Score
4.2
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More