The `vega-schema-url-parser` package provides a utility function designed to extract the library type (either "vega" or "vega-lite") and its corresponding version number from a given Vega or Vega-Lite JSON schema URL. This functionality is crucial for applications that programmatically need to identify and validate Vega/Vega-Lite specifications, as the `$schema` field in these specifications often points to URLs like `https://vega.github.io/schema/vega-lite/v5.json` or `https://vega.github.io/schema/vega/v5.19.0.json`. The parser simplifies the process of interpreting these schema URLs, making it easier for tools such as `vega-embed` to determine the correct rendering or parsing mode, and for development environments to offer accurate schema validation and autocompletion features. The current stable version is 3.0.2, with its release cadence generally aligning with major updates to the broader Vega and Vega-Lite ecosystems. Its key differentiator is its highly focused purpose, offering a reliable and standardized method for interpreting schema URLs without requiring complex manual string manipulation, which is a common footgun for developers parsing these URLs directly.
npm install vega-schema-url-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `parseSchemaUrl` function to extract the library type and version from various valid Vega and Vega-Lite schema URLs, as well as how it gracefully handles malformed or unrecognized inputs by returning `null` values.
Migrate to ESM `import` statements (e.g., `import parseSchemaUrl from 'vega-schema-url-parser';`) or configure your build system (e.g., Webpack, Rollup, Node.js `--experimental-loader`) to handle ESM imports in CJS contexts.
Always check the `library` and `version` properties of the returned object for `null` before attempting to use them, especially with user-provided URLs. Example: `const { library, version } = parseSchemaUrl(url); if (library && version) { /* use them */ }`If you need the *resolved* latest version for a major/minor schema URL, you would typically need to fetch the content of the `$schema` URL and inspect the actual schema for its full version, or consult the Vega/Vega-Lite documentation for version mappings. This parser provides the version as it appears in the URL path.
Use ESM syntax: `import parseSchemaUrl from 'vega-schema-url-parser';`. If in Node.js CJS, you might need dynamic import `const { default: parseSchemaUrl } = await import('vega-schema-url-parser');` or configure Node.js to handle ESM.Ensure you are importing the default export correctly: `import parseSchemaUrl from 'vega-schema-url-parser';`
Add the necessary import statement: `import parseSchemaUrl from 'vega-schema-url-parser';` at the top of your file.
No dependency data recorded yet.