npm.io
3.0.1 • Published 4 years agoCLI

@incmix/ts.runtime

Licence
ISC
Version
3.0.1
Deps
3
Size
105 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

ts.runtime

This tool converts TypeScript types into TS Runtime objects.

Usage - via CLI

Install it globally:

npm i ts.runtime -g

We have this file:

// test/test.ts
export type Type = string | 4 | 2 | boolean;

To convert the type in the file above, we do this:

ts.runtime test/test.ts

This generates the TS Runtime objects from the types in the file and prints them:

export type Type = string | 4 | 2 | boolean;

export type TsRuntimeObject_Type = {
  type: "union";
  members: [
    { type: "string" },
    { type: "number"; value: 4 },
    { type: "number"; value: 2 },
    { type: "boolean" }
  ];
};

Usage - via programmatic interface

You can use ts.runtime in your projects.

npm i ts.runtime

In our project, we import generateTSRuntimeObjectFromFile from ts.runtime:

import { generateTSRuntimeObjectFromFile } from "ts.runtime";

const tsRuntimeObject = generateTSRuntimeObjectFromFile("test/test.ts");