on-codemerge
Version:
A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product
38 lines (37 loc) • 1.2 kB
JavaScript
var p = Object.defineProperty;
var u = (r, e, t) => e in r ? p(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var s = (r, e, t) => u(r, typeof e != "symbol" ? e + "" : e, t);
import { createContainer as c } from "../../../utils/helpers.mjs";
class M {
constructor() {
s(this, "WORDS_PER_MINUTE", 200);
}
calculate(e) {
const t = this.stripHTML(e), n = this.countWords(t), o = t.length, a = t.replace(/\s/g, "").length, i = this.countSentences(t), l = this.countParagraphs(e), h = Math.max(1, Math.ceil(n / this.WORDS_PER_MINUTE));
return {
characters: o,
charactersNoSpaces: a,
words: n,
sentences: i,
paragraphs: l,
readingTime: h
};
}
stripHTML(e) {
const t = c();
return t.innerHTML = e, t.textContent || t.innerText || "";
}
countWords(e) {
return e.trim().split(/\s+/).filter((t) => t.length > 0).length;
}
countSentences(e) {
return e.split(/[.!?]+/).filter((t) => t.trim().length > 0).length;
}
countParagraphs(e) {
const t = c();
return t.innerHTML = e, t.querySelectorAll("p, div:not(.editor-toolbar)").length || 1;
}
}
export {
M as StatisticsCalculator
};