Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Isomorphic types for TS/JS
npm install arktype
If you're using TypeScript, you'll need at least 4.8
Note: This package is under active development. APIs have largely stabilized, but may still change prior to our upcoming 1.0-beta release. Stay tuned!⛵
import { type } from "arktype"
// Define a type...
export const user = type({
name: "string",
device: {
platform: "'android'|'ios'",
"version?": "number"
}
})
// Infer it...
export type User = typeof user.infer
// Validate your data anytime, anywhere, with the same clarity and precision you expect from TypeScript.
export const { data, problems } = user({
name: "Alan Turing",
device: {
platform: "enigma"
}
})
if (problems) {
// "device/platform must be 'android' or 'ios' (was 'enigma')"
console.log(problems.summary)
}
import { scope } from "arktype"
// Scopes are collections of types that can reference each other.
export const types = scope({
package: {
name: "string",
"dependencies?": "package[]",
"contributors?": "contributor[]"
},
contributor: {
// Subtypes like 'email' are inferred like 'string' but provide additional validation at runtime.
email: "email",
"packages?": "package[]"
}
}).compile()
// Cyclic types are inferred to arbitrary depth...
export type Package = typeof types.package.infer
// And can validate cyclic data.
const packageData: Package = {
name: "arktype",
dependencies: [{ name: "typescript" }],
contributors: [{ email: "david@sharktypeio" }]
}
packageData.dependencies![0].dependencies = [packageData]
export const { data, problems } = types.package(packageData)
ArkType supports many of TypeScript's built-in types and operators, as well as some new nes dedicated exclusively to runtime validation. In fact, we got a little ahead of ourselves and built a ton of cool features, but we're still working on getting caught up syntax and API docs. Keep an eye out for more in the next couple weeks! In the meantime, check out the examples from this README and use the type hints you get to learn how you can customize your types and scopes. If you have any questions, don't hesitate to reach out on the dedicated Discord channel!
If you're interested in contributing to ArkType...
This project is licensed under the terms of the MIT license.
FAQs
TypeScript's 1:1 validator, optimized from editor to runtime
The npm package arktype receives a total of 63,550 weekly downloads. As such, arktype popularity was classified as popular.
We found that arktype demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.