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

gulp-json-to-tsd

v0.9.6

Published

A gulp plugin to generate typescript definition file that represents a shape of JSON

Downloads

3

Readme

gulp-json-to-tsd

A gulp plugin to generate typescript definition file that represents a shape of JSON

For each JSON file a typescript interface will be generated that represents a shape of a JSON. Name of an interface is based on JSON file name. E.g. UserGroup interface (or IUserGroup, see below) will be generated for any of file names: user-group.json, user_group.json, userGroup.json, UserGroup.json.

Please, note that only basic latin letters and digits are currently supported. Any other character are ignored.

Install

$ npm install --save-dev gulp-json-to-tsd

Usage

const gulp = require('gulp');
const jsonToTsd = require('gulp-json-to-tsd');

gulp.task("default", () => {
	gulp.src("src/foo.json")
		.pipe(jsonToTsd())
		.pipe(gulp.dest("dist"))
);

Let's assume that src/foo.json has the following contents:

{
	"foo": "Lorem ipsum sid amet",
	"bar": 7009,
	"baz": {
		"fizz": null,
		"buzz": false
	}
}

Then by default plugin will generate the following definition:

declare interface Foo {
	"foo": string;
	"bar": number;
	"baz": {
		"fizz": null|undefined;
		"buzz": boolean;
	};
}

If we switch on namespaces and variable declarations (see options below), we will get:

declare namespace example {
	interface Foo {
		"foo": string;
		"bar": number;
		"baz": {
			"fizz": null|undefined;
			"buzz": boolean;
		};
	}
}
declare const foo: example.Foo;

API

jsonToTsd([options])

options

useInterfacePrefix

Type: boolean Default: false

If true, all interfaces will be prefixed with I letter. Let's assume that we have user-group.json file. Then if useInterfacePrefix = true, an IUserGroup interface will be generated. And if useInterfacePrefix = false, an interface will be UserGroup.

namespace

Type: string | undefined Default: undefined

If specified, all interface declarations will be put into namespace with a given name.

declareVariable

Type: boolean Default: false

Specifies if a variable of a generated interface must be declared. A declaration is put after an interface out of a namespace block (if any).

identStyle

Type: "tab" | "space" Default: "tab"

Specifies identiation style.

identSize

Type: number Default: 1

Specifies how many tabs/spaces will be used for one level of identiation.

License

MIT © 2017 Roman Liberov