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

better-name

v0.7.3

Published

CLI to rename ES2015 module files

Downloads

122

Readme

better-name

CircleCI Coverage Status npm version

A CLI to move JavaScript(ES2015) module files keeping dependencies.

If you have the following JavaScript files coupled with import/export dependencies and you want to refactor via moving the target.js to another directory.

// src/index.js

import { someFn } from './oldFile';

export default function main() {
  someFn();
}
// src/oldFile.js

export function someFn() {
  return 'test';
}

This CLI keeps their dependencies. In other words, after better-name src/oldFile.js src/feat/newFile.js, the import declaration in the index.js file gets updated with the new dependencies:

// src/index.js

import { someFn } from './feat/newFile';

export default function main() {
  someFn();
}

Install

npm -g install better-name

Usage

better-name [options] <fromFile> <toFile>

Exec better-name --help if you want more details :smile:

Configure

Project file patterns

By default, this CLI searches files to be replaced via src/**/*.{js,jsx,mjs,ts,tsx} glob pattern. You can customize the glob pattern with --pattern option or configuring in package.json:

  /* package.json */
  "betterName": {
    "patterns": [
      "src/javascript/**/*.{js,jsx}",
      "src/styles/**/*.css"
    ]
  },

Root import

Root path mapping using babel-plugin-root-import is supported. Path mapping configuration is loaded automaticcaly if your .babelrc has babel-plugin-root-import section.

You also can configure path mapping via package.json such as:

  /* package.json */
  "betterName": {
    "rootImport": [{
      "rootPathPrefix": "~",
      "rootPathSuffix": "src/js"
    }, {
      "rootPathPrefix": "@",
      "rootPathSuffix": "other-src/js"
    }, {
      "rootPathPrefix": "#",
      "rootPathSuffix": "../../src/in/parent"
    }]
  }

If you want to avoid prefixing after replacing, --normalize-root-import CLI option or the following package.json setting is available:

  /* package.json */
  "betterName": {
    "normalizeRootImport": true
  }

Format with Prettier

This CLI format your code after replace import declarations if your project has Prettier config file(.prettierrc, .prettierrc.js,,,). You can turn on this behavior passing --prettier options to CLI.

Remarks

Available file types

This CLI can replace import declarations in the following file types:

  • JavaScript: .js, .jsx, .mjs
  • TypeScript: .ts, .tsx

And imports non-JavaScript files are allowed. For example:

/* some.component.jsx */

import styles from './some.component.css';

// ...

However, non-JavaScript import(i.e. @import in CSS) could not be replaced.

License

MIT. See LICENSE file under the this repository.