1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 18:29:39 +02:00
Oinktube/node_modules/level-js/util/serialize.js
2022-07-15 11:08:01 -03:00

21 lines
522 B
JavaScript

'use strict'
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)
}
}