UNPKG

yaml-language-server

Version:
79 lines 2.98 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Red Hat, Inc. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLineOffsets = getLineOffsets; exports.removeDuplicatesObj = removeDuplicatesObj; exports.matchOffsetToDocument = matchOffsetToDocument; exports.isArrayEqual = isArrayEqual; function getLineOffsets(textDocString) { const lineOffsets = []; const text = textDocString; let isLineStart = true; for (let i = 0; i < text.length; i++) { if (isLineStart) { lineOffsets.push(i); isLineStart = false; } const ch = text.charAt(i); isLineStart = ch === '\r' || ch === '\n'; if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') { i++; } } if (isLineStart && text.length > 0) { lineOffsets.push(text.length); } return lineOffsets; } function removeDuplicatesObj(objArray) { const nonDuplicateSet = new Set(); const nonDuplicateArr = []; for (const obj in objArray) { const currObj = objArray[obj]; const stringifiedObj = JSON.stringify(currObj); if (!nonDuplicateSet.has(stringifiedObj)) { nonDuplicateArr.push(currObj); nonDuplicateSet.add(stringifiedObj); } } return nonDuplicateArr; } function matchOffsetToDocument(offset, jsonDocuments) { for (const jsonDoc of jsonDocuments.documents) { if (jsonDoc.internalDocument && jsonDoc.internalDocument.range[0] <= offset && jsonDoc.internalDocument.range[2] >= offset) { return jsonDoc; } } if (jsonDocuments.documents.length === 1) { return jsonDocuments.documents[0]; } return null; } function isArrayEqual(fst, snd) { if (!snd || !fst) { return false; } if (snd.length !== fst.length) { return false; } for (let index = fst.length - 1; index >= 0; index--) { if (fst[index] !== snd[index]) { return false; } } return true; } }); //# sourceMappingURL=arrUtils.js.map