UNPKG

@microsoft.azure/autorest.incubator

Version:
67 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const js_yaml_1 = require("js-yaml"); const propertyPriority = [ "schemas", "name", "type", "format", "schema", "operationId", "path", "method", "description" ]; const propertyNegativePriority = [ "callbacks", "http", "commands", "operations", "extensions", "details" ]; function sortWithPriorty(a, b) { if (a == b) { return 0; } const ia = propertyPriority.indexOf(a); const ib = propertyPriority.indexOf(b); const na = propertyNegativePriority.indexOf(a); const nb = propertyNegativePriority.indexOf(b); const dota = `${a}`.startsWith("."); const dotb = `${b}`.startsWith("."); if (dota) { if (!dotb) { return 1; } } else { if (dotb) { return -1; } } if (na > -1) { if (nb > -1) { return na - nb; } return 1; } if (nb > -1) { return -1; } if (ia != -1) { return ib != -1 ? ia - ib : -1; } return ib != -1 || a > b ? 1 : a < b ? -1 : 0; } async function deserialize(text, filename) { return js_yaml_1.safeLoad(await text, { filename: filename, }); } exports.deserialize = deserialize; function serialize(model) { return js_yaml_1.dump(model, { sortKeys: sortWithPriorty, schema: js_yaml_1.DEFAULT_SAFE_SCHEMA, skipInvalid: true }); } exports.serialize = serialize; //# sourceMappingURL=yaml.js.map