npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

typeonly

v1.1.3

Published

Parses types and interfaces from TypeScript and stores them as JSON files.

Downloads

807

Readme

TypeOnly

npm Type definitions GitHub

A lightweight library for validating JSON data using TypeScript type definitions.

Getting Started

npm install typeonly --save-dev
npm install @typeonly/validator

Add an entry to the "scripts" section of your package.json (this example uses a typeonly/ directory for input and a dist/ directory for output):

    "typeonly": "typeonly --bundle dist/types.to.json -s ./typeonly"

Create a type file with a .d.ts extension:

// typeonly/my-types.d.ts

export type Task = RedTask | BlueTask;

export interface RedTask {
  color: "red";
  priority: number | "max";
  label: string;
}

export interface BlueTask {
  color: "blue";
  label: string;
}

Important: TypeOnly uses its own parser and implements only a subset of TypeScript. Specifically, generics and template string types are not supported.

Generate the type bundle by running:

npm run typeonly

A new file dist/types.to.json will be generated containing all the type definitions from the input directory. Being a JSON file, the parser is not needed at runtime.

Validating JSON Data (ESM Version)

import { readFileSync } from "node:fs";
import { createValidator } from "@typeonly/validator";

const typeValidator = createValidator({
  bundle: JSON.parse(readFileSync("./dist/types.to.json", "utf-8")),
});

const result1 = typeValidator.validate("Task", {
  color: "red",
  priority: 2,
  label: "My urgent task"
});

console.log(result1); // { valid: true }

const result2 = typeValidator.validate("Task", {
  color: "red",
  priority: "abc",
  label: "My urgent task"
});

console.log(result2); // { valid: false, error: 'Value...' }

The error message looks like:

Value {color: "red", priority: "abc", label: "My urgent ta…"} is not conform to Task: no matching type in: RedTask | BlueTask.
In type 'RedTask', value {color: "red", priority: "abc", label: "My urgent ta…"} is not conform to RedTask.
In property 'priority', value '"abc"' is not conform to union: no matching type in: number | "max".

Validating JSON Data (CommonJS Version)

const { readFileSync } = require("node:fs");

async function main() {
  const { createValidator } = await import("@typeonly/validator");

  // … same code as in the ESM version …
}

main();

Command Line Interface

Compile a typing source file:

npx typeonly --bundle dist/types.to.json --source-dir types

This command generates a compiled file dist/types.to.json.

Available options:

  -h, --help                   Print this help message.
  -o, --output-dir directory   The output directory (optional).
  -s, --source-dir directory   The source directory (optional when used with option --ast or with a single source file).
  -e, --encoding string        Encoding for input and output file(s) (default is utf8).
  -b, --bundle string          Generate a bundle file for RTO data (optional).
  --prettify                   Prettify RTO files (optional).
  --ast                        Generate AST files instead of RTO files (optional).
  --src file ...               Input files to process (by default at last position).

Using as a Library

Install as a dependency:

npm install typeonly --save-dev

Then, use it:

import { generateRtoModules } from "typeonly";

const bundle = await generateRtoModules({
  modulePaths: ["./file-name"],
  readFiles: {
    sourceDir: `../types`
  },
  returnRtoModules: true
}).catch(console.log);