UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

37 lines (36 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._getMethodSignature = _getMethodSignature; exports._getTargetMethodSignature = _getTargetMethodSignature; exports._getArgsSignature = _getArgsSignature; /** * @returns * e.g `NameOfYourClass.methodName` * or `NameOfYourClass(instanceId).methodName` */ function _getMethodSignature(ctx, keyStr) { const { instanceId } = ctx; return `${ctx.constructor.name}${instanceId ? `#${instanceId}` : ''}.${keyStr}`; } /** * @returns `NameOfYourClass.methodName` */ function _getTargetMethodSignature(target, keyStr) { return `${target.constructor.name}.${keyStr}`; } /** * @example * e.g for method (a: string, b: string, c: string) * returns: * a, b, c */ function _getArgsSignature(args = [], logArgs = true) { if (!logArgs) return ''; return args .map(arg => { const s = arg && typeof arg === 'object' ? JSON.stringify(arg) : String(arg); return s.length > 30 ? '...' : s; }) .join(', '); }