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

@barelyhuman/typeable

v0.1.8

Published

> a on-the-fly type generator for objects in node

Downloads

21

Readme

typeable

a on-the-fly type generator for objects in node

Warning: This will not really work in a browser, it expects a filesystem

Installation

Install @barelyhuman/typeable with npm

  npm install @barelyhuman/typeable

What and Why

It's a generator for object interfaces. I have a project that I'm working on which has a ton of shared objects being defined during development, this makes it hard to keep track of what all was defined on the object.

Typescript has cross file inference but still doesn't help with dynamically defined properties so this helps generate a declarations file that stores all the properties added to the object. There's definite knick knacks that can be fixed.

Note: This is a subset requirement for one of my packages and might not be something you need for your day to day development. The generator's goal is to be able to generate types at runtime while in development.

Note: If the NODE_ENV is set to production, the type generator will not run.

Usage

const { createTypeable } = require('@barelyhuman/typeable')

/**
 * @type {import("./typeable").App}
 */

const app = createTypeable(
  {}, // an empty object or reference to an object to be read
  {
    outfile: 'typeable.d.ts', // output path for the generated declaration file
    rootInterfaceName: 'App', // the interface name to be generated for the above object.
  }
)

// add in properties, functions, methods, etc to the new typeable object.
app.property = {}
app.property.method = function () {}
// typeable.d.ts
export interface App {
  property: property
}

interface property {
  // generated generic functions right now
  method: (...args: any[]) => any
}

Caveats

  • Cannot handle kebab-case or spaced keys and will ignore them altogether
  • Cannot infer the type of arguments from a function

License

MIT