UNPKG

bc-minecraft-bedrock-project

Version:

The typescript library responsible for reading/parsing minecraft bedrock data

45 lines 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractFunctionId = extractFunctionId; exports.process = process; const bc_minecraft_bedrock_shared_1 = require("bc-minecraft-bedrock-shared"); const types_1 = require("../../../types"); /** * Extracts the function ID from a URI. * The ID is the path relative to the `functions/` directory segment, without * the `.mcfunction` extension and with backslashes normalised to forward slashes. * Returns `undefined` when the URI does not contain a `functions/` segment or * ends with `.json`. * * @param uri The document URI (e.g. `file:///bp/functions/my_folder/my_fn.mcfunction`) * @returns The function ID (e.g. `my_folder/my_fn`), or `undefined` */ function extractFunctionId(uri) { if (uri.endsWith('.json')) return undefined; const index = uri.indexOf('functions'); if (index < 0) return undefined; const id = uri.substring(index + 10).replace(/\\/g, '/').replace(/\.mcfunction$/, ''); return id || undefined; } /** * * @param doc * @returns */ function process(doc) { const uri = doc.uri; let id = extractFunctionId(uri); if (id === undefined) return undefined; if (id.includes(' ') || id.includes('\t')) { id = `"${id}"`; } return { id: id, location: bc_minecraft_bedrock_shared_1.Location.create(uri, 0), documentation: types_1.Documentation.getDoc(doc, () => `Mcfunction: ${id}`), }; } //# sourceMappingURL=process.js.map