UNPKG

read-time-estimate

Version:

A Medium like read time estimate with more accuracy and customisable values

3 lines (2 loc) 1.42 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).speedometer=t()}(this,function(){"use strict";const e=275,t=12,n=500,o=["img","Image"];function r(e=t,n=o,r){let i=0;const u=function(e,t){const n=e.join("|"),o=new RegExp(`<(${n})([\\w\\W]+?)[\\/]?>`,"g");return(t.match(o)||[]).length}(n,r);return{time:(i=u>10?u/2*(e+3)+3*(u-10):u/2*(2*e+(1-u)))/60,count:u}}function i(t,o=e){const{count:r,time:i,formattedString:u}=function(e){const t=new RegExp("[぀-ヿ㐀-䶿一-鿿豈-﫿ヲ-゚]","g"),o=(e.match(t)||[]).length;return{count:o,time:o/n,formattedString:e.replace(t,"")}}(t),c=function(e){const t=new RegExp("\\w+","g");return(e.match(t)||[]).length}(u);return{characterCount:r,otherLanguageTime:i,wordTime:c/o,wordCount:c}}return function(e,t,n,o,u){const{time:c,count:a}=r(n,u,e),m=function(e){const t=new RegExp("<\\w+(\\s+(\"[^\"]*\"|\\'[^\\']*'|[^>])+)?>|<\\/\\w+>","gi");return e.replace(t,"")}(function(e){return e.replace(/^\s+/,"").replace(/\s+$/,"")}(e)),{characterCount:g,otherLanguageTime:s,wordTime:f,wordCount:d}=i(m,t);return{humanizedDuration:(h=c+f,h<.5?"less than a minute":h>=.5&&h<1.5?"1 minute":`${Math.ceil(h)} minutes`),duration:c+f,totalWords:d,wordTime:f,totalImages:a,imageTime:c,otherLanguageTimeCharacters:g,otherLanguageTime:s};var h}}); //# sourceMappingURL=read-time-estimate.min.js.map