Allowlist
Easy way to allow good values and deny bads
Install
Install using npm or yarn:
npm i allowlist
yarn add allowlist
Import into your Node.js project:
const allowlist = require('allowlist')
import allowlist from 'allowlist'
Usage
Create a list:
const allow = allowlist('good')
const allow = allowlist('good', true)
const allow = allowlist(/better/)
const allow = allowlist([
'good',
/better/,
/best/i
])
const allow = allowlist((value) => {
return value.includes('good')
})
const allow = allowlist({
reject: [
'bad',
/awful/,
/worse/i
]
})
const allow = allowlist({
accept: [
'good',
/better/,
/best/i
],
reject: [
'bad',
/awful/,
/worse/i
]
})
Check for good:
if (allow('Sometimes good things fall apart so better things can fall together.')) {
}
License
MIT. Made with 💖