Michael Michael - 10 months ago 58
Javascript Question

Javascript check if character is 32bit

Using javascript, i want to check if a certain character is 32 bit or not ? How can i do it ? I have tried with

but it didn't work out for 32bit characters.

Any suggestions/help will be much appreciated.

Answer Source

The charCodeAt() docs returns integer between 0 to 65535 (FFFF) representing UTF-16 code unit. If you want the entire code point value, use codePointAt().
You can use the string.codePointAt(pos) to easily check if a character is represented by 1 or 2 code point value . Values greater than FFFF means they take 2 code units for a total of 32 bits.

function is32Bit(c) {
  return c.codePointAt(0) > 0xFFFF;