@svta/common-media-library
Version:
A common library for media playback in JavaScript
25 lines • 706 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToUint16 = stringToUint16;
/**
* Converts a string to a Uint16Array.
*
* @param str - The string to convert
* @returns A Uint16Array representation of the string
*
* @group Utils
*
* @beta
*
* @example
* {@includeCode ../../test/utils/stringToUint16.test.ts#example}
*/
function stringToUint16(str) {
const buffer = new ArrayBuffer(str.length * 2);
const view = new DataView(buffer);
for (let i = 0; i < str.length; i++) {
view.setUint16(i * 2, str.charCodeAt(i), true); // true for little-endian
}
return new Uint16Array(buffer);
}
//# sourceMappingURL=stringToUint16.js.map