agentleFS
Robot-InventorRobot-Inventor/agent-skills/skills/arktype/SKILL.md

ArkType

Skill3 starsChanged 3 months agoMITView on GitHub

This skill explains how to use ArkType, a validation library for TypeScript. Read this skill when writing validation logic using ArkType.

  • Installs packages

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If ArkType is not yet present in the project's dependencies, you can install it with npm install arktype.

    line 15
  2. Distinctive:

    If you don't need the full features of ArkType and only want to use type-safe regular expressions, you can use ArkRegex.

    line 100

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

ArkType

This skill explains how to use ArkType, a validation library for TypeScript. Read this skill when writing validation logic using ArkType. ArkType is a library that allows you to validate values ​​using a notation very similar to that of TypeScript type definitions.

Installation

If ArkType is not yet present in the project's dependencies, you can install it with npm install arktype. If the project uses a package manager other than npm, use that instead.

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

In ArkType, 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;

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.