3 ms·
but every time I read a code base, there is always a utility function reinventing the wheel. Sometimes the wheel is invented because the existing wheel isn't b
by dsp1234 11y ago
but every time I read a code base, there is always a utility function reinventing the wheel.
Sometimes the wheel is invented because the existing wheel isn't built for the same purpose (ex: off-road).
ex:
I recently needed to check a buffer to see if it's contents were valid UTF-8 in nodejs. I wanted to do this without having to run it through something like StringDecoder, because it's an intermediate buffer, and I didn't want to have the overhead of actually converting it since it wasn't for my use. So I do 'npm install is-utf8'. Then:
let isUtf8 = require('is-utf8')
isUtf8(new Buffer('\u0000')) //false
isUtf8(new Buffer('\u000B')) //false
isUtf8(new Buffer('foobar')) //true
So the package is-utf8 is really more like "Is a printable UTF-8 string". Which is certainly a reasonable choice, and a possibly reasonable default, but was not what I needed.