Registry / serialization / geostyler-geojson-parser

geostyler-geojson-parser

JSON →
library2.0.0jsnpmunverified

The `geostyler-geojson-parser` package provides an implementation of the GeoStyler data parser specification specifically for GeoJSON. It enables conversion between standard GeoJSON objects and GeoStyler's internal style representation, facilitating the styling of geographic data. The current stable version is 2.0.0, released recently after a significant architectural change that embraced ECMAScript Modules (ESM). While the project's release cadence has been irregular, v2.0.0 signifies a modernization effort for its module distribution. Key differentiators include its tight integration within the broader GeoStyler ecosystem, offering a consistent API for managing styles across various data formats, and robust handling of diverse GeoJSON structures into a unified style object. It is a fundamental component for applications that need to dynamically style GeoJSON data based on GeoStyler definitions.

npm install geostyler-geojson-parser
INSTALL
IMPORT
SIG · GEOSTYLER-GEOJSON-
G
geostyler-geojson-parser
serializationjavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GeoJsonParser
✓ import { GeoJsonParser } from 'geostyler-geojson-parser';
✗ const GeoJsonParser = require('geostyler-geojson-parser').GeoJsonParser;
Since version 2.0.0, the package primarily exports ESM. CommonJS `require()` syntax for named exports can be problematic or require specific bundler configurations. Use the direct package name, as the internal `dist` path is no longer exposed for direct import.
GeoJsonParser (as default)
✓ import GeoJsonParser from 'geostyler-geojson-parser';
✗ import { GeoJsonParser } from 'geostyler-geojson-parser/dist/GeoJsonParser';
While `GeoJsonParser` is primarily a named export, some tooling or configurations might interpret it as a default. However, direct imports from the 'dist' folder (e.g., `/dist/GeoJsonParser`) are deprecated and will break imports in v2.0.0+.
All exports as namespace
✓ import * as GeoJsonParserModule from 'geostyler-geojson-parser';
✗ const GeoJsonParserModule = require('geostyler-geojson-parser');
This pattern allows access to all named exports, e.g., `GeoJsonParserModule.GeoJsonParser`. The CommonJS `require` call will return the module object but might not correctly expose the ESM exports or might provide an unexpected structure due to the v2.0.0 ESM transition.

This snippet demonstrates how to instantiate the `GeoJsonParser` and use its `readStyle` method to convert a GeoJSON object into a GeoStyler `Style` object, and `writeStyle` for the reverse conversion. This showcases typical usage for styling workflows.

import { GeoJsonParser } from 'geostyler-geojson-parser'; import { Style } from 'geostyler-style'; // GeoStyler-style types are typically needed for parsing output const geoJsonParser = new GeoJsonParser(); const sampleGeoJson = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Example Point", "category": "A" }, "geometry": { "type": "Point", "coordinates": [10.2, 53.5] } }, { "type": "Feature", "properties": { "name": "Example Polygon", "area": 123.45 }, "geometry": { "type": "Polygon", "coordinates": [[[-10, 0], [0, 10], [10, 0], [0, -10], [-10, 0]]] } } ] }; async function parseAndConvertGeoJson() { try { console.log('Attempting to parse GeoJSON...'); // Convert GeoJSON to GeoStyler Style object const geoStylerStyle: Style = await geoJsonParser.readStyle(sampleGeoJson); console.log('Successfully parsed to GeoStyler Style:\n', JSON.stringify(geoStylerStyle, null, 2)); console.log('\nAttempting to convert GeoStyler Style back to GeoJSON...'); // Convert GeoStyler Style object back to GeoJSON const convertedGeoJson = await geoJsonParser.writeStyle(geoStylerStyle); console.log('Successfully converted back to GeoJSON:\n', JSON.stringify(convertedGeoJson, null, 2)); } catch (error) { console.error('Error during GeoJSON parsing or conversion:', error); } } parseAndConvertGeoJson();
Debug
Known issues
breakingVersion 2.0.0 introduces a significant change by moving to an ECMAScript Module (ESM) build. This means `require()` statements in CommonJS environments might no longer work directly, leading to `ERR_REQUIRE_ESM` errors.
fix
Migrate your project to use ES modules (`import`/`export`) or configure your bundler (e.g., Webpack, Rollup) to correctly handle ESM modules. For Node.js, ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions for ESM code.
affects: >=2.0.0
breakingThe internal file structure changed in v2.0.0; all exported files are now located inside the `dist` folder, but direct imports to these paths are deprecated. Direct imports pointing to specific files within `geostyler-geojson-parser/dist/...` paths will now break.
fix
Update your import paths to directly reference the package name, e.g., `import { GeoJsonParser } from 'geostyler-geojson-parser';`. The package exports are now configured to be resolved from the root.
affects: >=2.0.0
gotchaVersion 2.0.0 and later require Node.js version 20.6.0 or higher. Running with older Node.js versions will result in compatibility issues or failures due to engine requirements.
fix
Upgrade your Node.js environment to version 20.6.0 or newer to ensure full compatibility and prevent unexpected runtime errors.
affects: >=2.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import an ESM-only module (`geostyler-geojson-parser@2.0.0+`) in a CommonJS context.
fix
Switch to `import` statements and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` file extensions for files containing `import`/`export`).
Cannot find module 'geostyler-geojson-parser/dist/GeoJsonParser' or its corresponding type declarations.
Incorrect import path after v2.0.0, which deprecated direct access to files within the `dist` folder.
fix
Remove `/dist/GeoJsonParser` from your import path. The correct import should be `import { GeoJsonParser } from 'geostyler-geojson-parser';`.
TypeError: GeoJsonParser is not a constructor
CommonJS `require()` might return the module object directly, rather than the class constructor itself, especially when dealing with mixed ESM/CJS or incorrect default/named export handling after the v2.0.0 transition.
fix
For ESM, use `import { GeoJsonParser } from 'geostyler-geojson-parser';`. If you are strictly in a CommonJS environment, check if a specific CommonJS build is provided or consider a dynamic import (`import('geostyler-geojson-parser')`). Otherwise, ensure you are correctly accessing the named export, e.g., `const GeoJsonParser = require('geostyler-geojson-parser').GeoJsonParser;` (though this might still fail if the package is truly ESM-only for its primary exports).
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Bingbot
1
Resources
geostyler-geojson-parser — npm install geostyler-geojson-parser · libregistry