- 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>
22 lines
522 B
JavaScript
22 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)
|
|
}
|
|
}
|