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-ts-types

v1.0.3

Published

根据json字符串自动生成TypeScript interface定义

Downloads

3

Readme

json-ts-types

根据 json 字符串自动生成 TypeScript interface 定义

使用方式:

const interfaceDefinition = require('json-ts-types');
const res = interfaceDefinition(json对象||json字符串, {})

参数配置:

方法第二个参数接收一个对象,对象内容如下:

{
  globalExportMode: 1,      // 默认 don't export  1 = don't export 2 =  export 3 = export default
  lineBreak: '\n',          // 换行符
  indent: '  ',             // 缩进 默认两个空格
  interfaceName: 'Result',  // 导出第一级名称
  interfaceNamePrefix: 'I' ,// 接口名称前缀
}

示例:


json字符串

{"rewardable":true,"setting":{"description":"小礼物走一走,来简书关注我","default_amount":200},"total_rewards_count":2,"reward_buyers":[{"avatar":"https://upload.jianshu.io/users/upload_avatars/24980734/6a3c4ca0-a49b-4c04-bd0e-873680f9d299","slug":"7e41f9591579"},{"avatar":"https://cdn2.jianshu.io/assets/default_avatar/2-9636b13945b9ccf345bc98d0d81074eb.jpg","slug":"2b934bfdf859"}]}

结果:

don't export模式

interface IResult {
    rewardable: boolean;
    setting: ISetting;
    total_rewards_count: number;
    reward_buyers: IRewardBuyers[];
}

interface ISetting {
    description: string;
    default_amount: number;
}

interface IRewardBuyers {
    avatar: string;
    slug: string;
}
export 模式

export interface IResult {
    rewardable: boolean;
    setting: ISetting;
    total_rewards_count: number;
    reward_buyers: IRewardBuyers[];
}

export interface ISetting {
    description: string;
    default_amount: number;
}

export interface IRewardBuyers {
    avatar: string;
    slug: string;
}
export default模式

export default interface IResult {
    rewardable: boolean;
    setting: ISetting;
    total_rewards_count: number;
    reward_buyers: IRewardBuyers[];
}

interface ISetting {
    description: string;
    default_amount: number;
}

interface IRewardBuyers {
    avatar: string;
    slug: string;
}