@simplism/core
Advanced tools
Comparing version 10.3.72 to 10.3.73
@@ -1,1 +0,1 @@ | ||
export declare function optional<T, R>(obj: T, fn: (o: NonNullable<T>) => R): R | undefined; | ||
export declare function optional<R extends any>(fn: () => R): R | undefined; |
{ | ||
"name": "@simplism/core", | ||
"version": "10.3.72", | ||
"version": "10.3.73", | ||
"description": "Simplism Core Package", | ||
@@ -5,0 +5,0 @@ "repository": "github:kslhunter/simplism", |
@@ -1,9 +0,19 @@ | ||
/*export type ChainedRequired<T> = { [P in keyof T]-?: ChainedRequired<T[P]> };*/ | ||
export function optional<T, R>(obj: T, fn: (o: NonNullable<T>/*ChainedRequired<NonNullable<T>>*/) => R): R | undefined { | ||
export function optional<R extends any>(fn: () => R): R | undefined { | ||
try { | ||
return fn(obj as any); | ||
const result = fn(); | ||
if (result instanceof Promise) { | ||
return result | ||
.catch((err: Error) => { | ||
if (err instanceof TypeError && err.message.includes("Cannot read property") && (err.message.includes("of undefined") || err.message.includes("of null"))) { | ||
return; | ||
} | ||
throw err; | ||
}); | ||
} | ||
else { | ||
return result; | ||
} | ||
} | ||
catch (err) { | ||
if (err instanceof TypeError && err.message.includes("Cannot read property") && err.message.includes("of undefined")) { | ||
if (err instanceof TypeError && err.message.includes("Cannot read property") && (err.message.includes("of undefined") || err.message.includes("of null"))) { | ||
return undefined; | ||
@@ -13,11 +23,2 @@ } | ||
} | ||
/*const parsed: ILambdaParseResult = LambdaParser.parse(fn); | ||
const chains: string[] = parsed.returnContent.slice(parsed.params[0].length + 1).split("."); | ||
let cursor: any = obj; | ||
for (const chain of chains) { | ||
cursor = cursor === undefined ? undefined : cursor[chain]; | ||
} | ||
return cursor;*/ | ||
} |
Sorry, the diff of this file is too big to display
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
238488
3360