Source

arrayBuffer/stringToArrayBuffer.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToArrayBuffer = void 0;
// 2 bytes for each char
var BYTES_PER_CHAR = 2;
/**
 * Reference: https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
 * @param str
 * @category arrayBuffer
 * @module stringToArrayBuffer
 */
function stringToArrayBuffer(str) {
    var buf = new ArrayBuffer(str.length * BYTES_PER_CHAR);
    var bufView = new Uint8Array(buf);
    for (var i = 0, strLen = str.length; i < strLen; i++)
        bufView[i] = str.charCodeAt(i);
    return buf;
}
exports.stringToArrayBuffer = stringToArrayBuffer;
exports.default = stringToArrayBuffer;