GitHub 6219★

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
Follow me on and to get more useful contents.