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
//returns a copy of a string with a portion removed | |
//(essentially the opposite of `slice`) | |
//the `end` argument is optional | |
//str.prune(begin[, end]) | |
if(!String.prototype.prune){ | |
String.prototype.prune = function prune(begin, end){ | |
"use strict"; | |
var newStr = this.slice(0); //make a copy of the string |
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 (){ | |
"use strict"; | |
var oldEncodeURI = encodeURI; | |
encodeURI = function encodeURI(str){ return oldEncodeURI(str).replace(/%5B/ig, "[").replace(/%5D/ig, "]"); }; | |
})(); |
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
//encode reserved characters in a string for use in HTML | |
//if `keepValidEntities` is true, the amphersands for valid character entity references will not be encoded | |
function textToHTML(str, keepValidEntities){ | |
"use strict"; | |
var validEntityNames, rxp; | |
if(keepValidEntities){ | |
//see http://www.w3.org/TR/html401/sgml/entities.html | |
validEntityNames = ""+ | |
//markup-significant and internationalization characters |
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
//creates a new function that, when called, has its `this` keyword set to the provided object, with a given sequence of arguments | |
// preceding any provided when the new function is called | |
//note: this is only a partial implementation; it may not work as expected in some scenarios. | |
// For instance, the resulting function cannot be used as a contructor. | |
if(!Function.prototype.bind){ | |
Function.prototype.bind = function bind(toObject){ | |
"use strict"; | |
var originalFn, boundArgs; | |
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
//returns an array of the properties & methods that are direct properties of an object (i.e., those that have not been inherited) | |
//see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys | |
if(!Object.keys){ | |
Object.keys = (function (){ | |
"use strict"; | |
var hasOwnProperty = Object.prototype.hasOwnProperty, | |
hasDontEnumBug = !({toString: null}).propertyIsEnumerable("toString"), | |
dontEnums = ["toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor"]; | |
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 functions were tested in Firefox 4, 8, & 20; IE 6 & 9; Chrome 17; Safari 5.1; and Opera 11.5 | |
//built-in trim() is much faster in Firefox & IE, slower in Opera, and slower for short strings but much faster for long strings in Chrome & Safari | |
if(!String.prototype.trim /*|| window.opera*/){ | |
if( window.navigator.mozIsLocallyAvailable || ((/safari/i).test(window.navigator.userAgent) && !window.chrome) ) //Firefox & Safari | |
String.prototype.trim = function trim(){ | |
var str = /\S+(?:\s+\S+)*/.exec(this); | |
return str ? str[0] : ""; | |
}; | |
else //other browsers |
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 ordinalOf(num){ | |
var n; | |
return ((n = num%100) === 11 || n === 12 || n === 13) ? "th" : ((n = num%10) === 1) ? "st" : (n === 2) ? "nd" : (n === 3) ? "rd" : (num%1 === 0) ? "th" : ""; | |
} |
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
//month names, weekday names, and ordinal indicators are in English | |
// Date.now() | |
// Date.fromISOString(isoStr) | |
// Date.timeBetween(date1, date2) | |
// dat.isLeapYear() | |
// dat.isUTCLeapYear() | |
// dat.getDaysInMonth() | |
// dat.getUTCDaysInMonth() | |
// dat.getMonthName() |
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
if(!Math.root){ | |
Math.root = function root(num, degree){ | |
return Math.pow(num, (1/degree)); | |
}; | |
} |