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

@ajar/timescript

v1.4.0

Published

A simple time script

Downloads

228

Readme

Creating an npm package

initial files and folders

  1. Create a new package project in a new folder npm init -y
  2. Create an src folder and a index.ts file inside it.

Running Typescript in Node.js while developing the package

We will start by installing tsx. It uses esbuild to run typescript files on the fly in node.js with zero configuration.

  1. run npm install -D tsx

  2. add a dev script to package.json to run tsx in watch mode.

    "scripts": {
        "dev": "tsx watch ./src/index.ts",
    }
  3. Write some typescript code in index.ts and run npm run dev to see it in action.

Building the package

While esbuild is orders-of-magnitude faster then tsc it doesn't type-check our code. Although there are configuration options to use tsc only for type-checking in tandam with esbuild for the actual compilation, I want to keep our config simple and not rely too much on esbuild other then spontanious zero-config development. So let's use tsc to build our package for production.

  1. install the following dev dependencies

    1. typescript - the tsc compiler for our build step
    2. @types/node - types for node.js
    3. rimraf - a rm -rf util for node.js that works on windows too
  2. Add a tsconfig.json file to the root of the project with the following code. If you're curious about the configuration options, you can read about them here, or run tsc --init to generate a tsconfig.json file with comments explaining each option...

    {
        "compilerOptions": {
            "target": "esnext",
            "module": "esnext",
            "outDir": "dist",
            "rootDir": "src",
            "strict": true,
            "noEmitOnError": true,
            "moduleResolution": "node",
            "esModuleInterop": true,
            "skipLibCheck": true,
            "forceConsistentCasingInFileNames": true
        },
        "exclude": ["**/*.spec.ts"]
    }
  3. Add a build script to package.json to run tsc .

    "scripts": {
        "build": "rimraf dist && tsc",
    }

unit tests and code coverage

  1. We'll use vitest - a lightweight next generation drop-in replacement for jest