react-hook-reading-time
Version:
Medium's like reading time estimation for React.
2 lines (1 loc) • 810 B
JavaScript
function t(t,e=275){const{count:n,time:r,formattedText:c}=function(t){const e=new RegExp("[-ヿ㐀-䶿一-鿿豈-ヲ-゚]","g"),n=(t.match(e)||[]).length;return{count:n,time:n/500,formattedText:t.replace(e,"")}}(t),o=function(t){const e=new RegExp("\\w+","g");return(t.match(e)||[]).length}(c);return{characters:n,otherLanguageTime:r,words:o,time:o/e}}function e(t){return t<.5?"less than a min":t>=.5&&t<1.5?"1 min read":Math.ceil(t)+" min read"}function n(t){return t<.5?.5:t>=.5&&t<1.5?1:Math.ceil(t)}function r(r){const c=function(t){const e=new RegExp("<\\w+(\\s+(\"[^\"]*\"|\\'[^\\']*'|[^>])+)?>|<\\/\\w+>","gi");return t.replace(e,"")}(function(t){return t.replace(/^\s+/,"").replace(/\s+$/,"")}(r)),{time:o,words:i}=t(c);return{text:e(o),minutes:n(o),words:i,time:o}}export{r as useReadingTime};