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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-to-io

v0.3.1

Published

Converts TypeScript type and interface definitions into [io-ts](https://github.com/gcanti/io-ts) type validators.

Downloads

21,885

Readme

ts-to-io

Converts TypeScript type and interface definitions into io-ts type validators.

Usage

As a script

$ npm install -g ts-to-io
$ ts-to-io file.ts

or

$ npx ts-to-io file.ts

From code

NOTE: The validator generation is not intended to be performed at runtime. You should first generate the validators locally and then include them in the program source.

import { getValidatorsFromString } from "ts-to-io"

const sourceString = `
  type Person = { name: string; age: number | null }
`

const validators = getValidatorsFromString(sourceString)

Configuration

ts-to-io supports the following config options

| Key | CLI opt | Default | Description | |-----------------|-----------------------|---------|----------------------------------------------------| | followImports | --follow-imports | false | output codecs for types declared in imported files | | includeHeader | --no-include-header | true | omit io-ts import from the output |

Supported types

| Type | Supported | TypeScript | codec | |-----------------|-----------|------------------------------------|---------------------------------| | string | ✅ | string | t.string | | number | ✅ | number | t.number | | boolean | ✅ | boolean | t.boolean | | null | ✅ | null | t.null | | undefined | ✅ | undefined | t.undefined | | void | ✅ | void | t.void | | any, unknown | ✅ | any, unknown | t.unknown | | array | ✅ | Array<A> | t.array(A) | | record | ✅ | Record<K, A> | t.record(K, A) | | object type | ✅ | { name: string } | t.type({ name: t.string }) | | interface | ✅ | interface I { name: string } | t.type({ name: t.string }) | | literal | ✅ | 'ABC' | t.literal('ABC') | | partial | ✅ | Partial<{ name: string }> | t.partial({ name: t.string }) | | readonly | ❌ | Readonly<A> | - | | readonly array | ❌ | ReadonlyArray<A> | - | | tuple | ✅ | [ A, B ] | t.tuple([ A, B ]) | | tuple with rest | ❌ | [ A, B, ...C ] | - | | union | ✅ | A \| B | t.union([ A, B ]) | | intersection | ✅ | A & B | t.intersection([ A, B ]) | | keyof | ❌ | keyof M | - | | recursive type | ❌ | type Node = { children: Node[] } | - | | function | ✅ | type fn = () => string | t.Function |