Gathering detailed insights and metrics for @stdlib/utils-async-map-keys
Gathering detailed insights and metrics for @stdlib/utils-async-map-keys
npm install @stdlib/utils-async-map-keys
Typescript
Module System
Min. Node Version
Node Version
NPM Version
68.6
Supply Chain
83.7
Quality
82.3
Maintenance
100
Vulnerability
87.6
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
4,507
Last Day
1
Last Week
13
Last Month
82
Last Year
826
Apache-2.0 License
2 Stars
67 Commits
3 Watchers
5 Branches
11 Contributors
Updated on Dec 01, 2024
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
Cumulative downloads
Total Downloads
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
11
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!
Map keys from one object to a new object having the same values.
1npm install @stdlib/utils-async-map-keys
1var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );
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 the transform
function for each own property. If true
, the function sets options.limit=1
. Default: false
.thisArg
: the execution context for fcn
.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 to key
.obj
: source object.next
: a callback which should be called once the transform
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*/
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()
.
next
callback with a truthy error
argument, the function suspends execution and immediately calls the done
callback for subsequent error
handling.object
, the function calls the done
callback with an empty object
.object
key enumeration is not specified according to the ECMAScript specification. In practice, however, most engines use insertion order to sort an object
's keys, thus allowing for iteration order.transform
function should be a value which can be serialized as an object
key.mapKeysAsync
nor the function returned by the factory
method guarantee asynchronous execution. To guarantee asynchrony, wrap the done
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
).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 );
@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.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-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
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
Reason
branch protection not enabled on development/release branches
Details
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Score
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