UNPKG

@multiplayer-app/session-recorder-common

Version:
50 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _toJsonSchema = require("to-json-schema"); // @ts-ignore const toJsonSchema = (_toJsonSchema === null || _toJsonSchema === void 0 ? void 0 : _toJsonSchema.default) || _toJsonSchema; const defaultSchemifyOptions = { strings: { preProcessFnc: (value, defaultFnc) => { if ((value === null || value === void 0 ? void 0 : value.length) >= 30) { return defaultFnc('some_string'); } return defaultFnc(value); }, }, arrays: { mode: 'first', }, }; exports.default = (payload, stringify = true, options = defaultSchemifyOptions) => { if (!payload) { return ''; } let payloadJson; if (typeof payload === 'string') { try { payloadJson = JSON.parse(payload); } catch (_a) { return payload; } } else if (typeof payload === 'object') { payloadJson = payload; } else { return payload; } try { const schema = toJsonSchema(payloadJson, options); if (stringify) { return JSON.stringify(schema); } return schema; } catch (err) { // error can happen when array has items like ['test', 'asd', '1'], type for '1' is null return ''; } }; //# sourceMappingURL=schemify.js.map