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

@primeagen/undefined

v1.0.8

Published

A project to turn a file of JSON responses into TypeScript types

Downloads

12

Readme

undefined

A project to turn a file of JSON responses into TypeScript types

Warning on code

I haven't really tried to organize this code. I made this code strictly as i learned more about the problem space. So the code looks like exploratory code, not production ready code.

To me, it seems like there is going to be a several pass compiler for this to be a real deal here.

I am unsure how much i want to pursue this beyond my needs

My needs have been met, i am unsure if I want to pursue this much further.

If anyone is interested in this, i can certainly help you get ramped up, whisper me twitter

Union Collapsing is really hard...

Its currently disabled because its creating incorrect types. But i think i am pretty dang close to it being correct.

Why create this?

I have a new database at Netflix with +100 unique events without definitions. I will define them...

Here is a reason for why you could use it:

  1. You have too many JSON objects to develop types for other than naming.
  2. You may have enums that need to get pulled out.
  3. You want as compact possible representation

How To Use

  1. Clone

    git clone [email protected]:ThePrimeagen/undefined.git
  2. Dependency installation

    yarn install
  3. Have a file filled with json responses (check out out)

  4. The data can be handed in a few ways

    cat <jsons_here> | npx ts-node src/undefined.ts stdin
    npx ts-node src/undefined.ts <json_here>
  5. You want to save this to a file?

    npx ts-node src/undefined.ts <json_here> > types.d.ts

Enums

You can specify what fields need to be lifted into enums. I make the assumption that enums are likely string values (though there is a case for me to fix this, PRs will be merged with little regard)

npx ts-node src/undefined.ts <json_here> --enums Foo,Bar > types.d.ts

This will take any top level fields on objects and attempt to pull out the values, convert it into an enum, put at top of definitions, and replace their type (usually string) as the enum.

There is an issue

Fix it and make a PR. The code is shitty because I rage wrote it all in ~1 hour on twitch.

ThePrimeagen

Support

Github sponsor or twitch prime babe!