@saberhq/solana-contrib
Advanced tools
Comparing version 1.12.70 to 1.12.71
@@ -34,2 +34,15 @@ /** | ||
export declare const exists: <TValue>(value: TValue | null | undefined) => value is TValue; | ||
/** | ||
* Applies a function to a null/undefined inner value if it is null or undefined, | ||
* otherwise returns null/undefined. | ||
* | ||
* @param obj | ||
* @param fn | ||
* @returns | ||
*/ | ||
export declare const mapSome: <T, U>(obj: NonNullable<T> | null | undefined, fn: (obj: NonNullable<T>) => U) => U | null | undefined; | ||
/** | ||
* Applies a function to a list of null/undefined values, unwrapping the null/undefined value or passing it through. | ||
*/ | ||
export declare const mapN: <T extends unknown[], U>(fn: (...a: { [K in keyof T]: NonNullable<T[K]>; }) => U, ...args: T) => U | null | undefined; | ||
//# sourceMappingURL=misc.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.exists = exports.isNotUndefined = exports.isNotNull = exports.suppressConsoleError = exports.suppressConsoleErrorAsync = void 0; | ||
exports.mapN = exports.mapSome = exports.exists = exports.isNotUndefined = exports.isNotNull = exports.suppressConsoleError = exports.suppressConsoleErrorAsync = void 0; | ||
const noop = () => { | ||
@@ -75,2 +75,25 @@ // noop | ||
exports.exists = exists; | ||
/** | ||
* Applies a function to a null/undefined inner value if it is null or undefined, | ||
* otherwise returns null/undefined. | ||
* | ||
* @param obj | ||
* @param fn | ||
* @returns | ||
*/ | ||
const mapSome = (obj, fn) => ((0, exports.exists)(obj) ? fn(obj) : obj); | ||
exports.mapSome = mapSome; | ||
/** | ||
* Applies a function to a list of null/undefined values, unwrapping the null/undefined value or passing it through. | ||
*/ | ||
const mapN = (fn, ...args) => { | ||
if (!args.every((arg) => arg !== undefined)) { | ||
return undefined; | ||
} | ||
if (!args.every((arg) => arg !== null)) { | ||
return null; | ||
} | ||
return fn(...args); | ||
}; | ||
exports.mapN = mapN; | ||
//# sourceMappingURL=misc.js.map |
@@ -34,2 +34,15 @@ /** | ||
export declare const exists: <TValue>(value: TValue | null | undefined) => value is TValue; | ||
/** | ||
* Applies a function to a null/undefined inner value if it is null or undefined, | ||
* otherwise returns null/undefined. | ||
* | ||
* @param obj | ||
* @param fn | ||
* @returns | ||
*/ | ||
export declare const mapSome: <T, U>(obj: NonNullable<T> | null | undefined, fn: (obj: NonNullable<T>) => U) => U | null | undefined; | ||
/** | ||
* Applies a function to a list of null/undefined values, unwrapping the null/undefined value or passing it through. | ||
*/ | ||
export declare const mapN: <T extends unknown[], U>(fn: (...a: { [K in keyof T]: NonNullable<T[K]>; }) => U, ...args: T) => U | null | undefined; | ||
//# sourceMappingURL=misc.d.ts.map |
@@ -67,2 +67,23 @@ const noop = () => { | ||
}; | ||
/** | ||
* Applies a function to a null/undefined inner value if it is null or undefined, | ||
* otherwise returns null/undefined. | ||
* | ||
* @param obj | ||
* @param fn | ||
* @returns | ||
*/ | ||
export const mapSome = (obj, fn) => (exists(obj) ? fn(obj) : obj); | ||
/** | ||
* Applies a function to a list of null/undefined values, unwrapping the null/undefined value or passing it through. | ||
*/ | ||
export const mapN = (fn, ...args) => { | ||
if (!args.every((arg) => arg !== undefined)) { | ||
return undefined; | ||
} | ||
if (!args.every((arg) => arg !== null)) { | ||
return null; | ||
} | ||
return fn(...args); | ||
}; | ||
//# sourceMappingURL=misc.js.map |
{ | ||
"name": "@saberhq/solana-contrib", | ||
"version": "1.12.70", | ||
"version": "1.12.71", | ||
"description": "Common types and libraries for Solana", | ||
@@ -46,3 +46,3 @@ "author": "Ian Macalinao <ian@saber.so>", | ||
}, | ||
"gitHead": "576566ae9814f24e994ac19e2aaa522ebf98f099", | ||
"gitHead": "e735e4e65e0f04a2d1f1950deddffeffa90ea04a", | ||
"publishConfig": { | ||
@@ -49,0 +49,0 @@ "access": "public" |
@@ -76,1 +76,38 @@ const noop = () => { | ||
}; | ||
/** | ||
* Applies a function to a null/undefined inner value if it is null or undefined, | ||
* otherwise returns null/undefined. | ||
* | ||
* @param obj | ||
* @param fn | ||
* @returns | ||
*/ | ||
export const mapSome = <T, U>( | ||
obj: NonNullable<T> | null | undefined, | ||
fn: (obj: NonNullable<T>) => U | ||
): U | null | undefined => (exists(obj) ? fn(obj) : obj); | ||
/** | ||
* Applies a function to a list of null/undefined values, unwrapping the null/undefined value or passing it through. | ||
*/ | ||
export const mapN = <T extends unknown[], U>( | ||
fn: ( | ||
...a: { | ||
[K in keyof T]: NonNullable<T[K]>; | ||
} | ||
) => U, | ||
...args: T | ||
): U | null | undefined => { | ||
if (!args.every((arg) => arg !== undefined)) { | ||
return undefined; | ||
} | ||
if (!args.every((arg) => arg !== null)) { | ||
return null; | ||
} | ||
return fn( | ||
...(args as { | ||
[K in keyof T]: NonNullable<T[K]>; | ||
}) | ||
); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
688935
9654