File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,33 @@ Other schemas:
3030- [ Transform] ( https://sruenwg.github.io/topojson-validation/schemas/draft-07/Transform.json )
3131
3232
33+ ## Usage
34+
35+ To use the schemas, either install the package from npm (` npm install @sruenwg/topojson-schema ` ) or fetch the schemas from the links above.
36+ Make sure your validator supports JSON Schema draft-07.
37+
38+ For instance, using Ajv:
39+ ``` ts
40+ import Ajv from ' ajv' ;
41+ import { Topology as installedSchema } from ' @sruenwg/topojson-schema/draft-07' ;
42+
43+ const ajv = new Ajv ();
44+ const myTopology = {
45+ type: ' Topology' ,
46+ objects: {... },
47+ arcs: [... ],
48+ };
49+
50+ // Using schema from installed topojson-schema package
51+ let isTopology = ajv .validate (installedSchema , myTopology );
52+
53+ // Using schema from URL
54+ const fetchedSchema = await fetch (' https://sruenwg.github.io/topojson-validation/schemas/draft-07/Topology.json' )
55+ .then ((res ) => res .json ());
56+ isTopology = ajv .validate (fetchedSchema , myTopology );
57+ ```
58+
59+
3360## Limitations
3461
3562Some requirements of the TopoJSON specification are not fully validated by these schemas, in part due to the difficulty of performing complex validation via JSON Schema.
Original file line number Diff line number Diff line change @@ -5,6 +5,31 @@ This package provides [Valibot](https://valibot.dev/) schemas for validating [To
55Schemas and their inferred types are provided for each constituent part of the TopoJSON format.
66
77
8+ ## Usage
9+
10+ Simply use the schemas like any other Valibot schema.
11+ ``` ts
12+ import * as v from ' valibot' ;
13+ import { TopologySchema } from ' @sruenwg/topojson-valibot' ;
14+
15+ const myTopology = {
16+ type: ' Topology' ,
17+ objects: {... },
18+ arcs: [... ],
19+ };
20+ const isTopology = v .safeParse (TopologySchema , myTopology ).success ;
21+ ```
22+
23+ Types inferred from the schemas are also exported for convenience.
24+ ``` ts
25+ import type { Position } from ' @sruenwg/topojson-valibot' ;
26+
27+ function truncateDimensions(pos : Position ) {
28+ ...
29+ }
30+ ```
31+
32+
833## Limitations
934
1035Some requirements of the TopoJSON specification are not fully validated by these schemas.
You can’t perform that action at this time.
0 commit comments