Last active
December 10, 2015 08:08
-
-
Save Mithrandir0x/4405770 to your computer and use it in GitHub Desktop.
So, is it a bad idea to fetch data from "arguments"? (Rotten belches in 3, 2, 1...)
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
function makeplain(strAccents) | |
{ | |
if(strAccents==undefined) | |
return ""; | |
strAccents = strAccents.split(''); | |
var strAccentsOut = new Array(); | |
var strAccentsLen = strAccents.length; | |
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž'; | |
var accentsOut = ['A','A','A','A','A','A','a','a','a','a','a','a','O','O','O','O','O','O','O','o','o','o','o','o','o','E','E','E','E','e','e','e','e','e','C','c','D','I','I','I','I','i','i','i','i','U','U','U','U','u','u','u','u','N','n','S','s','Y','y','y','Z','z']; | |
for (var y = 0; y < strAccentsLen; y++) | |
{ | |
if (accents.indexOf(strAccents[y]) != -1) | |
{ | |
strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])]; | |
} | |
else | |
strAccentsOut[y] = strAccents[y]; | |
} | |
strAccentsOut = strAccentsOut.join(''); | |
return strAccentsOut.toLowerCase(); | |
} |
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
function strf(){ | |
var args = arguments, | |
arg_l = args.length - 1; | |
var onReplace = function(arg, i){ | |
i = parseInt(i); | |
if ( i >= 0 && i < arg_l ) | |
return args[i + 1]; | |
return arg; | |
}; | |
return args[0].replace(/\$\{([0-9]+)\}/g, onReplace); | |
} | |
// strf('Hello ${0}', 'World'); // "Hello World" | |
// strf('Hello ${0}'); // "Hello ${0}" | |
// strf('${0}${1}', 'Hello ', 'World'); // "Hello World" |
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
// Trim shim for Internet Explorer. | |
// Author: Ben Rowe | |
// Source: http://stackoverflow.com/questions/2308134/trim-in-javascript-not-working-in-ie | |
if(typeof String.prototype.trim !== 'function') { | |
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g, ''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment