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