node-web-mvc
Version:
node spring mvc
63 lines (62 loc) • 2.36 kB
JavaScript
;
/**
* @module Javascript
* @description 处理javascript相关兼容
*/
Object.defineProperty(exports, "__esModule", { value: true });
const empty = {};
const protoKeys = Reflect.ownKeys(empty.__proto__).reduce((map, k) => (map[k] = true, map), {});
const symbol = Symbol('@parameters');
const isClassSymbol = Symbol('isClass');
class Javascript {
/**
* 获取原生对象上的keys
*/
static get protoKeys() {
return protoKeys;
}
/**
* 提取函数签名参数
*/
static resolveParameters(handler) {
if (typeof handler !== 'function') {
return [];
}
if (!handler[symbol]) {
const parts = handler.toString().split('(')[1] || '';
const express = parts.split(')')[0] || '';
handler[symbol] = express.split(',').map((s) => s.trim()).filter((s) => !!s);
}
return handler[symbol];
}
static createTyper(childType) {
return {
type: childType,
isExtendOf: (parentType) => {
var _a, _b;
return (_b = (_a = parentType === null || parentType === void 0 ? void 0 : parentType.prototype) === null || _a === void 0 ? void 0 : _a.isPrototypeOf) === null || _b === void 0 ? void 0 : _b.call(_a, childType === null || childType === void 0 ? void 0 : childType.prototype);
},
isType: (parentType) => {
var _a, _b;
return childType && parentType === childType || ((_b = (_a = parentType === null || parentType === void 0 ? void 0 : parentType.prototype) === null || _a === void 0 ? void 0 : _a.isPrototypeOf) === null || _b === void 0 ? void 0 : _b.call(_a, childType === null || childType === void 0 ? void 0 : childType.prototype));
},
};
}
static isClass(ctor) {
if (!ctor || typeof ctor !== 'function') {
return false;
}
if (ctor[isClassSymbol] === undefined) {
const source = String(ctor);
ctor[isClassSymbol] = source.indexOf('class ') === 0;
}
return ctor[isClassSymbol];
}
static defineHiddenProperty(data, name, value) {
Object.defineProperty(data, name, {
value: value,
enumerable: false,
});
}
}
exports.default = Javascript;