Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

core-functions

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-functions - npm Package Compare versions

Comparing version 3.0.24 to 3.0.25

9

CHANGES.md
## Changes
### 3.0.25
- Changes to `promises` module:
- Added `handleUnhandledRejection` & `handleUnhandledRejections` functions based on
`avoidUnhandledPromiseRejectionWarning` & `avoidUnhandledPromiseRejectionWarnings` functions
- Changed `avoidUnhandledPromiseRejectionWarning/s` functions to be deprecated synonyms for
`handleUnhandledRejection/s` functions
- Added `ignoreUnhandledRejection` & `ignoreUnhandledRejections` functions that suppress unhandled rejections without
logging
### 3.0.24

@@ -4,0 +13,0 @@ - Changes to `promises` module:

2

package.json
{
"name": "core-functions",
"version": "3.0.24",
"version": "3.0.25",
"description": "Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.",

@@ -5,0 +5,0 @@ "author": "Byron du Preez",

@@ -31,5 +31,14 @@ 'use strict';

exports.installCancelTimeout = installCancelTimeout;
exports.avoidUnhandledPromiseRejectionWarning = avoidUnhandledPromiseRejectionWarning;
exports.avoidUnhandledPromiseRejectionWarnings = avoidUnhandledPromiseRejectionWarnings;
exports.handleUnhandledRejection = handleUnhandledRejection;
exports.handleUnhandledRejections = handleUnhandledRejections;
exports.ignoreUnhandledRejection = ignoreUnhandledRejection;
exports.ignoreUnhandledRejections = ignoreUnhandledRejections;
// Legacy names
/** @deprecated use handleUnhandledRejection instead */
exports.avoidUnhandledPromiseRejectionWarning = handleUnhandledRejection;
/** @deprecated use handleUnhandledRejections instead */
exports.avoidUnhandledPromiseRejectionWarnings = handleUnhandledRejections;
/** @deprecated */

@@ -63,2 +72,4 @@ exports.wrapMethod = wrapMethod;

const noop = () => undefined;
/**

@@ -553,3 +564,3 @@ * An Error subclass thrown to cancel/short-circuit a promise that is waiting for a list of promises to resolve (see

// Attach `catch` clauses to the remaining unresolved promises to avoid unneeded warnings, since we will probably never do anything more with them
avoidUnhandledPromiseRejectionWarnings(unresolvedPromises, logger);
handleUnhandledRejections(unresolvedPromises, logger);
throw new CancelledError(outcomes.slice(0, i + 1), unresolvedPromises);

@@ -789,28 +800,58 @@ }

/**
* Attaches an arbitrary `catch` clause to the given promise to avoid an UnhandledPromiseRejectionWarning.
* Handles any unhandled rejections by attaching an error logging `catch` clause to the given promise.
* @param {Promise|PromiseLike|*} promise - a promise to which to attach an arbitrary `catch` clause
* @param {BasicLogger|undefined} [logger] - an optional alternative logger to use instead of the default `console` logger
* @returns {Promise|PromiseLike|*} the given promise for convenient chaining
*/
function avoidUnhandledPromiseRejectionWarning(promise, logger) {
function handleUnhandledRejection(promise, logger) {
if (promise && promise.catch) {
promise.catch(err => {
// Avoid unneeded warnings: e.g. (node:18304) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: ...): ...
const msg = 'Avoiding UnhandledPromiseRejectionWarning -';
if (!logger || logger.warn)
(logger || console).warn(msg, err);
const msg = 'Avoiding unhandled rejection:';
if (!logger || logger.error)
(logger || console).error(msg, err);
else
(logger || console).log('WARN', msg, err);
(logger.log ? logger : console).log('ERROR', msg, err);
});
}
return promise;
}
/**
* Attaches an arbitrary `catch` clause to each of the given promises to avoid UnhandledPromiseRejectionWarnings.
* Handles any unhandled rejections by attaching an error logging `catch` clause to each of the given promises.
* @param {Array.<Promise|PromiseLike|*>} promises - an array of promise to which to attach arbitrary `catch` clauses
* @param {BasicLogger|undefined} [logger] - an optional alternative logger to use instead of the default `console` logger
* @returns {Array.<Promise|PromiseLike|*>} the given array of promises for convenient chaining
*/
function avoidUnhandledPromiseRejectionWarnings(promises, logger) {
function handleUnhandledRejections(promises, logger) {
if (Array.isArray(promises)) {
promises.forEach(p => avoidUnhandledPromiseRejectionWarning(p, logger));
promises.forEach(p => handleUnhandledRejection(p, logger));
}
return promises;
}
/**
* Ignores any unhandled rejections by attaching a no-operation `catch` clause to the given promise.
* NB: ONLY use if this if you have already logged the promise's rejection.
* @param {Promise|PromiseLike|*} promise - a promise to which to attach a no-op `catch` clause
* @returns {Promise|PromiseLike|*} the given promise for convenient chaining
*/
function ignoreUnhandledRejection(promise) {
if (promise && promise.catch) {
promise.catch(noop);
}
return promise;
}
/**
* Ignores any unhandled rejections by attaching a no-operation `catch` clause to each of the given promises.
* NB: ONLY use if this if you have already logged the promises' rejections.
* @param {Array.<Promise|PromiseLike|*>} promises - an array of promise to which to attach `catch` clauses
* @returns {Array.<Promise|PromiseLike|*>} the given array of promises for convenient chaining
*/
function ignoreUnhandledRejections(promises) {
if (Array.isArray(promises)) {
promises.forEach(p => ignoreUnhandledRejection(p));
}
return promises;
}

@@ -1,2 +0,2 @@

# core-functions v3.0.24
# core-functions v3.0.25

@@ -3,0 +3,0 @@ Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc