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

json-to-typing

v0.1.2

Published

[![NPM version](https://img.shields.io/npm/v/json-to-typing.svg)](https://www.npmjs.com/package/json-to-typing) [![Build Status](https://travis-ci.org/atayahmet/json-to-typing.svg?branch=main)](https://travis-ci.org/atayahmet/json-to-typing) [![Coverage S

Downloads

15

Readme

json-to-typing

NPM version Build Status Coverage Status Conventional Commits Standard Version

Transform json data to Typescript type elements. If do not use Typescript and need to cover type of json data, this tool will be helpfuly for you. You can also use in terminal to automate the transfom process as cli command.

Install

Npm:

$ npm i json-to-typing --save

Yarn:

$ yarn add json-to-typing

Examples:

Basic

import jsonToTyping from 'json-to-typing';

jsonToTyping('{"name": "John", "age": 30, "isActive": true}');

Result:

{
  name: string;
  age: number;
  isActive: boolean;
}

Nested

{
  "name": "John",
  "age": 30,
  "isActive": true,
  "books": ["Book 1", "Book 2", "Book 3"],
  "movies": {
    "genres": ["sci-fi", "comedy", "fantastic"],
    "favorite": "The Lord Of The Rings"
  }
}
jsonToTyping(nested);

Result:

{
  name: string;
  age: number;
  isActive: boolean;
  books: [string, string, string];
  movies: {
    genres: [string, string, string];
    favorite: string;
  }
}

CLI

Install Globally

$ npm i -g json-to-typing
$ json2typing --help

Run locally

$ node_modules/.bin/json2typing --help

Run with npx

$ npx json2typing --help

Examples

Basic:

$ json2typing --source '{"name": "John"}'

output:

{
  name: string;
}

Interface Example:

$ json2typing interface IUser --source '{"name": "John"}'

output:

interface IUser {
  name: string;
}

Note: You can use --export flag to add export keyword.

$ json2typing interface IUser --source '{"name": "John"}' --export

output:

export interface IUser {
  name: string;
}

Typing types

| Name | | :-------- | | interface | | declare | | type |

Flags

| Name | Description | | :------- | ----------------------------- | | --source | JSON string or json file path | | --export | Add export keyword | | --help | Show help menu |

Use in CMD Pipeline

$ echo '{"name": "John"}' | json2typing type Member --export

output:

export type Member {
  name: string;
}

Another:

$ cat ./package.json | json2typing declare Package --export

output:

export declare const Package: {
  version: string;
  license: string;
  main: string;
  typings: string;
  bin: {
    json2typing: string;
  };
  files: [string, string];
  engines: {
    node: string;
  };
  scripts: {
    start: string;
    build: string;
  };
  peerDependencies: {};
  husky: {
    hooks: {
      'pre-commit': string;
      'commit-msg': string;
    };
  };
  prettier: {
    printWidth: number;
    semi: boolean;
    singleQuote: boolean;
    trailingComma: string;
  };
  name: string;
  author: string;
  module: string;
  devDependencies: {
    husky: string;
  };
  dependencies: {};
};

Tests

$ npm test

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT