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

core-types-ts

v4.1.0

Published

core-types ⬌ TypeScript interface conversion

Downloads

73,860

Readme

npm version downloads build status coverage status Node.JS version

core-types-ts

This package provides conversion functions between core-types and TypeScript.

You probably don't want to use this package directly, but rather typeconv which uses this package to convert between TypeScript, JSON Schema and GraphQL.

See

Other conversion packages:

Versions

Since 4.0, this package is pure ESM and requires Node 14.13.1 or later.

Contents

Usage

There are two conversion functions, convertCoreTypesToTypeScript and convertTypeScriptToCoreTypes, both returning a wrapped value, of the type ConversionResult.

core-types to TypeScript

import { convertCoreTypesToTypeScript } from 'core-types-ts'

let doc; // This core-types document comes from somewhere

const { data: tsSourceCode } = convertCoreTypesToTypeScript( doc );

You can provide options as a second argument fn the type:

interface ToTsOptions
{
	warn?: WarnFunction;
	filename?: string;
	sourceFilename?: string;
	useUnknown?: boolean;
	declaration?: boolean;
	userPackage?: string;
	userPackageUrl?: string;
	noDisableLintHeader?: boolean;
	noDescriptiveHeader?: boolean;
	namespaces?: 'ignore'| 'dot'| 'underscore'| 'all';
	unsupported?: 'ignore' | 'warn' | 'error';
}

These options are all optional.

  • warn: A function callback to be used for warnings, defaults to console.warn.
  • filename The filename to be written to.This is a hint, no file will be written by the conversion function.
  • sourceFilename: The name of the source file from which the core-types comes.
  • useUnknown: Use unknown rather than any for any-types.
  • declaration: Write a declaration file, where e.g. "export interface" becomes "export declare interface".
  • userPackage: The name of the package using this package.
  • userPackageUrl: The url to the package using this package.
  • noDisableLintHeader: Prevent writing the "disable linting" comment.
  • noDescriptiveHeader: Do no write a top-level descriptive comment about the auto-generated file
  • namespaces: Try to reconstruct namespaces
    • ignore: Don't try to reconstruct namespaces (default)
    • dot: Split names by dot (.) as namespaces for top-level types
    • underscore: Split names by underscore (_) as namespaces for top-level types
    • all: Split by dot (.) and/or underscores (_) as namespaces for top-level types
  • unsupported: What to do when detecting an unsupported type
    • ignore: Ignore (skip) type
    • warn: Ignore type, but warn (default)
    • error: Throw an error

The warn function is of type WarnFunction from core-types, meaning it takes a message as string, and an optional second argument of type CoreTypesErrorMeta, also from core-types.

TypeScript to core-types

import { convertTypeScriptToCoreTypes } from 'core-types-ts'

let sourceCode; // This source code comes from somewhere

const { data: doc } = convertTypeScriptToCoreTypes( sourceCode );

An optional second argument can be provided on the form

interface FromTsOptions
{
	warn?: WarnFunction;
	namespaces?: 'ignore' | 'hoist' | 'join-dot' | 'join-underscore';
	nonExported?: 'fail' | 'ignore' | 'include' | 'inline' | 'include-if-referenced';
	unsupported?: 'ignore' | 'warn' | 'error';
}
  • warn: The same warn function as in CoreTypesToGraphqlOptions
  • namespaces: How to deal with namespaces *ignore: Ignore namespaces entirely (default)
    • hoist: Hoist types inside namespaces to top-level, so that the types are included, but without their namespace. This can cause conflicts, in which case deeper declarations will be dropped in favor of more top-level declarations. Same-level will be exported non-deterministically.
    • join-dot: Join namespaces and types with a dot (.)
    • join-underscore: Join namespaces and types with an underscore (_)
  • nonExported: How to handle references to non-exported types
    • fail: Fail conversion with an Error
    • ignore: Don't include non-exported types, but allow references to them
    • include: Include non-exported types
    • inline: Don't include non-exported types, inline them if necessary.Will throw an Error if the inlined types have cyclic dependencies.
    • include-if-referenced: Include non-exported types only if they are referencedfrom exported types (default)
  • unsupported: What to do when detecting an unsupported type
    • ignore: Ignore (skip) type (default)
    • warn: Ignore type, but warn
    • error: Throw an error