包详细信息

allowlist

nuxt-contrib2.4kMIT0.1.1

Create allow/deny matcher with Patterns, Regex and Functions

自述文件

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 💖

更新日志

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.1.1 (2020-12-06)

0.1.0 (2020-12-06)

⚠ BREAKING CHANGES

  • prevent synthetic default export

Features

  • export AllowlistOptions with default generic type (dbc662f)

Bug Fixes

  • prevent synthetic default export (138d7e0)

0.0.4 (2020-12-01)

Bug Fixes

0.0.3 (2020-11-30)

0.0.2 (2020-11-30)

0.0.1 (2020-11-27)