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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nuclide-format-js

v0.0.42

Published

A collection of codemods to help auto format javascript

Readme

nuclide-format-js

Build Status

Use this Atom plugin to automatically add require and import statements for values and types in your JavaScript.

Usage

The default keyboard shortcut for nuclide-format-js:organize-requires is cmd-shift-i.

Details

This collection of codemods automatically adds, removes, and formats your requires. It is primarily a heuristic that works by requiring identifiers that are being used that were not declared. It is also aware of Flow types and will properly promote type imports to requires, and demote requires to type imports when appropriate.

There are a few best practices that you should follow in order to get the most benefit out of these transforms:

  • Don't shadow require names anywhere in the file. The transform is very minimally aware of scope.
  • Don't alias requires (unless you specify the alias in the aliases setting).
  • Destructure in a line separate from the require (this is a general best practice):
var React = require('react');
var {PropTypes} = React;

Ordering Rules

It is good to keep a consistent ordering of lists to avoid most merge conflicts. You do not need to remember the ordering specified here, it has been chosen to give good results and this plugin will automatically follow it.

There are 5 groups separated by a blank line:

  1. type imports
  2. bare requires
  3. requires from modules with capitalized names
  4. requires from modules with non-capitalized names

For example:

import type A from 'a';
import typeof B from 'b';

require('c');

const D = require('d');

const e = require('e');

Each group is then ordered by the module name (the string on the right hand side), with capitalized names being first. The reason for using the module name as opposed to the type or value names on the left hand side is that with changing names in destructuring it is more likely that lines would shift, causing merge conflicts. Type and object destructuring lists are also sorted by local names, with uncapitalized names grouped first.

Scope

There are also a few things that are not supported yet that would be nice to support:

  • Relative requires, e.g. require('../lib/module');
  • Only add requires for known modules by maintaining a list of known modules, or by getting this information from Flow.
  • Allow per-directory configurations.
  • import statements for requiring values.

Right now the recommended set up is to not run-on-save and instead use the default keyboard shortcut.

Make sure to verify the requires that are added by this plugin and report any issues. If anything is getting in your way when using this plugin you can generally work around it by modifying the plugin's settings. It's possible to adjust things like built-ins, aliases, and even blacklist particular transforms there.

Developing

# Clone the repo
git clone [email protected]:facebooknuclide/nuclide-format-js.git

cd nuclide-format-js

# To use as an Atom package
apm link

# Install dependencies and start the transpiler watcher
yarn install
yarn run watch

Releasing

  • Make sure that master is up-to-date.
# Bump the version number
yarn version --no-git-tag-version

# Commit the version bump
git add package.json
git commit -m "$(node -p 'require("./package.json").version')"

# Run the release script
./tools/release.sh

# Follow the printed instructions if everything looks good