Friday, July 1, 2022

Preventing accidental alert and console.log on production

Use this regular expression to find stray console.log and alert:
^[^\/]\s+console\.group|^console\.group
^[^\/]\s+console\.log|^console\.log
^[^\/]\s+alert|^alert

Saturday, June 11, 2022

Multiple nots is knotty to read

Simplifying multiple nots:
const isVariant = e.match(VARIANT_TESTER);
const matchingFirstHanzi = isVariant?.[2];
const matchingSecondHanzi = isVariant?.[4];

// knotty read:
// const needToShow
//     = !isVariant || (matchingFirstHanzi !== hanzi && matchingSecondHanzi !== hanzi);

// De-Morgan'd, easy to read:
// const needToHide = isVariant && (matchingFirstHanzi === hanzi || matchingSecondHanzi === hanzi);

const needToHide = isVariant && [matchingFirstHanzi, matchingSecondHanzi].includes(hanzi);
const needToShow = !needToHide;