@prefer-jsr/npm2jsr
Version:
Mapping of NPM packages to their JSR equivalents
79 lines (50 loc) • 1.71 kB
Markdown

A utility package that provides mapping between NPM packages and their JSR equivalents.
```bash
pnpm i jsr:@prefer-jsr/npm2jsr
```
```bash
yarn add jsr:@prefer-jsr/npm2jsr
```
```bash
npx jsr add @prefer-jsr/npm2jsr
```
<details>
<summary>NPM registry (If you really need it for some reason)</summary>
```bash
npm install @prefer-jsr/npm2jsr
```
</details>
## Usage
```typescript
import {
getJsrEquivalent,
hasJsrEquivalent,
toJsrDependency,
} from '@prefer-jsr/npm2jsr';
// Check if a package has a JSR equivalent
if (hasJsrEquivalent('zod')) {
const jsrPackage = getJsrEquivalent('zod'); // '@zod/zod'
const jsrDep = toJsrDependency('^3.21.4'); // 'jsr:^3.21.4'
}
// Get all available mappings
import { getAvailableNpmPackages } from '@prefer-jsr/npm2jsr';
const packages = getAvailableNpmPackages(); // ['zod', '@eslint/markdown']
```
Returns the JSR package name for a given NPM package, or null if no mapping exists.
Checks if an NPM package has a JSR equivalent.
Converts a version string to JSR format by prefixing with `jsr:`.
Returns an array of all NPM packages that have JSR mappings.
This package is part of the prefer-jsr monorepo. The mapping may be updated as new packages become available on JSR.
Run `nx build npm2jsr` to build the library.
Run `nx test npm2jsr` to execute the unit tests via [Vitest](https://vitest.dev/).