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

precinct

v12.1.1

Published

Unleash the detectives

Downloads

4,677,322

Readme

precinct

CI npm version npm downloads

Unleash the detectives

npm install precinct

Uses the appropriate detective to find the dependencies of a file or its AST.

Supports:

  • JavaScript modules: AMD, CommonJS, and ES6
  • TypeScript
  • CSS Preprocessors: Sass, Scss, Stylus, and Less
  • CSS (PostCSS)

Usage

const fs = require('fs');
const precinct = require('precinct');

const content = fs.readFileSync('myFile.js', 'utf8');

// Pass in a file's content or an AST
const deps = precinct(content);

You may pass options (to individual detectives) based on the module type via an optional second object argument detective(content, options), for example:

Example call:

precinct(content, {
  amd: {
    skipLazyLoaded: true
  },
  type: 'amd'
});
  • The supported module type prefixes are: amd, commonjs, css, es6, less, sass, scss, stylus, ts, tsx, vue.

Current options:

  • amd.skipLazyLoaded: tells the AMD detective to omit lazy-loaded dependencies (i.e., inner requires).
  • es6.mixedImports: allows for all dependencies to be fetched from a file that contains both CJS and ES6 imports.
    • Note: This will work for any file format that contains an ES6 import.
  • css.url: tells the CSS detective to include url() references to images, fonts, etc.

Finding non-JavaScript (ex: Sass and Stylus) dependencies:

const fs = require('fs');
const content = fs.readFileSync('styles.scss', 'utf8');

const sassDeps = precinct(content, { type: 'sass' });
const stylusDeps = precinct(content, { type: 'stylus' });

Or, if you just want to pass in a filepath and get the dependencies:

const { paperwork } = require('precinct');

const deps = paperwork('myFile.js');
const deps2 = paperwork('styles.scss');

precinct.paperwork(filename, options)

Supported options:

  • includeCore: (default: true) set to false to exclude core Node.js dependencies from the list of dependencies.
  • fileSystem: (default: undefined) set to an alternative fs implementation that will be used to read the file path.
  • You may also pass detective-specific configuration like you would to precinct(content, options).

CLI

Assumes a global install precinct with npm install -g precinct.

precinct [options] path/to/file

Run precinct --help to see all options.

License

MIT