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

@typescript-runtime-schema/transform

v0.3.0

Published

Typescript transform which enriches source code with runtime schema validation

Downloads

10

Readme

@typescript-runtime-schema/transform version

Typescript transform which enriches source code with runtime schema validation

Comparison

There are other packages similar to this one, like typescript-is. The intention of this package is to, in future version, support "schema like" identifiers that will tell the compiler that the runtime value should conform to some constraint so that you can provide contentful validation with your types. Example:

import { is } from '@typescript-runtime-schema/lib'
import { UUID, Maximum, Minimum, Email } from '@typescript-runtime-schema/lib/contentful'

type User = {
  id: string & UUID<'v4'>,
  name: string & Minimum<10> & Maximum<50>,
  email: string & Email
}

const validatePayloadAsUser = (something: any) => {
  return is<User>(something)
}

Disclaimer

Please note that the above example is a draft of what the future API may look like and is subject to change. The "contentful" utility types are not yet implemented as of this version of the package.

Installation

Using npm:

npm install @typescript-runtime-schema/transform

Using yarn:

yarn add @typescript-runtime-schema/transform

Usage

This package exposes a TypeScript transformer factory at @typescript-runtime-schema/factory

Custom typescript transformers is natively supported internally in TypeScript, but is not publically exposed. The current recommended workaround is to replace your typescript compiler with ttypescript which is a TypeScript compiler wrapper that exposes the internal transformers API.

(Please vote here to support transformers out-of-the-box)

ttypescript

For ttypescript installation instructions, please see the ttypescript repo

Add a plugins property to compilerOptions in your tsconfig.json and specify @typescript-runtime-schema/transformer as your transformer:

{
    "compilerOptions": {
        "plugins": [
            { "transform": "@typescript-runtime-schema/transformer" }
        ]
    }
}

Build your typescript project like you previously would, but replace your usage of tsc with ttsc

## Examples:
npx ttsc
# or
./node_modules/.bin/ttsc --project .

ts-node, webpack, Rollup

Please read the instructions of ttypescript for information on how to use it in combination with ts-node, webpack, and Rollup.

Note: This will not work if ts-loader is configured with transpileOnly: true.

Options

There are currently no options supported for this package. Options will be available and exposed in future version of the package.

License

MIT License Copyright (c) 2021 Simon Johansson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.