JSFiddle - React, Tailwind, and code Playground
by rwaldin
HTML
<!-- ignore this stuff, it's just here to allow us to jsfiddle wsi stuff --><script>WSI = {isEnabled: function(){return false;},offsiteRequests:[]};</script><script src='http://www.williams-sonoma.com/wsimgs/ab/images/s/201207/0011/js/dojo/wsgc/wsgc.js'></script><script>WSI.utils = new wsgc.js.Utils('','');</script><!-- end ignore -->
JavaScript
(function() {
dojo.mixin(dojo.provide('wsgc.js.StringUtils'), {
/**
* returns given string with the first word with first letter in upper case and the rest in lower case
*/
capitalize: function(word) {
return word.replace(/\w/)
return word[0].toUpperCase() + (word[1] ? word.substr(1).toLowerCase() : '');
},
/**
* returns given string with padded on the left sufficiently to fill the specified width
*/
leftPad: function(str, width, pad) {
return (Array(width + 1).join(pad || '0') + str).substr(-width);
},
/**
* prepares given string literal for use in regular expression by escaping regex sigificant characters
*/
escapeRegExp: function(str) {
return str.replace(/([.?*+\[\]^$()])/g, '\\$1');
},
/**
* return the given number as a string with the correct ordinal suffix (eg. 33 => 33rd)
*/
ordinalSuffix: function(n) {
// exclude teens from this conditional because they always have ordinal suffix 'th'
if (((n % 100) / 10) | 0 !== 1) {
switch (n % 10) {
case 1:
return n + 'st';
case 2:
return n + 'nd';
case 3:
return n + 'rd';
}
}
return n + 'th';
}
});
}());
(function() {
var DATE_UTILS = dojo.provide('wsgc.js.DateUtils'),
stringUtils = wsgc.js.StringUtils,
// define these here so the *_ABBRS initializers below can access them
MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
DAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
wsgc.js.DateUtils =...