Skip to content

Instantly share code, notes, and snippets.

@zfkun
Last active December 25, 2015 03:59
Show Gist options
  • Save zfkun/6913546 to your computer and use it in GitHub Desktop.
Save zfkun/6913546 to your computer and use it in GitHub Desktop.
JavaScript implements for `ascii2native`
/**
* javascript implements for `ascii2native`
*
* @file ascii2native
* @author zfkun(zfkun@msn.com)
*/
/**
* pattern 1
*
* @param {string} str
* @return {string}
*/
function ascii2native( str ) {
return unescape( ( str + '' ).replace( /\\(?=u[\da-z]{4})/gi, '%' ) );
}
/**
* pattern 2
*
* @param {string} str
* @return {string}
*/
/*
function ascii2native( str ) {
return ( str + '' ).replace( /\\u[\da-z]{4}/gi , function( ascii ) {
return unescape( ascii.replace( /\\/, '%' ) );
});
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment