UNPKG

bc-minecraft-bedrock-types

Version:

The typescript library that provides default types for minecraft bedrock

83 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentLocation = void 0; const json_path_1 = require("./json-path"); const offset_word_1 = require("./offset-word"); const position_1 = require("./position"); const range_1 = require("./range"); function ToText(value) { return typeof value === "string" ? value : value.getText(); } /** * */ var DocumentLocation; (function (DocumentLocation) { /**TODO add documentation * * @param data * @param text * @returns */ function toOffset(data, text) { switch (typeof data) { case "number": return data; //Json path case "string": return json_path_1.JsonPath.resolve(text, data); //Position case "object": if (offset_word_1.OffsetWord.is(data)) { return data.offset; } return position_1.Position.toOffset(data, ToText(text)); default: return 0; } } DocumentLocation.toOffset = toOffset; /**TODO add documentation * * @param data * @param text * @returns */ function toPosition(data, text) { switch (typeof data) { case "number": return position_1.Position.toPosition(data, ToText(text)); //Json path case "string": return position_1.Position.toPosition(json_path_1.JsonPath.resolve(text, data), ToText(text)); //Position case "object": if (offset_word_1.OffsetWord.is(data)) { return position_1.Position.toPosition(data.offset, data.text); } return data; default: return position_1.Position.create(0, 0); } } DocumentLocation.toPosition = toPosition; /**TODO add documentation * * @param data * @param text * @param length * @returns */ function ToRange(data, text, length) { if (offset_word_1.OffsetWord.is(data)) { const t = data.text; return range_1.Range.create(position_1.Position.toPosition(data.offset, t), position_1.Position.toPosition(data.offset + t.length, t)); } const startindex = toOffset(data, text); const endindex = startindex + length; const t = ToText(text); return range_1.Range.create(position_1.Position.toPosition(startindex, t), position_1.Position.toPosition(endindex, t)); } DocumentLocation.ToRange = ToRange; })(DocumentLocation || (exports.DocumentLocation = DocumentLocation = {})); //# sourceMappingURL=document-location.js.map