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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lhint

v1.0.2

Published

__Learn the Hints__

Downloads

266

Readme

lhint

Learn the Hints

A utility that automatically "learns" type hints from any data.

How it works

lhint implements its own type hint shape, everyting else is just transformations between the lhint hint shape and other shapes.
An illustration because I'm bad at explaining things:

Input -> lhint -> types -> desired-output / transformation

A more concrete example

Let's say you're building an app and you're working with some external API for fetching weather information,
this API unfortunately doesn't have very good documentation.
You can then use lhint to automatically generate types, just by giving it some samples of an API endpoint:

import { hints, TypescriptTemplateTransformer } from 'lhint';

const req = await fetch('https://the-weather-api-foobar/api');
const resp = await req.json(); // let's say this is an array of some unknown objects
const typescriptTypes = TypescriptTemplateTransformer.transform(hints.auto(resp));
console.log(typescriptTypes); // A string containing the typescript types that you can copy-paste and save somewhere.

Install

npm install lhint

API Interface

Examples

Learned hints

import { hints } from 'lhint';

// The following automatically "learns" the types
const hint = hints.auto({
  firstname: 'john',
  lastname: 'doe'
})
// And this will give the same as manually doing this:
const myHint = hints.mapping({
  firstname: hints.string(),
  lastname: hints.string()
});

Transforming

These transformations are currently available:

  • typescript-template (generates typescript types in the form of a string)
  • json-schema (generates json-schema objects)
Example
import { hints, TypescriptTemplateTransformer } from 'lhint';

const hint = hints.auto({
  firstname: 'john',
  lastname: 'doe',
  friend: hints.optional(hints.mapping({
    name: hints.string()
  }))
});

const ts: string = TypescriptTemplateTransformer.transform(hint);
/* 
  {
    firstname: string,
    lastname: string,
    friend?: {
      name: string
    }
  }
*/

Basic hint usage

import { hints } from 'lhint';

const name = hints.string();
const age = hints.number();
const happy = hints.boolean();
const dateOfBirth = hints.date();
const userType = hints.union([hints.literal('admin'), hints.literal('developer')]);

const flags = hints.record(hints.string(), hints.boolean());

const car = hints.mapping({
  brand: hints.string(),
  color: hints.optional(hints.string()),
  price: hints.number(),
});

// "Extract" the typescript type of a hint
const myCar: UnHint<typeof car>;
/**
  This will give the following type:
  {
    brand: string,
    color?: string,
    price: number
  }
*/

CLI

Available commands:

  • transform
  • hint

transform

args:

  • source (a stringified JSON | URL to JSON | filepath to JSON)
  • format (typescript | json-schema | hint)

example

command:

lhint transform --source "https://jsonplaceholder.typicode.com/users" --format typescript

output:

Array<{
  id: number;
  name: string;
  username: string;
  email: string;
  address: {
    street: string;
    suite: string;
    city: string;
    zipcode: string;
    geo: {
      lat: string;
      lng: string
    }
  };
  phone: string;
  website: string;
  company: {
    name: string;
    catchPhrase: string;
    bs: string
  }
}>