@@ -6,7 +6,7 @@ See the [STAC Validator Comparison](COMPARISON.md) for the features supported by
66
77## Versions
88
9- ** Current version:** 2.0.0-beta.18
9+ ** Current version:** 2.0.0-rc.1
1010
1111| STAC Node Validator Version | Supported STAC Versions |
1212| --------------------------- | ----------------------- |
@@ -17,15 +17,22 @@ See the [STAC Validator Comparison](COMPARISON.md) for the features supported by
1717
1818## Quick Start
1919
20- 1 . Install a recent version of [ node and npm] ( https://nodejs.org )
20+ Two options:
21+
22+ 1 . Go to [ check-stac.moregeo.it] ( https://check-stac.moregeo.it ) for an online validator.
21232 . ` npx stac-node-validator /path/to/your/file-or-folder ` to temporarily install the library and validate the provided file for folder. See the chapters below for advanced usage options.
2224
23- ## Setup
25+ ## Usage
2426
25- 1 . Install [ node and npm] ( https://nodejs.org ) - should run with any version >= 22.1.0.
26- 2 . ` npm install -g stac-node-validator ` to install the library permanently
27+ ### CLI
2728
28- ## Usage
29+ Install a recent version of [ node] ( https://nodejs.org ) (>= 22.1.0) and npm.
30+
31+ Then install the CLI on your computer:
32+
33+ ``` bash
34+ npm install -g stac-node-validator
35+ ```
2936
3037- Validate a single file: ` stac-node-validator /path/to/your/file.json `
3138- Validate multiple files: ` stac-node-validator /path/to/your/catalog.json /path/to/your/item.json `
@@ -49,136 +56,139 @@ Further options to add to the commands above:
4956** Note on API support:** Validating lists of STAC items/collections (i.e. ` GET /collections ` and ` GET /collections/:id/items ` ) is partially supported.
5057It only checks the contained items/collections, but not the other parts of the response (e.g. ` links ` ).
5158
52- ## Browser Usage
59+ You can also pass a config file via the ` --config ` option. Simply pass a file path as value.
60+ Parameters set via CLI will not override the corresponding setting in the config file.
5361
54- The validator is also available as a browser bundle that can be used directly in web browsers without Node.js.
62+ The config file uses the same option names as above.
63+ To specify the files to be validated, add an array with paths.
64+ The schema map is an object instead of string separated with a ` = ` character.
5565
56- ### Installation
66+ ### Programmatic
5767
58- #### CDN (Recommended)
68+ You can also use the validator programmatically in your JavaScript/NodeJS applications.
5969
60- ``` html
61- <script src =" https://github.com/moregeo-it/stac-node-validator/releases/latest/download/index.js" ></script >
70+ Install it into an existing project:
71+
72+ ``` bash
73+ npm install stac-node-validator
6274```
6375
64- #### Download
76+ #### For browsers
6577
66- Download the ` index.js ` file from the [ latest release ] ( https://github.com/moregeo-it/stac-node-validator/releases/latest ) and include it in your HTML :
78+ Then in your code, you can for example do the following :
6779
68- ``` html
69- <script src =" ./path/to/index.js" ></script >
80+ ``` javascript
81+ const validate = require (' stac-node-validator' );
82+
83+ // Add any options, e.g. strict mode
84+ const config = {
85+ strict: true
86+ };
87+
88+ // Validate a STAC file from a URL
89+ const result = await validate (' https://example.com/catalog.json' , config);
90+
91+ // Check if validation passed
92+ if (result .valid ) {
93+ console .log (' STAC file is valid!' );
94+ } else {
95+ console .log (' STAC file has errors:' );
96+ }
7097```
7198
72- ### Browser Usage Example
99+ #### For NodeJS
73100
74- ``` html
75- <!DOCTYPE html>
76- <html >
77- <head >
78- <script src =" https://github.com/moregeo-it/stac-node-validator/releases/latest/download/index.js" ></script >
79- </head >
80- <body >
81- <script >
82- // Create validator instance
83- const validator = new STACValidator ();
84-
85- // Example STAC catalog
86- const stacCatalog = {
87- " stac_version" : " 1.0.0" ,
88- " type" : " Catalog" ,
89- " id" : " example-catalog" ,
90- " title" : " Example Catalog" ,
91- " description" : " This is an example catalog" ,
92- " links" : [
93- {
94- " rel" : " self" ,
95- " href" : " ./catalog.json"
96- }
97- ]
98- };
99-
100- // Validate the STAC object
101- validator .validate (stacCatalog).then (report => {
102- console .log (' Validation result:' , report);
103- console .log (' Is valid:' , report .valid );
104- if (! report .valid ) {
105- console .log (' Errors:' , report .messages );
106- }
107- }).catch (error => {
108- console .error (' Validation error:' , error);
109- });
110- </script >
111- </body >
112- </html >
101+ ``` javascript
102+ const validate = require (' stac-node-validator' );
103+ const nodeLoader = require (' stac-node-validator/src/loader/node' );
104+
105+ // Add any options
106+ const config = {
107+ loader: nodeLoader
108+ };
109+
110+ // Validate a STAC file from a URL
111+ const result = await validate (' https://example.com/catalog.json' , config);
112+
113+ // Check if validation passed
114+ if (result .valid ) {
115+ console .log (' STAC file is valid!' );
116+ } else {
117+ console .log (' STAC file has errors:' );
118+ }
113119```
114120
115- See [ example.html ] ( ./example.html ) for a complete working example.
121+ #### Validation Results
116122
117- ### API
118-
119- The browser version exposes the same API as the Node.js version:
123+ The ` validate ` function returns a ` Report ` object with the following structure:
120124
121125``` javascript
122- // Create validator with options
123- const validator = new STACValidator ({
124- schemas: ' https://schemas.stacspec.org/v1.0.0' , // optional
125- strict: false , // optional
126- // Note: some options like custom loaders may not work in browser
127- });
128-
129- // Validate a STAC object
130- validator .validate (stacObject).then (report => {
131- // Handle validation result
132- });
126+ {
127+ id: " catalog.json" , // File path or STAC ID
128+ type: " Catalog" , // STAC type (Catalog, Collection, Feature)
129+ version: " 1.0.0" , // STAC version
130+ valid: true , // Overall validation result
131+ skipped: false , // Whether validation was skipped
132+ messages: [], // Info/warning messages
133+ children: [], // Child reports for collections/API responses
134+ results: {
135+ core: [], // Core schema validation errors
136+ extensions: {}, // Extension validation errors (by schema URL)
137+ custom: [] // Custom validation errors
138+ },
139+ apiList: false // Whether this is an API collection response
140+ }
133141```
134142
135- ### Config file
143+ ### Browser
136144
137- You can also pass a config file via the ` --config ` option. Simply pass a file path as value.
138- Parameters set via CLI will not override the corresponding setting in the config file.
145+ The validator is also available as a browser bundle for client-side validation.
139146
140- The config file uses the same option names as above.
141- To specify the files to be validated, add an array with paths.
142- The schema map is an object instead of string separated with a ` = ` character.
147+ #### CDN Usage
148+
149+ ``` html
150+ <!-- Include axios for HTTP requests -->
151+ <script src =" https://cdn.jsdelivr.net/npm/axios@1/dist/axios.min.js" ></script >
152+ <!-- Include the STAC validator bundle -->
153+ <script src =" https://cdn.jsdelivr.net/npm/stac-node-validator@2/dist/index.js" ></script >
154+
155+ <script >
156+ // The validator is available as a global 'validate' function
157+ async function validateSTAC () {
158+ const stacData = {
159+ " stac_version" : " 1.0.0" ,
160+ " type" : " Catalog" ,
161+ " id" : " my-catalog" ,
162+ " description" : " A sample catalog" ,
163+ " links" : []
164+ };
165+
166+ const result = await validate (stacData);
167+
168+ if (result .valid ) {
169+ console .log (' STAC is valid!' );
170+ } else {
171+ console .log (' Validation errors:' , result .results .core );
172+ }
173+ }
174+
175+ validateSTAC ();
176+ </script >
177+ ```
143178
144- ### Development
179+ ## Development
145180
1461811 . ` git clone https://github.com/moregeo-it/stac-node-validator ` to clone the repo
1471822 . ` cd stac-node-validator ` to switch into the new folder created by git
1481833 . ` npm install ` to install dependencies
1491844 . Run the commands as above, but replace ` stac-node-validator ` with ` node bin/cli.js ` , for example ` node bin/cli.js /path/to/your/file.json `
150185
151- #### Browser Bundle Development
152-
153- To work on the browser bundle:
154-
155- 1 . ` npm run build:dev ` - Build the bundle in development mode
156- 2 . ` npm run serve ` - Start a local server to test the bundle
157- 3 . Open ` http://localhost:8080/example.html ` in your browser to test the bundle
158- 4 . ` npm run build ` - Build the production bundle
159-
160- The browser bundle is built using Webpack and includes polyfills for Node.js modules to ensure compatibility with browsers.
161-
162- ### Test
186+ ### Tests
163187
164188Simply run ` npm test ` in a working [ development environment] ( #development ) .
165189
166- If you want to disable tests for your fork of the repository, simply delete ` .github/workflows/test.yaml ` .
167-
168- ### Release Process
169-
170- The project uses GitHub Actions for automated releases:
171-
172- 1 . ** Testing** : All pull requests and pushes to master trigger the test suite across multiple Node.js versions and operating systems.
173- 2 . ** Browser Bundle Testing** : The test suite also validates that the browser bundle can be built successfully.
174- 3 . ** Release** : When a new tag is pushed (format: ` v* ` ), the release workflow automatically:
175- - Runs all tests
176- - Builds the browser bundle
177- - Creates a GitHub release with the browser bundle as an asset
178- - Publishes the package to npm
190+ ### Browser Bundle
179191
180- To create a new release:
192+ To work on the browser bundle build it: ` npm run build `
181193
182- 1 . Update the version in ` package.json `
183- 2 . Create and push a git tag: ` git tag v2.0.0-beta.19 && git push origin v2.0.0-beta.19 `
184- 3 . The release workflow will automatically handle the rest
194+ Then you can import it from the ` dist ` folder.
0 commit comments