-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
28 lines (26 loc) · 778 Bytes
/
validate.js
File metadata and controls
28 lines (26 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { schema } from "@uniswap/token-lists";
import Ajv from "ajv";
import addFormats from "ajv-formats";
import mainnetsTokenList from "./mauve.tokenlist.mainnets.json";
import testnetsTokenList from "./mauve.tokenlist.testnets.json";
async function validate(tokenList) {
const ajv = new Ajv({ allErrors: true, verbose: true });
addFormats(ajv);
const validator = ajv.compile(schema);
const valid = validator(tokenList);
if (valid) {
return valid;
}
if (validator.errors) {
throw validator.errors.map((error) => {
delete error.data;
return error;
});
}
}
validate(mainnetsTokenList)
.then(console.log("Valid List."))
.catch(console.error);
validate(testnetsTokenList)
.then(console.log("Valid List."))
.catch(console.error);