New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@typeonly/validator

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typeonly/validator - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

bundle-tsd/bundle-tsd.js

15

CHANGELOG.md
# @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

12

package.json
{
"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)**.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc