Last active
December 25, 2015 03:59
-
-
Save zfkun/6913461 to your computer and use it in GitHub Desktop.
JavaScript implements for `native2ascii`
This file contains hidden or 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
/** | |
* javascript implements for `native2ascii` | |
* | |
* @file native2ascii | |
* @author zfkun([email protected]) | |
*/ | |
/** | |
* pattern 1 | |
* | |
* @param {string} str | |
* @return {string} | |
*/ | |
function native2ascii( str ) { | |
return unescape( escape( str + '' ).replace( /%(?=u[\da-z]{4})/gi, '\\' ) ); | |
} | |
/** | |
* pattern 2 | |
* | |
* @param {string} str | |
* @return {string} | |
*/ | |
/* | |
function native2ascii(str) { | |
return ( str + '' ).replace( | |
/[^\x00-\xff]/g, | |
function ( char ) { | |
return escape( char ).replace( /\%/, '\\' ); | |
} | |
); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment