Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tomokimiyauci/is-valid-package-name

Validation for package name
https://github.com/tomokimiyauci/is-valid-package-name

denoland is-valid nestland npm typescript validation validator

Last synced: about 1 month ago
JSON representation

Validation for package name

Awesome Lists containing this project

README

        


logo image

is-valid-package-name


Validation for package name

[![test](https://github.com/TomokiMiyauci/is-valid-package-name/actions/workflows/test.yml/badge.svg)](https://github.com/TomokiMiyauci/is-valid-package-name/actions/workflows/test.yml)
[![GitHub release](https://img.shields.io/github/release/TomokiMiyauci/is-valid-package-name.svg)](https://github.com/TomokiMiyauci/is-valid-package-name/releases)
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno&labelColor=black)](https://deno.land/x/is_valid_package_name)
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/is_valid_package_name)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/is_valid_package_name/mod.ts)
[![deno version](https://img.shields.io/badge/deno-^1.6.0-lightgrey?logo=deno)](https://github.com/denoland/deno)
![node support version](https://img.shields.io/badge/node-%5E6.17.0-yellow)
![npm download](https://img.shields.io/npm/dw/is-valid-package-name?color=blue)

![GitHub (Pre-)Release Date](https://img.shields.io/github/release-date-pre/TomokiMiyauci/is-valid-package-name)
[![dependencies Status](https://status.david-dm.org/gh/TomokiMiyauci/is-valid-package-name.svg)](https://david-dm.org/TomokiMiyauci/is-valid-package-name)
[![codecov](https://codecov.io/gh/TomokiMiyauci/is-valid-package-name/branch/main/graph/badge.svg?token=SPAi5Pv2wd)](https://codecov.io/gh/TomokiMiyauci/is-valid-package-name)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f43b1c317e11445399d85ce6efc06504)](https://www.codacy.com/gh/TomokiMiyauci/is-valid-package-name/dashboard?utm_source=github.com&utm_medium=referral&utm_content=TomokiMiyauci/is-valid-package-name&utm_campaign=Badge_Grade)
![npm type definitions](https://img.shields.io/npm/types/is-valid-package-name)
![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)
![Gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style=flat)
![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)

---

A validator collection of package names for each package registry

## :sparkles: Features

- :zap: Multi runtime support (`Deno`, `Node.js`)
- :books: Pure TypeScript and provides type definition
- :package: Optimized, super slim size
- :page_facing_up: TSDoc-style comments

Currently providing validators for the following package registries:
Check each for detailed validation rules.

- [npm](./npm/README.md)
- [deno.land](./deno_land/README.md)
- [nest.land](./nest_land/README.md)

## :zap: Overview

### isValid*

The `isValid*` function returns a boolean if the package name is valid as a package.

```ts
isValidNpm('is-valid-package-name') // true
isValidNpm('node_modules') // false

isValidDenoLand('is_valid') // true
isValidDenoLand('is-valid') // false

isValidNestLand('oak') // true
isValidNestLand('o') // false
```

### validate*

The `validate*` function returns tuple of boolean and error message.

```ts
validateNpm('is-valid-package-name') // [ true, "" ]
validateNpm('node_modules') // [ false, "Name is blacklisted" ]

validateDenoLand('is_valid') // [ true, "" ]
validateDenoLand('is-valid') // [ false, "Name contains only the characters a-z, 0-9 and _" ]

validateNestLand('oak') // [ true, "" ]
validateNestLand('o') // [ false, "Name length must be greater than 1" ]
```

## :dizzy: Usage

`is-valid-package-name` provides multi platform modules.

### 🦕 Deno

#### [deno.land](https://deno.land/x/is_valid_package_name)

```ts
import { isValidNpm ,validateNpm, isValidDenoLand, validateDenoLand, isValidNestLand, validateNestLand } from "https://deno.land/x/is_valid_package_name/mod.ts";
```

#### [nest.land](https://nest.land/package/is_valid_package_name)

```ts
import { isValidNpm ,validateNpm, isValidDenoLand, validateDenoLand, isValidNestLand, validateNestLand } from "https://x.nest.land/is_valid_package_name/mod.ts";
```

### :package: Node.js

#### Install

```bash
npm i is-valid-package-name
or
yarn add is-valid-package-name
```

#### ES modules

```ts
import { isValidNpm ,validateNpm, isValidDenoLand, validateDenoLand, isValidNestLand, validateNestLand } from "is-valid-package-name";
```

#### Commonjs

```ts
const { isValidNpm ,validateNpm, isValidDenoLand, validateDenoLand, isValidNestLand, validateNestLand } = require("is-valid-package-name");
```

### :globe_with_meridians: Browser

The module that bundles the dependencies is obtained from [skypack](https://www.skypack.dev/view/is-valid-package-name).

```html

import { isValidNpm ,validateNpm, isValidDenoLand, validateDenoLand, isValidNestLand, validateNestLand } from "https://cdn.skypack.dev/is-valid-package-name";

```

## :green_heart: Support

> ie is no longer supported to reduce bundle size.

The TypeScript version must be `4.1.0` or higher.

This project provides `ES modules` and `Commonjs`.

If you have an opinion about what to support, you can open an
[issue](https://github.com/TomokiMiyauci/equal/issues) to discuss it.

The `browserslist` has the following settings.

```text
defaults
last 8 version
not IE <= 11
not ie_mob <= 11
node 6
```

| DenoDeno | Node.jsNode.js | IE / EdgeEdge | FirefoxFirefox | ChromeChrome | SafariSafari | iOS SafariiOS Safari | SamsungSamsung | OperaOpera |
| --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `^1.6.0` | `^6.17.0` | `^83` | `^78` | `^83` | `^11` | `^12.0` | `^7.2` | `^68` |

## :handshake: Contributing

Contributions, issues and feature requests are welcome!
Feel free to check [issues](https://github.com/TomokiMiyauci/is-valid-pacakge-name/issues).

## :seedling: Show your support

Give a ⭐️ if this project helped you!



## :bulb: License

Copyright © 2021-present [TomokiMiyauci](https://github.com/TomokiMiyauci).

Released under the [MIT](./LICENSE) license