UNPKG

@hestjs/core

Version:

HestJS Core Framework - A TypeScript framework built on Hono with dependency injection and decorators

61 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isConstructor = isConstructor; exports.getParamTypes = getParamTypes; exports.getReturnType = getReturnType; exports.generateId = generateId; exports.deepMerge = deepMerge; require("reflect-metadata"); /** * 检查是否为类构造函数 */ function isConstructor(target) { return typeof target === 'function' && target.prototype && target.prototype.constructor === target; } /** * 获取函数参数类型 */ function getParamTypes(target, propertyKey) { if (propertyKey) { return Reflect.getMetadata('design:paramtypes', target.prototype, propertyKey) || []; } return Reflect.getMetadata('design:paramtypes', target) || []; } /** * 获取函数返回类型 */ function getReturnType(target, propertyKey) { return Reflect.getMetadata('design:returntype', target.prototype, propertyKey); } /** * 生成唯一标识符 */ function generateId() { return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); } /** * 深度合并对象 */ function deepMerge(target, source) { const result = { ...target }; for (const key in source) { if (source.hasOwnProperty(key)) { const sourceValue = source[key]; const targetValue = result[key]; if (isObject(sourceValue) && isObject(targetValue)) { result[key] = deepMerge(targetValue, sourceValue); } else { result[key] = sourceValue; } } } return result; } /** * 检查是否为对象 */ function isObject(obj) { return obj !== null && typeof obj === 'object' && !Array.isArray(obj); } //# sourceMappingURL=helpers.js.map