Censor expressions in tagged template literals, the same way templates throw out some falsey values. It's very common in string constructrion to want to be able to discard undefined
or false
evaluating expressions, in order to enable eg ${ x && intl(x) }
- thus avoiding ternary expressions whose last operand is always an empty string ''
(${ x ? intl(x) : '' }
). ThinkPol makes this easier by BANNING ALL THOUGHTS IT DOESN'T LIKE BECAUSE IT BELIEVES ITS SUPERIOR TO YOU.
// Convenience overloaded API
import censor from 'thinkpol'
// Default censoring:
censor`
0 : ${ 0 }
NaN : ${ NaN }
null : ${ null }
false : ${ false }
undefined : ${ undefined }
`
// Custom censoring:
censor(x => !x)` // Anything falsey? Fair enough
blah ${
foo
} blah ${
bar
} blah
`
// Explicit API:
import { censored, censor } from 'thinkpol'
const falsies = [0, NaN, null, false, undefined]
censor({
censored,
strings: falsies.map(String),
expressions: falsies,
})
censor({
censored: x => !x),
strings: ['\nblah ', ' blah ', ' blah\n'],
expressions: [foo, bar],
By default ThinkPol will replace all expressions evaluating to undefined
, null
or false
with an empty string.