allowlist
Create allow/deny matcher with Patterns, Regex and Functions
Last updated 4 years ago by pi0 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install allowlist 
SYNC missed versions from official npm registry.

Allowlist

Create allow/deny matcher with Patterns, Regex and Functions

npm version npm downloads Github Actions Codecov

Install

Install using npm or yarn:

npm i allowlist
# or
yarn add allowlist

Import:

// CommonJS
const { allowlist } = require('allowlist')

// ESM
import { allowlist } from 'allowlist'

Note: You may need to transpile library!

Usage

Create a matcher:

// 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:

if (allow('Sometimes good things fall apart so better things can fall together.')) {
    // cool stuff
}

License

MIT. Made with ????

Current Tags

  • 0.1.1                                ...           latest (4 years ago)

5 Versions

  • 0.1.1                                ...           4 years ago
  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |