@electricmagnetic/nzbbtef
Version:
18 lines (14 loc) • 660 B
JavaScript
import { longColours, longCombinedColours } from './colours/transforms';
/**
This function iterates over the colour object given, doing a (word bounded) find/replace.
- Use of \b necessary to not transform PaleBlue to PaleB
- Double backslash because string escaping necessary
*/
const transform = (nzbbtefValue, colours) =>
Object.keys(colours).reduce(
(nzbbtefValue, currentSearch) =>
nzbbtefValue.replace(new RegExp(`\\b${currentSearch}\\b`, 'gi'), colours[currentSearch]),
nzbbtefValue
);
const colourTransform = nzbbtefValue => transform(transform(nzbbtefValue, longColours), longCombinedColours);
export default colourTransform;