https://github.com/nuxt-contrib/allowlist
Easy way to allow good values and deny bad ones
https://github.com/nuxt-contrib/allowlist
Last synced: 22 days ago
JSON representation
Easy way to allow good values and deny bad ones
- Host: GitHub
- URL: https://github.com/nuxt-contrib/allowlist
- Owner: nuxt-contrib
- License: mit
- Created: 2020-11-27T19:06:43.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-15T02:23:21.000Z (12 months ago)
- Last Synced: 2025-06-05T04:27:46.375Z (5 months ago)
- Language: TypeScript
- Size: 237 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Allowlist
> Create allow/deny matcher with Patterns, Regex and Functions
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]
## Install
Install using npm or yarn:
```bash
npm i allowlist
# or
yarn add allowlist
```
Import:
```js
// CommonJS
const { allowlist } = require('allowlist')
// ESM
import { allowlist } from 'allowlist'
```
**Note:** You may need to transpile library!
## Usage
**Create a matcher:**
```js
// Allow a good string
const allow = allowlist('good')
// Allow a good string ignore case
const allow = allowlist('good', true)
// Allow a better regex
const allow = allowlist(/better/)
// Allow list of good values
const allow = allowlist([
'good',
/better/,
/best/i
])
// Allow good values with your logic
const allow = allowlist((value) => {
return value.includes('good')
})
// Deny bad values
const allow = allowlist({
reject: [
'bad',
/awful/,
/worse/i
]
})
// Allow good values and deny bads
const allow = allowlist({
accept: [
'good',
/better/,
/best/i
],
reject: [
'bad',
/awful/,
/worse/i
]
})
```
**Use matcher:**
```js
if (allow('Sometimes good things fall apart so better things can fall together.')) {
// cool stuff
}
```
## License
MIT. Made with 💖
[npm-version-src]: https://img.shields.io/npm/v/allowlist?style=flat-square
[npm-version-href]: https://npmjs.com/package/allowlist
[npm-downloads-src]: https://img.shields.io/npm/dm/allowlist?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/allowlist
[github-actions-src]: https://img.shields.io/github/workflow/status/farnabaz/allowlist/ci/master?style=flat-square
[github-actions-href]: https://github.com/farnabaz/allowlist/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/farnabaz/allowlist/master?style=flat-square
[codecov-href]: https://codecov.io/gh/farnabaz/allowlist