npm.io
3.2.0 • Published 3 months ago

npm-to-yarn

Licence
MIT
Version
3.2.0
Deps
0
Size
166 kB
Vulns
0
Weekly
0
Stars
37

npm-to-yarn

npm License CI Coveralls

styled with prettier Donate

Summary

npm-to-yarn is designed to convert NPM CLI commands to their Yarn equivalents (and vice versa).

Why npm-to-yarn?

npm-to-yarn is super helpful in documentation, for example in generating code tabs.

Docs

import convert from 'npm-to-yarn'

// or
// var convert = require('npm-to-yarn')

convert('npm install squirrelly', 'yarn')
// yarn add squirrelly

convert('npm install squirrelly', 'deno')
// deno add squirrelly

convert('npm install squirrelly', 'nub')
// nub add squirrelly

// npx conversions

convert('npx create-next-app', 'yarn')
// yarn dlx create-next-app

convert('npx create-next-app', 'deno')
// deno x create-next-app

convert('npx create-next-app', 'nub')
// nubx create-next-app

npm-to-yarn exposes a UMD build, so you can also install it with a CDN (it exposes global variable n2y)

API
/**
 * Converts between npm and yarn command
 */
export default function convert (str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun' | 'deno' | 'nub'): string

Tests

Tests can be run with npm test. Multiple tests check that parsing, rendering, and compiling return expected results, formatting follows guidelines, and code coverage is at the expected level.

Contributing to npm-to-yarn - Setup Guide

Install Dependencies

npm install

Run the development server

npm run start

A new file: npm-to-yarn.mjs is created in dist folder.
Open node inside the terminal and write the following code to test new changes

const npmToYarn = await import('./dist/npm-to-yarn.mjs')
const convert = npmToYarn.default

convert('npm install react', 'bun')

Resources

To be added

Projects using npm-to-yarn

Contributors

Made with by @nebrelbug and all these wonderful contributors (emoji key):

This project follows the all-contributors specification. Contributions of any kind are welcome!

Keywords