Skip to content

Instantly share code, notes, and snippets.

@zfkun
Last active December 25, 2015 03:59
Show Gist options
  • Save zfkun/6913461 to your computer and use it in GitHub Desktop.
Save zfkun/6913461 to your computer and use it in GitHub Desktop.
JavaScript implements for `native2ascii`
/**
* javascript implements for `native2ascii`
*
* @file native2ascii
* @author zfkun(zfkun@msn.com)
*/
/**
* 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