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

c5t-current-schema-ts

v0.2.1

Published

C5T/Current schema common type definitions and validators for TypeScript.

Readme

c5t-current-schema-ts

C5T/Current schema common type definitions and validators for TypeScript.

The library provides compile-time (in TypeScript) and runtime (in io-ts) type definitions for the common primitive and collection types used by the schema definitions generated by the C5T/Current schema export as TypeScript.

Usage

If C5T/Current TypeScript schemas are used, this library is required to be installed as a peer dependency because it is required from the schema files, along with the io-ts library which provides low-level primitives for TypeScript compile-time and runtime type definitions used in the schema files.

npm install --save c5t-current-schema-ts io-ts

NOTE: The schema files specify the recommended versions of c5t-current-schema-ts and io-ts at the top, for example:

// peerDependencies: io-ts@^0.6.1 c5t-current-schema-ts@^0.2.1

The generated TypeScript schema files export two items per CURRENT_STRUCT:

  • a const with a runtime type object created via io-ts interface or union,
  • a compile-time TypeScript type representing that runtime type.

Examples

Type definitions

Given the following C5T/Current type definitions:

CURRENT_STRUCT(Primitives) {
  CURRENT_FIELD(a, uint8_t);
  CURRENT_FIELD_DESCRIPTION(a, "It's the \"order\" of fields that matters.");
  CURRENT_FIELD(b, uint16_t);
  CURRENT_FIELD_DESCRIPTION(b, "Field descriptions can be set in any order.");
  CURRENT_FIELD(c, uint32_t);
  CURRENT_FIELD(d, uint64_t);
  CURRENT_FIELD(e, int8_t);
  CURRENT_FIELD(f, int16_t);
  CURRENT_FIELD(g, int32_t);
  CURRENT_FIELD(h, int64_t);
  CURRENT_FIELD(i, char);
  CURRENT_FIELD(j, std::string);
  CURRENT_FIELD(k, float);
  CURRENT_FIELD(l, double);
  CURRENT_FIELD(m, bool);
  CURRENT_FIELD_DESCRIPTION(m, "Multiline\ndescriptions\ncan be used.");
  CURRENT_FIELD(n, std::chrono::microseconds);
  CURRENT_FIELD(o, std::chrono::milliseconds);
};

CURRENT_VARIANT(MyFreakingVariant, A, X, Y);

The following TypeScript type definitions are generated:

import * as iots from 'io-ts';
import * as C5TCurrent from 'c5t-current-schema-ts';

export const Primitives_IO = iots.interface({
  // It's the "order" of fields that matters.
  a: C5TCurrent.UInt8_IO,

  // Field descriptions can be set in any order.
  b: C5TCurrent.UInt16_IO,
  c: C5TCurrent.UInt32_IO,
  d: C5TCurrent.UInt64_IO,
  e: C5TCurrent.Int8_IO,
  f: C5TCurrent.Int16_IO,
  g: C5TCurrent.Int32_IO,
  h: C5TCurrent.Int64_IO,
  i: C5TCurrent.Char_IO,
  j: C5TCurrent.String_IO,
  k: C5TCurrent.Float_IO,
  l: C5TCurrent.Double_IO,

  // Multiline
  // descriptions
  // can be used.
  m: C5TCurrent.Bool_IO,
  n: C5TCurrent.Microseconds_IO,
  o: C5TCurrent.Milliseconds_IO,
}, 'Primitives');
export type Primitives = iots.TypeOf<typeof Primitives_IO>;

export const MyFreakingVariant_IO = iots.union([
  MyFreakingVariant_VariantCase_A_IO,
  MyFreakingVariant_VariantCase_X_IO,
  MyFreakingVariant_VariantCase_Y_IO,
  iots.null,
], 'MyFreakingVariant');
export type MyFreakingVariant = iots.TypeOf<typeof MyFreakingVariant_IO>;

Type validation

The validate function from io-ts returns a value of the Either type which can be either Right that contains the validated object or Left that contains the error. This Either type and the isRight function to tell Right from Left are defined in the fp-ts module at fp-ts/lib/Either.

WARNING Due to the out-of-memory issues with TypeScript processing fp-ts, as of 2017-08-23 fp-ts is not recommended to be used directly. Use io-ts/lib/PathReporter or io-ts/lib/ThrowReporter with try..catch around it if required.

import * as fs from 'fs';
import * as iots from 'io-ts';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { ThrowReporter } from 'io-ts/lib/ThrowReporter';

import * as generated_schema_ts from './generated_schema_ts';

const generated_schema_serialized: generated_schema_ts.FullTest = JSON.parse(String(fs.readFileSync('./generated_schema_serialized.json')));
const validation_result = iots.validate(generated_schema_serialized, generated_schema_ts.Primitives_IO);

const error_report: string[] = PathReporter.report(validation_result);
// `PathReporter.report` on a succeeded validation returns `[ 'No errors!' ]`.
// `PathReporter.report` on a failed validation returns an array of error messages.

try {
  ThrowReporter.report(validation_result);
  // `ThrowReporter.report` on a succeeded validation is a no-op.
  // `ThrowReporter.report` on a failed validation throws an `Error`.
}
catch (validation_error) {
  //
}

Contribution

Please see C5T/Current guidelines for contribution.