UNPKG

@berish/rfp

Version:

Binary secure transport organization protocol for peer communication using function fingerprints

60 lines 2.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPrint = exports.getType = exports.PrintTypeEnum = exports.SYMBOL_SERBER_PEER = void 0; const typeof_1 = __importDefault(require("@berish/typeof")); const const_1 = require("../const"); exports.SYMBOL_SERBER_PEER = Symbol('serberPeer'); var PrintTypeEnum; (function (PrintTypeEnum) { PrintTypeEnum["printFunction"] = "pf"; PrintTypeEnum["printClass"] = "pc"; PrintTypeEnum["printBuffer"] = "pb"; PrintTypeEnum["printError"] = "pe"; })(PrintTypeEnum = exports.PrintTypeEnum || (exports.PrintTypeEnum = {})); const mainPrintTypeKey = '_t'; const customPrintTypeKey = '_pt'; const printFunctionHandler = { typeName: 'printFunction', handler: (value, preview) => preview === 'object' && isPrint(value) && value[customPrintTypeKey] === PrintTypeEnum.printFunction, }; const printClassHandler = { typeName: 'printClass', handler: (value, preview) => preview === 'object' && isPrint(value) && value[customPrintTypeKey] === PrintTypeEnum.printClass, }; const printBufferHandler = { typeName: 'printBuffer', handler: (value, preview) => preview === 'object' && isPrint(value) && value[customPrintTypeKey] === PrintTypeEnum.printBuffer, }; const printErrorHandler = { typeName: 'printError', handler: (value, preview) => preview === 'object' && isPrint(value) && value[customPrintTypeKey] === PrintTypeEnum.printError, }; function getType(value) { return typeof_1.default(value, [ printFunctionHandler, printClassHandler, printBufferHandler, printErrorHandler, ]); } exports.getType = getType; function createPrint(type) { return { [mainPrintTypeKey]: const_1.magicalDictionary.mainKey, [customPrintTypeKey]: type, }; } exports.createPrint = createPrint; function isPrint(data) { if (data && typeof data === 'object' && mainPrintTypeKey in data && customPrintTypeKey in data && data[mainPrintTypeKey] === const_1.magicalDictionary.mainKey) return true; return false; } //# sourceMappingURL=abstract.js.map