unicode() - Converts any string into a string of 6-character JS-compliant unicode code points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts any string into a string of 6-character JS-compliant unicode code | |
* points. | |
* @param {string} input | |
* The input that will be converted to a string of 6-character groups | |
* representing unicode code points. | |
* @param {boolean} [asJSON=false] | |
* Optional, defaults to `false`. Indicates if the returned string will be | |
* the JSON version of `input`. | |
* @returns {string} | |
* A string where each character from `input` will be represented by one or | |
* more 6-character groups. Each 6-character group will be a string that | |
* representing a unicode code point (between "\u0000" and "\uFFFF"). If | |
* `asJSON` is `true` this string will begin and end with a double-quote. | |
*/ | |
function unicode(input, asJSON=false) { | |
for (var r = '', i = input.length; i--;) { | |
r = '\\u' + ('000' + input.charCodeAt(i).toString(16)).slice(-4) + r; | |
} | |
return asJSON ? '"' + r + '"' : r; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Name of the function responsable for transforming the input into the output. | |
"transform": "unicode", | |
// Type of YourJS IO-App | |
"type": "instant", | |
// Where to find the code that will be eval'd. | |
"files": ["unicode.js"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IO App:
https://www.yourjs.com/gist-io/938926a9a7f6f9e1d5d24e6f36f8ec71