JS: String.fromCodePoint
New in ES2015.
String.fromCodePoint ( codePoint1, codePoint2 … )
Return a string, each character corresponds to the code point in argument.
// convert sequence of unicode code point to string console.log ( String.fromCodePoint ( 97, 128514 ) === "a😂" ); // true // 97 is the code point for letter “a” // 128514 is the code point for the char 😂 FACE WITH TEARS OF JOY
How to Find Character's Code Point
To find character's code point, use String.prototype.codePointAt
.
For code point of English character and punctuations, see ASCII Table.
fromCodePoint polyfill
if (!String.fromCodePoint) { // ES6 Unicode Shims 0.1 , © 2012 Steven Levithan http://slevithan.com/ , MIT License String.fromCodePoint = function fromCodePoint () { var chars = [], point, offset, units, i for (i = 0; i < arguments.length; ++i) { point = arguments[i] offset = point - 0x10000 units = point > 0xFFFF ? [0xD800 + (offset >> 10), 0xDC00 + (offset & 0x3FF)] : [point] chars.push(String.fromCharCode.apply(null, units)) } return chars.join("") } }
Reference
ECMAScript 2015 §Text Processing#sec-string.fromcodepoint
Character Topic
String Topic
- JS: String Overview
- JS: Template String
- JS: String Object
- JS: String.prototype
- JS: String Code Unit vs Code Point
- JS: String Escape Sequence
- JS: Unicode Escape Sequence
- JS: Source Code Encoding
- JS: Allowed Characters in Identifier
- JS: Convert String to Number
- JS: Encode URL, Escape String
- JS: Format Number
- JS: JSON
Patreon me $5. Ask me question on patreon