Add a (scope-friendly) prefix to an npm package name
Useful when you have a tool that allows package name shorthands. e.g., babel
plugins are resolved by either the direct package name or
babel-plugin-${packageName}
.
npm:
npm install add-package-prefix
yarn:
yarn add add-package-prefix
addPackagePrefix(prefix : string, packageName : string)
Prefixes the packageName
with the given prefix
, ignoring any package
scope. Automatically converts spaces to hyphens. prefix
will not be added if packageName
already contains the prefix
.
const addPackagePrefix = require('add-package-prefix');
addPackagePrefix('babel-plugin', 'my-cool-project'); // => 'babel-plugin-my-cool-project'
addPackagePrefix('webpack-plugin', '@scope/awesome-thing'); // => '@scope/webpack-plugin-awesome-thing'
addPackagePrefix('yep yep', 'this is fun'); // => 'yep-yep-this-is-fun'
addPackagePrefix('babel-plugin', 'babel-plugin-something'); // => 'babel-plugin-something'
Name |
---|
YellowKirby |
MIT © YellowKirby