UNPKG

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

39 lines (38 loc) 1.44 kB
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */ 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 };