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

@jsweb/packs

v3.0.1

Published

A simple, fast and objective manager for modules, snippets, assets or anything with no dependencies.

Downloads

12

Readme

@jsweb/packs

A simple, fast and objective manager for modules, snippets, assets or anything with no dependencies.

Note: Since version 3.0.0, @jsweb/packs requires Node.js v16.0.0 or higher and should break compatibility with older Node.js versions.

  • CLI
  • Modules/Snippets/Assets manager
  • Simple, fast, objective
  • Get only files you want from NPM packages
  • Fetch Gist and Gitlab snippets to save as code
  • Grab anything from the web
  • All automated with a simple JSON setup


Install

In your project:

npm i -D @jsweb/packs

Or...

yarn add @jsweb/packs

Then, include a new command in package.json into scripts section:

{
  "scripts": {
    "packs": "packs"
  }
}

Choose a name of your preference, but point it to packs, or just use with NPX or Yarn into your project folder: npx packs or yarn packs.

If you prefer, install it globaly: npm i -g @jsweb/packs or yarn global add @jsweb/packs.

Then you can run packs CLI anywhere.

Or, use with NPX without install: npx -p @jsweb/packs packs.

Usage

@jsweb/packs reads a section at your package.json file to register packages, snippets, gists or anything you want to fetch from web into your project.

Just create a @jsweb/packs section like this:

{
  "@jsweb/packs": {
    "dir": "jsweb-packs",
    "gist": {
      "asq.js": "jyamashiro24/17ac171a73246744b09a47d6c9d77241",
      "steven89/kav.js": "steven89/f7aedca683deee6ee8211399e94cd583"
    },
    "gitlab": {
      "dom.js": "34295",
      "dstrbg.styl": "1662645",
      "tpl/render.js": "1663326"
    },
    "unpkg": {
      "moment.js": "moment/min/moment-with-locales.min.js",
      "jsweb/truetype.js": "@jsweb/truetype",
      "normalize.css": "normalize.css"
    },
    "web": {
      "animate.css": "https://raw.githubusercontent.com/daneden/animate.css/master/animate.min.css",
      "img/js.svg": "https://upload.wikimedia.org/wikipedia/commons/9/99/Unofficial_JavaScript_logo_2.svg"
    }
  }
}

Then, just run packs update CLI command!

key : value pairs within sections represent destination : source, so key is the filename where the asset will be saved and value is the source to fetch its content.

You can save your assets in sub directories by setting key as a path to save into respective section.

Result

@jsweb/packs saves downloaded files into a diretory structure corresponding to @jsweb/packs section at package.json:

./
| -${packs dir}
  | - gist
  | - gitlab
  | - unpkg
  | - web

@jsweb/packs directory

@jsweb/packs default dir is a jsweb-packs folder at package.json root directory, but it is possible to set a custom path to save your assets.

Just define dir on setup at package.json:

{
  "@jsweb/packs": {
    "dir": "path/to/your/custom/packs"
  }
}

CLI commands

@jsweb/packs CLI support some simple commands. If none is given, help is default.

update

Update/fetch all of your assets with this simple command: packs update.

Important: By default, this command rewrites @jsweb/packs section at package.json file to properly sort the content. If you need to prevent this behavior for CI/CD or any other production workflow, make sure to set NODE_ENV to any value which not contains dev (case not sensitive).

add

You can add new assets to your project by manually adding @jsweb/packs section at package.json and runing update command.

But packs add [type] [dest] [source] command is a convenient way:

packs add unpkg moment.js moment/min/moment-with-locales.min.js

packs add gist steven89/kav.js steven89/f7aedca683deee6ee8211399e94cd583

packs add gitlab dom.js 34295

packs add web animate.css https://raw.githubusercontent.com/daneden/animate.css/master/animate.min.css

Arguments must follow this pattern:

  • type the resource type where the asset is hosted, section within @jsweb/packs at package.json and folder into @jsweb/packs->dir
  • dest defines the destination path/filename where to save content
  • source is an ID, PATH or URL to fetch content

Important: This command ever writes data to package.json file to update @jsweb/packs section.

del

To remove assets you can just delete files from directory and remove entry from @jsweb/packs section at package.json.

But you can simply run packs del [type] [file]:

packs del web jquery.js

Important: This command ever writes data to package.json file to update @jsweb/packs section.

list

Prints @jsweb/packs section from package.json. Just for convenience!

packs list

How it works

NPM / Unpkg

@jsweb/packs gets the code of NPM packages from Unpkg CDN.

Optionally, you can use SEMVER tags if you need to specify packages versions, like:

{
  "@jsweb/packs": {
    "unpkg": {
      "moment.js": "[email protected]/min/moment-with-locales.min.js"
    }
  }
}

If no version was defined, the latest version is the default at Unpkg CDN.

Gist and Gitlab Snippets

For code snippets repositories, @jsweb/packs simply fetch raw files as is.

The codes must to be public available.

Gists need user/hash to identify and get the code. Gitlab Snippets just need an id.

Web / Anything

@jsweb/packs can fetch any online public file. Just map it into web section, like this:

{
  "@jsweb/packs": {
    "web": {
      "img/js.svg": "https://upload.wikimedia.org/wikipedia/commons/9/99/Unofficial_JavaScript_logo_2.svg",
      "img/npm-do-more.svg": "https://static.npmjs.com/images/saas-features/do-more-faster.svg"
    }
  }
}