@typeonly/validator
Advanced tools
Comparing version 1.0.0 to 1.0.1
# @typeonly/validator | ||
## 1.0.1 | ||
### Patch Changes | ||
- 9759c6a: Documentation | ||
- Updated dependencies [9759c6a] | ||
- @typeonly/loader@1.0.1 | ||
## 1.0.0 | ||
@@ -9,2 +17,8 @@ | ||
## 0.6.0 | ||
### Minor Changes | ||
- upgrade dependencies & syntax | ||
### Patch Changes | ||
@@ -20,1 +34,2 @@ | ||
- Improve validation error message (fix) | ||
- @typeonly/loader@0.6.0 |
{ | ||
"name": "@typeonly/validator", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An API to validate JSON data or JavaScript objects, using TypeScript typing definitions.", | ||
"author": "Paroi", | ||
"author": "Paroi Team", | ||
"scripts": { | ||
@@ -18,3 +18,3 @@ "prepublishOnly": "npm run build && npm run test", | ||
"dependencies": { | ||
"@typeonly/loader": "^1.0.0" | ||
"@typeonly/loader": "^1.0.1" | ||
}, | ||
@@ -24,3 +24,3 @@ "devDependencies": { | ||
"rimraf": "^6.0.1", | ||
"typeonly": "^1.0.0", | ||
"typeonly": "^1.0.1", | ||
"typescript": "^5.7.3", | ||
@@ -36,3 +36,3 @@ "vitest": "^3.0.5" | ||
}, | ||
"homepage": "https://github.com/paroi-tech/typeonly/tree/master/validator", | ||
"homepage": "https://github.com/paroi-tech/typeonly/tree/master/packages/validator", | ||
"license": "CC0-1.0", | ||
@@ -44,2 +44,2 @@ "keywords": [ | ||
] | ||
} | ||
} |
@@ -8,51 +8,2 @@ # @typeonly/validator | ||
[TypeOnly](https://github.com/paroi-tech/typeonly/tree/master/typeonly) aims to be the pure typing part of TypeScript. This package provides an API to validate JSON and JavaScript objects with TypeScript definitions, using the TypeOnly parser. | ||
## Tutorial: How to programmatically validate JSON data | ||
At first, it is necessary to follow [the tutorial](https://github.com/paroi-tech/typeonly/blob/master/typeonly/README.md#tutorial-parse-typescript-definitions-with-the-cli) of TypeOnly in order to generate a `.to.json` file based on your TypeScript definitions. After this step, you have the following file: `dist/types.to.json`. | ||
Now, add `@typeonly/validator` to the project: | ||
```sh | ||
npm install @typeonly/validator | ||
``` | ||
Create a file `src/validate-main.js` with the following content: | ||
```ts | ||
// src/validate-main.js | ||
import { readFileSync } from "node:fs" | ||
import { createValidator } from "@typeonly/validator"; | ||
const data = { | ||
color: "green", | ||
shape: { | ||
kind: "circle", | ||
x: 100, | ||
y: 100, | ||
radius: 50 | ||
} | ||
}; | ||
const validator = createValidator({ | ||
bundle: JSON.parse(readFileSync(`./types.to.json`)); | ||
}); | ||
const result = validator.validate("./drawing", "Drawing", data); | ||
console.log(result); | ||
``` | ||
This code validates the `data` object using RTO files generated by the TypeOnly parser. | ||
Execute it: | ||
```sh | ||
$ node src/validate-main.js | ||
{ valid: true } | ||
``` | ||
## Contribute | ||
With VS Code, our recommanded plugin is: | ||
- **Biome** from biomejs (biomejs.dev) | ||
This package is part of **TypeOnly**, a lightweight validation library that uses TypeScript type definitions to validate JSON data. **[Learn more about TypeOnly here](https://www.npmjs.com/package/typeonly)**. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
69171
21
1665
0
0
9
Updated@typeonly/loader@^1.0.1