@supercharge/goodies
Advanced tools
Comparing version 1.11.1 to 2.0.0
/** | ||
* Runs the given `callback` if the `predicate` is `null` or `undefined`. | ||
* | ||
* @param {Boolean} predicate | ||
* @param {Function} callback | ||
* | ||
* @returns {*} | ||
*/ | ||
export declare function ifNullish<R>(input: boolean, callback: () => Promise<R>): undefined | Promise<R>; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ifNullish = void 0; | ||
const isNullish_1 = require("./isNullish"); | ||
function ifNullish(input, callback) { | ||
if ((0, isNullish_1.isNullish)(input)) { | ||
import { isNullish } from './isNullish.js'; | ||
export function ifNullish(input, callback) { | ||
if (isNullish(input)) { | ||
return callback(); | ||
} | ||
return undefined; | ||
} | ||
exports.ifNullish = ifNullish; |
@@ -1,10 +0,9 @@ | ||
export * from './esmRequire'; | ||
export * from './esmResolve'; | ||
export * from './ifNullish'; | ||
export * from './isAsyncFunction'; | ||
export * from './isFunction'; | ||
export * from './isNullish'; | ||
export * from './isNotNullish'; | ||
export * from './isPromise'; | ||
export * from './tap'; | ||
export * from './upon'; | ||
export { ifNullish } from './ifNullish.js'; | ||
export { isAsyncFunction, AsyncFunction } from './isAsyncFunction.js'; | ||
export { isFunction } from './isFunction.js'; | ||
export { isNullish } from './isNullish.js'; | ||
export { isNotNullish } from './isNotNullish.js'; | ||
export { isPromise } from './isPromise.js'; | ||
export { resolveDefaultImport } from './resolveDefaultImport.js'; | ||
export { tap } from './tap.js'; | ||
export { upon } from './upon.js'; |
'use strict'; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./esmRequire"), exports); | ||
__exportStar(require("./esmResolve"), exports); | ||
__exportStar(require("./ifNullish"), exports); | ||
__exportStar(require("./isAsyncFunction"), exports); | ||
__exportStar(require("./isFunction"), exports); | ||
__exportStar(require("./isNullish"), exports); | ||
__exportStar(require("./isNotNullish"), exports); | ||
__exportStar(require("./isPromise"), exports); | ||
__exportStar(require("./tap"), exports); | ||
__exportStar(require("./upon"), exports); | ||
export { ifNullish } from './ifNullish.js'; | ||
export { isAsyncFunction } from './isAsyncFunction.js'; | ||
export { isFunction } from './isFunction.js'; | ||
export { isNullish } from './isNullish.js'; | ||
export { isNotNullish } from './isNotNullish.js'; | ||
export { isPromise } from './isPromise.js'; | ||
export { resolveDefaultImport } from './resolveDefaultImport.js'; | ||
export { tap } from './tap.js'; | ||
export { upon } from './upon.js'; |
@@ -1,9 +0,5 @@ | ||
export declare type AsyncFunction = (...args: any[]) => Promise<any>; | ||
export type AsyncFunction = (...args: any[]) => Promise<any>; | ||
/** | ||
* Determine whether the given `input` is an async function. | ||
* | ||
* @param {*} input | ||
* | ||
* @returns {Boolean} | ||
*/ | ||
export declare function isAsyncFunction(input: any): input is AsyncFunction; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAsyncFunction = void 0; | ||
const isFunction_1 = require("./isFunction"); | ||
import { isFunction } from './isFunction.js'; | ||
/** | ||
* Determine whether the given `input` is an async function. | ||
* | ||
* @param {*} input | ||
* | ||
* @returns {Boolean} | ||
*/ | ||
function isAsyncFunction(input) { | ||
return (0, isFunction_1.isFunction)(input) && input.constructor.name === 'AsyncFunction'; | ||
export function isAsyncFunction(input) { | ||
return isFunction(input) && input.constructor.name === 'AsyncFunction'; | ||
} | ||
exports.isAsyncFunction = isAsyncFunction; |
/** | ||
* Determine whether the given `input` is a function. | ||
* | ||
* @param {*} input | ||
* | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
@@ -9,0 +5,0 @@ * isFunction('no') // false |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isFunction = void 0; | ||
/** | ||
* Determine whether the given `input` is a function. | ||
* | ||
* @param {*} input | ||
* | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
@@ -17,5 +11,4 @@ * isFunction('no') // false | ||
*/ | ||
function isFunction(input) { | ||
export function isFunction(input) { | ||
return typeof input === 'function'; | ||
} | ||
exports.isFunction = isFunction; |
/** | ||
* Determine whether the given `input` is **not** `null` or `undefined`. | ||
* | ||
* @param {T} input | ||
* | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
@@ -9,0 +5,0 @@ * isNotNullish() // false |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNotNullish = void 0; | ||
const isNullish_1 = require("./isNullish"); | ||
import { isNullish } from './isNullish.js'; | ||
/** | ||
* Determine whether the given `input` is **not** `null` or `undefined`. | ||
* | ||
* @param {T} input | ||
* | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
@@ -21,5 +15,4 @@ * isNotNullish() // false | ||
*/ | ||
function isNotNullish(input) { | ||
return !(0, isNullish_1.isNullish)(input); | ||
export function isNotNullish(input) { | ||
return !isNullish(input); | ||
} | ||
exports.isNotNullish = isNotNullish; |
/** | ||
* Determine whether the given `input` is `null` or `undefined`. | ||
* | ||
* @param {T} input | ||
* | ||
* @returns {Boolean} | ||
*/ | ||
export declare function isNullish<T>(input: T | undefined | null): input is null | undefined; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNullish = void 0; | ||
/** | ||
* Determine whether the given `input` is `null` or `undefined`. | ||
* | ||
* @param {T} input | ||
* | ||
* @returns {Boolean} | ||
*/ | ||
function isNullish(input) { | ||
export function isNullish(input) { | ||
return input == null; | ||
} | ||
exports.isNullish = isNullish; |
/** | ||
* Determine whether the given `promise` is a Promise. | ||
* | ||
* @param {T} promise | ||
* | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
@@ -9,0 +5,0 @@ * isPromise('no') // false |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isPromise = void 0; | ||
const isFunction_1 = require("./isFunction"); | ||
import { isFunction } from './isFunction.js'; | ||
/** | ||
* Determine whether the given `promise` is a Promise. | ||
* | ||
* @param {T} promise | ||
* | ||
* @returns {Boolean} | ||
* | ||
* @example | ||
@@ -16,5 +10,4 @@ * isPromise('no') // false | ||
*/ | ||
function isPromise(promise) { | ||
return !!promise && (0, isFunction_1.isFunction)(promise.then); | ||
export function isPromise(promise) { | ||
return promise != null && isFunction(promise.then); | ||
} | ||
exports.isPromise = isPromise; |
@@ -6,7 +6,2 @@ /** | ||
* | ||
* @param {*} value | ||
* @param {Function} callback | ||
* | ||
* @returns {*} value | ||
* | ||
* @example | ||
@@ -13,0 +8,0 @@ * const user = await tap(new User({ name: 'Supercharge' }), async user => { |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tap = void 0; | ||
const isPromise_1 = require("./isPromise"); | ||
const isFunction_1 = require("./isFunction"); | ||
const isAsyncFunction_1 = require("./isAsyncFunction"); | ||
function tap(value, callback) { | ||
if ((0, isPromise_1.isPromise)(value)) { | ||
import { isPromise } from './isPromise.js'; | ||
import { isFunction } from './isFunction.js'; | ||
import { isAsyncFunction } from './isAsyncFunction.js'; | ||
export function tap(value, callback) { | ||
if (isPromise(value)) { | ||
return tapAsync(value, callback); | ||
} | ||
if ((0, isAsyncFunction_1.isAsyncFunction)(callback)) { | ||
if (isAsyncFunction(callback)) { | ||
return tapAsync(value, callback); | ||
@@ -16,10 +14,4 @@ } | ||
} | ||
exports.tap = tap; | ||
/** | ||
* Synchronous handling of `tap`. | ||
* | ||
* @param {*} value | ||
* @param {Function} callback | ||
* | ||
* @returns {*} | ||
*/ | ||
@@ -30,3 +22,3 @@ function tapSync(value, callback) { | ||
} | ||
if ((0, isFunction_1.isFunction)(callback)) { | ||
if (isFunction(callback)) { | ||
callback(value); | ||
@@ -38,7 +30,2 @@ } | ||
* Asynchronous handling of `tap`. | ||
* | ||
* @param {*} value | ||
* @param {Function} callback | ||
* | ||
* @returns {*} | ||
*/ | ||
@@ -49,6 +36,6 @@ async function tapAsync(value, callback) { | ||
} | ||
if ((0, isPromise_1.isPromise)(value)) { | ||
if (isPromise(value)) { | ||
value = await value; | ||
} | ||
if ((0, isFunction_1.isFunction)(callback)) { | ||
if (isFunction(callback)) { | ||
await callback(value); | ||
@@ -55,0 +42,0 @@ } |
@@ -6,7 +6,2 @@ /** | ||
* | ||
* @param {*} value | ||
* @param {Function} callback | ||
* | ||
* @returns {*} value | ||
* | ||
* @example | ||
@@ -13,0 +8,0 @@ * const email = await upon(User.findById(1), async user => { |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.upon = void 0; | ||
const isPromise_1 = require("./isPromise"); | ||
const isFunction_1 = require("./isFunction"); | ||
const isAsyncFunction_1 = require("./isAsyncFunction"); | ||
function upon(value, callback) { | ||
if ((0, isPromise_1.isPromise)(value)) { | ||
import { isPromise } from './isPromise.js'; | ||
import { isFunction } from './isFunction.js'; | ||
import { isAsyncFunction } from './isAsyncFunction.js'; | ||
export function upon(value, callback) { | ||
if (isPromise(value)) { | ||
return uponAsync(value, callback); | ||
} | ||
if ((0, isAsyncFunction_1.isAsyncFunction)(callback)) { | ||
if (isAsyncFunction(callback)) { | ||
return uponAsync(value, callback); | ||
@@ -16,10 +14,4 @@ } | ||
} | ||
exports.upon = upon; | ||
/** | ||
* Synchronous handling of `upon`. | ||
* | ||
* @param {*} value | ||
* @param {Function} callback | ||
* | ||
* @returns {*} | ||
*/ | ||
@@ -30,3 +22,3 @@ function uponSync(value, callback) { | ||
} | ||
return (0, isFunction_1.isFunction)(callback) | ||
return isFunction(callback) | ||
? callback(value) | ||
@@ -37,15 +29,10 @@ : value; | ||
* Asynchronous handling of `upon`. | ||
* | ||
* @param {*} value | ||
* @param {Function} callback | ||
* | ||
* @returns {*} | ||
*/ | ||
async function uponAsync(value, callback) { | ||
if ((0, isPromise_1.isPromise)(value)) { | ||
if (isPromise(value)) { | ||
value = await value; | ||
} | ||
return (0, isFunction_1.isFunction)(callback) | ||
return isFunction(callback) | ||
? callback(value) | ||
: value; | ||
} |
{ | ||
"name": "@supercharge/goodies", | ||
"description": "Utility functions for Node.js and JavaScript", | ||
"version": "1.11.1", | ||
"version": "2.0.0", | ||
"author": "Marcus Pöhls <marcus@superchargejs.com>", | ||
@@ -9,20 +9,23 @@ "bugs": { | ||
}, | ||
"devDependencies": { | ||
"@japa/run-failed-tests": "~1.0.7", | ||
"@japa/runner": "~2.0.9", | ||
"@japa/spec-reporter": "~1.1.12", | ||
"@supercharge/eslint-config-typescript": "~2.3.0", | ||
"@supercharge/tsconfig": "~4.0.0", | ||
"@types/node": "~18.6.2", | ||
"@typescript-eslint/eslint-plugin": "~5.31.0", | ||
"c8": "~7.12.0", | ||
"eslint": "~8.20.0", | ||
"expect": "~28.1.3", | ||
"typescript": "~4.7.4" | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist", | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist", | ||
"exports": { | ||
".": "./dist/index.js" | ||
}, | ||
"devDependencies": { | ||
"@supercharge/eslint-config-typescript": "~4.0.0", | ||
"@supercharge/tsconfig": "~7.0.0", | ||
"@types/node": "~20.8.6", | ||
"c8": "~8.0.1", | ||
"eslint": "~8.51.0", | ||
"expect": "~29.7.0", | ||
"typescript": "~5.2.2" | ||
}, | ||
"homepage": "https://github.com/supercharge/goodies", | ||
@@ -51,6 +54,5 @@ "keywords": [ | ||
"lint:fix": "npm run lint -- --fix", | ||
"posttest": "c8 report --reporter=html", | ||
"test": "npm run build && npm run lint && npm run test:run", | ||
"test:run": "c8 node bin/test.js" | ||
"test:run": "c8 node --test" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
7
0
Yes
13000
23
258
1