@simplism/core
Advanced tools
Comparing version 10.1.15 to 10.1.16
@@ -94,3 +94,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 9); | ||
/******/ return __webpack_require__(__webpack_require__.s = 8); | ||
/******/ }) | ||
@@ -1273,32 +1273,2 @@ /************************************************************************/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var LambdaParser = (function () { | ||
function LambdaParser() { | ||
} | ||
LambdaParser.parse = function (predicate) { | ||
var matches = predicate.toString().match(/function\s?\(([^)]*)\)[^{]*{((?!return)(.|\r|\n))*return\s?((.|\r|\n)*);?\s?}$/); | ||
if (matches === null) { | ||
throw new Error("Lambda 파싱 실패: " + predicate.toString() + "\n"); | ||
} | ||
var params = matches[1].split(",").map(function (item) { return item.trim(); }); | ||
var returnContent = matches[4].trim(); | ||
if (returnContent.endsWith(";")) { | ||
returnContent = returnContent.slice(0, -1); | ||
} | ||
return { | ||
params: params, | ||
returnContent: returnContent | ||
}; | ||
}; | ||
return LambdaParser; | ||
}()); | ||
exports.LambdaParser = LambdaParser; | ||
//# sourceMappingURL=module.js.map | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function __export(m) { | ||
@@ -1311,3 +1281,3 @@ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
__export(__webpack_require__(7)); | ||
__export(__webpack_require__(10)); | ||
__export(__webpack_require__(9)); | ||
__export(__webpack_require__(2)); | ||
@@ -1317,6 +1287,6 @@ __export(__webpack_require__(1)); | ||
__export(__webpack_require__(3)); | ||
__export(__webpack_require__(11)); | ||
__export(__webpack_require__(10)); | ||
__export(__webpack_require__(4)); | ||
__export(__webpack_require__(6)); | ||
__export(__webpack_require__(8)); | ||
__export(__webpack_require__(11)); | ||
__export(__webpack_require__(12)); | ||
@@ -1328,2 +1298,11 @@ __export(__webpack_require__(13)); | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=module.js.map | ||
/***/ }), | ||
/* 10 */ | ||
@@ -1344,2 +1323,23 @@ /***/ (function(module, exports, __webpack_require__) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var LambdaParser = (function () { | ||
function LambdaParser() { | ||
} | ||
LambdaParser.parse = function (predicate) { | ||
var matches = predicate.toString().match(/function\s?\(([^)]*)\)[^{]*{((?!return)(.|\r|\n))*return\s?((.|\r|\n)*);?\s?}$/); | ||
if (matches === null) { | ||
throw new Error("Lambda 파싱 실패: " + predicate.toString() + "\n"); | ||
} | ||
var params = matches[1].split(",").map(function (item) { return item.trim(); }); | ||
var returnContent = matches[4].trim(); | ||
if (returnContent.endsWith(";")) { | ||
returnContent = returnContent.slice(0, -1); | ||
} | ||
return { | ||
params: params, | ||
returnContent: returnContent | ||
}; | ||
}; | ||
return LambdaParser; | ||
}()); | ||
exports.LambdaParser = LambdaParser; | ||
//# sourceMappingURL=module.js.map | ||
@@ -1511,12 +1511,12 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var LambdaParser_1 = __webpack_require__(8); | ||
function optional(obj, fn) { | ||
var parsed = LambdaParser_1.LambdaParser.parse(fn); | ||
var chains = parsed.returnContent.slice(parsed.params[0].length + 1).split("."); | ||
var cursor = obj; | ||
for (var _i = 0, chains_1 = chains; _i < chains_1.length; _i++) { | ||
var chain = chains_1[_i]; | ||
cursor = cursor === undefined ? undefined : cursor[chain]; | ||
try { | ||
return fn(obj); | ||
} | ||
return cursor; | ||
catch (err) { | ||
if (err.message.includes("123")) { | ||
return undefined; | ||
} | ||
throw err; | ||
} | ||
} | ||
@@ -1523,0 +1523,0 @@ exports.optional = optional; |
{ | ||
"name": "@simplism/core", | ||
"version": "10.1.15", | ||
"version": "10.1.16", | ||
"description": "Simplism Core Package", | ||
@@ -5,0 +5,0 @@ "repository": "github:kslhunter/simplism", |
@@ -1,7 +0,14 @@ | ||
import {ILambdaParseResult, LambdaParser} from "./LambdaParser"; | ||
export type ChainedRequired<T> = { [P in keyof T]-?: ChainedRequired<T[P]> }; | ||
export type ChainedRequired<T> = {[P in keyof T]-?: ChainedRequired<T[P]>}; | ||
export function optional<T, R>(obj: T, fn: (o: ChainedRequired<NonNullable<T>>) => R): R | undefined { | ||
const parsed: ILambdaParseResult = LambdaParser.parse(fn); | ||
try { | ||
return fn(obj as any); | ||
} | ||
catch (err) { | ||
if (err.message.includes("123")) { | ||
return undefined; | ||
} | ||
throw err; | ||
} | ||
/*const parsed: ILambdaParseResult = LambdaParser.parse(fn); | ||
const chains: string[] = parsed.returnContent.slice(parsed.params[0].length + 1).split("."); | ||
@@ -14,3 +21,3 @@ | ||
return cursor; | ||
return cursor;*/ | ||
} |
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
3185
224027