JSFiddle - React, Tailwind, and code Playground
JavaScript
/* sni-hgtv.2.0.js -- Tue, 11 Dec 2012 10:06:40 EST */
if (typeof (SNI.HGTV) == "undefined") {
SNI.HGTV = {};
}
SNI.HGTV.ANIMATION_SPEED = 150;
(function () {
if (typeof SNI.HGTV === "undefined") SNI.HGTV = new Object();
SNI.HGTV.truncate = function truncate(input, args) {
var limit = args && args.limit || 10,
omission = args && args.omission || '...';
return input.length <= limit ? input : input.slice(0, limit) + omission;
};
SNI.HGTV.trim = function strip(input) {
return input.trim ? input.trim() : input.replace(/^\s+/, '').replace(/\s+$/, '');
};
SNI.HGTV.humanize = function humanize(number) {
if (number % 100 >= 11 && number % 100 <= 13) return number + "th";
switch (number % 10) {
case 1:
return number + "st";
case 2:
return number + "nd";
case 3:
return number + "rd";
};
return number + "th";
};
SNI.HGTV.guid = function guid(length) {
var buf = [],
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
charlen = chars.length,
length = length || 16;
for (var i = 0; i < length; i++) {
buf[i] = chars.charAt(Math.floor(Math.random() * charlen));
};
return buf.join('');
};
SNI.HGTV.isBlank = function isBlank(input) {
return /^\s*$/.test(input);
};
SNI.HGTV.remove = function remove(input, start, end) {
return input.slice(0, start) + input.slice(end);
};
SNI.HGTV.insert = function insert(input, string, index) {
return input.slice(0, index) + string + input.slice(index);
};
SNI.HGTV.dasherize = function dasherize(input) {
return input.replace(/\W+/g, '-').replace(/([a-z\d])([A-Z])/g, '$1-$2').toLowerCase();
};
SNI.HGTV.camelize = function camelize(input) {
return input.replace(/\W+(.)/g, function (match,...