arktype
How to use ArkType, a validation library for TypeScript.
How do I install this agent skill?
npx skills add https://github.com/robot-inventor/agent-skills --skill arktypeIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill provides comprehensive documentation and usage examples for the ArkType validation library in TypeScript. No malicious patterns, data exfiltration, or security vulnerabilities were detected.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
ArkType
ArkType is a library that allows you to validate values using a notation very similar to that of TypeScript type definitions.
Basic usage
import { type } from "arktype";
const User = type({
name: "string",
platform: "'android' | 'ios'",
email: "string.email",
score: "number.integer <= 100",
"versions?": "(number | string)[]",
details: {
// nested definitions don't need to be wrapped
"['devices' | 'apps']": "string[]"
},
areWeCoolYet: "boolean = true"
});
// extract the type if needed
type User = typeof User.infer;
const out = User(value);
if (out instanceof type.errors) {
console.error(out.summary);
} else {
console.log(`Hello, ${out.name}`);
}
// throws an error if the value is invalid.
const user = User.assert(value);
// `.allows()` is a type guard and does not apply morphs or transformations
if (User.allows(value)) {
console.log("value is correct");
}
Note: Object types allow and preserve undeclared properties by default. Use "+": "reject" to reject them or "+": "delete" to strip them.
Optional properties
Optional properties does not implicitly allow undefined as a value.
const User = type({
// `name` may be absent
"name?": "string",
// `value` is required, but may be undefined
value: "string | undefined",
// `label` may be absent or explicitly undefined
"label?": "string | undefined"
});
Constraints
// you can add non-standard constraints with `.narrow()`
const Odd = type("number").narrow((n, ctx) => (n % 2 === 0 ? ctx.mustBe("odd") : true));
Builtin keywords
For example, you can represent a URL-formatted string with type("string.url"), and you can morph it into a URL object while performing validation using type("string.url.parse"). For all built-in primitives and keywords, refer to the documentation: https://arktype.io/docs/keywords
Regex
const User = type({
birthday: "x/^(?<month>\\d{2})-(?<day>\\d{2})-(?<year>\\d{4})$/"
});
const data = User.assert({ birthday: "05-21-1993" });
// fully type-safe
data.birthday.groups.month; // "05"
data.birthday.groups.day; // "21"
data.birthday.groups.year; // "1993"
If you don't need the full features of ArkType and only want to use type-safe regular expressions, you can use ArkRegex.
import { regex } from "arkregex";
// RegExp-compatible
const semver = regex("^(\\d+)\\.(\\d+)\\.(\\d+)$");
Morphs & JSON
const morphed = type("string").pipe((s) => s.trim());
const parseJson = type("string.json.parse").to({
version: "string.semver"
});
const out = parseJson('{ "version": "2.0.0" }');
Recursive Types
import { scope } from "arktype";
const userScope = scope({
User: {
id: "string",
friends: "User[]"
},
UsersById: {
"[string]": "User | undefined"
}
});
const userModule = userScope.export();
const out = userModule.User(value);
Creating validators and types from variables
// `as const` is required
const allowedValues = ["foo", "bar", "baz"] as const;
const AllowedValue = type.enumerated(...allowedValues);
// "foo" | "bar" | "baz"
type AllowedValue = typeof AllowedValue.infer;
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/robot-inventor/agent-skills/arktype">View arktype on skillZs</a>