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-schema

v0.7.8

Published

A reflective type model for TypeScript applications

Downloads

78

Readme

TypeScript Schema Library

Overview

A reflective type model for TypeScript applications. There are two primary models:

  • A raw model, which is a serialisable format (consider using typescript-package for the generation of this from a TypeScript package or project). References to types are stored as a {moduleName:string, name:string} object.
  • A fully resolved model, where all references are replaced with actual instances of that type. This is the model most useful for use.

A high level over-view of the modules in this library are:

  • rawConverter: converts raw models to resolved models.
  • model: contains the type meta-model, both for raw and resolved models
  • factories: used by rawConverter. Contains the code for creating resolved model elements
  • equals: contains equality functions for resolved models
  • typeCloser: elements with type-parameters (classes, interfaces, etc.) are treated as type-constructors. To create an actual type, use typeCloser with arguments for the parameters
  • typeUtils: some useful functions for dealing with types
  • serialiserParser: use this to create a more readable serialised form of a raw model (and for parsing that form)
  • filter: used to reduce raw models to complete sub-models based off specific elements (e.g.: filtered to a closed model for a particular module, or class)
  • toString: used to create a unique identifier for various resolved model elements
  • expressionToLiteral: used to convert a resolved expression model into a pure javascript equivalent
  • visitor: used to easily navigate a resolved model

Usage

Install:

npm install typescript-schema

Basic Usage:

import * as s from 'typescript-schema'

let rawModules:s.Map<s.Module>

// Given a raw model, filter its contents to only contain types relevant to and referenced by some module
let filteredModules = s.filterRawModules(['moduleA'], rawModules)

// Given a raw model, convert to a resolved one:
let resolvedModules = s.convertRawModules(rawModules)

// Give a raw model, create a nice text format
let str = s.stringify(rawModules)
// And parse it back into a raw model
rawModules = s.parse(str)

let someInterfaceConstructor:s.InterfaceConstructor
let someTypeForT:s.Type
// Given a type constructor (e.g. interface A<T>), create a type
s.closeInterface(someInterfaceConstructor, [someTypeForT])

// Visit the elements in a model
s.modulesVisitor(resolveModules, {
  onModule: function(module){
    return <s.ModuleVisitor> {
      onClassConstructor: function(cc) {
        // etc
      }
    }
  }
})

// Get the unique id for an element
let id = s.interfaceConstructorToString(someInterfaceConstructor)

let decorator:s.Decorator

// For some expression (e.g. from a decorator)
let pureValue = s.expressionToLiteral(decorator.parameters[0])

let someOtherInterfaceConstructor

// Compare two entities
let isEqual = someInterfaceConstructor.equals(someOtherInterfaceConstructor)