recoder-code
Version:
Complete AI-powered development platform with ML model training, plugin registry, real-time collaboration, monitoring, infrastructure automation, and enterprise deployment capabilities
22 lines (19 loc) • 522 B
JavaScript
var Buffer = require('buffer').Buffer
// Returns either a Uint8Array or Buffer (doesn't matter to
// IndexedDB, because Buffer is a subclass of Uint8Array)
var str2bin = (function () {
if (global.TextEncoder) {
var encoder = new TextEncoder('utf-8')
return encoder.encode.bind(encoder)
} else {
return Buffer.from
}
})()
module.exports = function (data, asBuffer) {
if (asBuffer) {
return Buffer.isBuffer(data) ? data : str2bin(String(data))
} else {
return String(data)
}
}