-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.min.js
8 lines (8 loc) · 1.26 KB
/
helpers.min.js
1
2
3
4
5
6
7
8
/**
* helpers.js — Small JavaScript functions for common use cases.
*
* @version 2.1.1
* @license MIT
* @author Sacha Schmid (http://sacha.me)
*/
var readingtime=function(t,r,e){var n=r||"{time}",o=Math.round(t/(e||180)),i=/\{time\}/,p="",u=function(){return n.replace(i,p)};return p=o>=0&&2>o?"about a minute":o>=25&&35>=o?"about half an hour":o>=55&&65>=o?"about an hour":55>o?"about "+o+" minutes":"quite some time",u()};Number.prototype.round=Number.prototype.round||function(t){return Math.round(this*Math.pow(10,t||2))/Math.pow(10,t||2)},String.prototype.base=String.prototype.base||function(t){var r=this.replace(/(http(s)?:\/\/)?(www\.)?/,"").split("/")[0];return t?r.split(".")[0]:r},String.prototype.format=String.prototype.format||function(){for(var t=this,r=0,e=arguments.length;e>r;r++)t=t.replace(RegExp("\\{"+r+"\\}","gm"),arguments[r]);return t},String.prototype.insert=String.prototype.insert||function(t,r){return t?(r="end"===r?this.length:"start"===r?0:r||0,this.slice(0,r)+t+this.slice(r)):this},String.prototype.truncate=String.prototype.truncate||function(t,r){return this.length>(t||30)?this.substr(0,t||30).replace(/\s$/,"")+(r||"…"):""+this},String.prototype.words=String.prototype.words||function(){return this.replace(/\s+/g," ").split(" ").length};