Get the length of a string in bytes
JavaScript version
const bytes = (str) => new Blob([str]).size;
TypeScript version
const bytes = (str: string): number => new Blob([str]).size;
Examples
bytes('hello world'); // 11
bytes('🎉'); // 4
JavaScript version
const bytes = (str) => new Blob([str]).size;
TypeScript version
const bytes = (str: string): number => new Blob([str]).size;
Examples
bytes('hello world'); // 11
bytes('🎉'); // 4