提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
791 B

  1. export const fromCodePoint =
  2. String.fromCodePoint ||
  3. function (astralCodePoint: number) {
  4. return String.fromCharCode(
  5. Math.floor((astralCodePoint - 0x10000) / 0x400) + 0xd800,
  6. ((astralCodePoint - 0x10000) % 0x400) + 0xdc00
  7. );
  8. };
  9. // @ts-expect-error - String.prototype.codePointAt might not exist in older node versions
  10. export const getCodePoint = String.prototype.codePointAt
  11. ? function (input: string, position: number) {
  12. return input.codePointAt(position);
  13. }
  14. : function (input: string, position: number) {
  15. return (input.charCodeAt(position) - 0xd800) * 0x400 + input.charCodeAt(position + 1) - 0xdc00 + 0x10000;
  16. };
  17. export const highSurrogateFrom = 0xd800;
  18. export const highSurrogateTo = 0xdbff;