Files
FrenoCorp/node_modules/level-js/util/deserialize.js
Michael Freno 7c684a42cc FRE-600: Fix code review blockers
- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 00:08:01 -04:00

45 lines
1.0 KiB
JavaScript

'use strict'
var Buffer = require('buffer').Buffer
var ta2str = (function () {
if (global.TextDecoder) {
var decoder = new TextDecoder('utf-8')
return decoder.decode.bind(decoder)
} else {
return function ta2str (ta) {
return ta2buf(ta).toString()
}
}
})()
var ab2str = (function () {
if (global.TextDecoder) {
var decoder = new TextDecoder('utf-8')
return decoder.decode.bind(decoder)
} else {
return function ab2str (ab) {
return Buffer.from(ab).toString()
}
}
})()
function ta2buf (ta) {
var buf = Buffer.from(ta.buffer)
if (ta.byteLength === ta.buffer.byteLength) {
return buf
} else {
return buf.slice(ta.byteOffset, ta.byteOffset + ta.byteLength)
}
}
module.exports = function (data, asBuffer) {
if (data instanceof Uint8Array) {
return asBuffer ? ta2buf(data) : ta2str(data)
} else if (data instanceof ArrayBuffer) {
return asBuffer ? Buffer.from(data) : ab2str(data)
} else {
return asBuffer ? Buffer.from(String(data)) : String(data)
}
}