// loaders.gl, MIT license import { XMLLoader } from '@loaders.gl/xml'; /** * Parses a typed data structure from raw XML for `GetCapabilities` response * @note Error handlings is fairly weak */ export function parseWFSCapabilities(text, options) { // Remove namespaces in XML options = { ...options, xml: { ...options?.xml, removeNSPrefix: true } }; const parsedXML = XMLLoader.parseTextSync?.(text, options); const xmlCapabilities = parsedXML.Capabilities || parsedXML; return uncapitalizeKeys(xmlCapabilities); } /** Uncapitalize all keys of an object */ function uncapitalizeKeys(object) { if (object && typeof object === 'object') { const newObject = {}; for (const [key, value] of Object.entries(object)) { newObject[uncapitalize(key)] = uncapitalizeKeys(value); } return newObject; } return object; } /** Uncapitalize first letter of a string */ function uncapitalize(str) { return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str; }