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

ntro

v0.3.4

Published

Introspect configuration files and generate typescript type declarations or other useful typescript code.

Downloads

12

Readme

crates.io npm version

ntro

A cli tool that to ntrospect configuration files and output a typescript type declarations.

Features

.yaml -> .d.ts

# filename: test.multiple.yaml
calling-birds:
  - huey
  - dewey
  - louie
  - fred
doe: "a deer, a female deer"
french-hens: 3
pi: 3.14159
ray: "a drop of golden sun"
xmas: true
xmas-fifth-day:
  calling-birds: four
  french-hens: 3
  golden-rings: 5
  partridges:
    count: 1
    location: "a pear tree"
  turtle-doves: two
---
calling-birds:
  - huey
  - dewey
  - louie
  - fred
doe: "a deer, a female deer"
---
hello: world

becomes

declare namespace TestMultiple {
  export type Document0 = {
    "calling-birds": ["huey", "dewey", "louie", "fred"];
    doe: "a deer, a female deer";
    "french-hens": 3;
    pi: 3.14159;
    ray: "a drop of golden sun";
    xmas: true;
    "xmas-fifth-day": {
      "calling-birds": "four";
      "french-hens": 3;
      "golden-rings": 5;
      partridges: { count: 1; location: "a pear tree" };
      "turtle-doves": "two";
    };
  };
  export type Document1 = {
    "calling-birds": ["huey", "dewey", "louie", "fred"];
    doe: "a deer, a female deer";
  };
  export type Document2 = { hello: "world" };
  export type All = [Document0, Document1, Document2];
}

Usage

Usage: ntro yaml [OPTIONS] <SOURCE_FILE>

Arguments:
  <SOURCE_FILE>  Path to a yaml file

Options:
  -o <OUTPUT_DIR>      Set the output directory, to where to save the *.d.ts file
  -q, --quiet          Disable logs
  -h, --help           Print help

.env -> .ts

NAME="value"
NEXT_PUBLIC_KEY="yoa",

# notice the type hint below
# @type 'a' | 'b'
NAME2=value
KEY = "value" # asdfa

keys= 'city'

# another type hint
# @type string
keys2 ='city'

*.d.ts

declare namespace NodeJS {
  interface ProcessEnv {
    KEY?: string;

    NAME?: string;

    NAME2?: string;

    NEXT_PUBLIC_KEY: string;

    keys?: string;

    keys2?: string;
  }
}

You can also generate a typescript module that parses environment variables with extra type safety using zod. The advantage is that type hint comment are collected and used to define the zod schema.

import z, { ZodTypeAny } from "zod";

const clientEnvSchemas = {
  NEXT_PUBLIC_KEY: z.string(),
};

const serverEnvSchemas = {
  ...clientEnvSchemas,
  NAME: z.string(),
  NAME2: z.enum(["a", "b"]),
  keys: z.string(),
  keys2: z.string(),
};

//... more implementation details are generated

Usage

Usage: ntro dotenv [OPTIONS] [SOURCE_FILES]...

Arguments:
  [SOURCE_FILES]...  Path(s) to some .env files

Options:
  -o <OUTPUT_DIR>                 Set the output directory, to where to save the env.d.ts file
  -q, --quiet                     Disable logs
  -z, --zod                       Generate a typescript module implementing a zod schema for env variables
  -w, --watch                     Wath for changes in the source files and rerun
  -p, --set-ts-config-path-alias  Update the project's tsconfig.json to include a path alias to the env.parsed.ts module that holds the zod schemas
  -h, --help                      Print help