GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — javascript-toolkit/utils/bionic-reading.js at main · virtualitems/javascript-toolkit Expand file tree/ Copy pathbionic-reading.jsMore file actions 55 lines (42 loc) · 953 Bytes / Copy pathbionic-reading.jsFile metadata and controls55 lines (42 loc) · 953 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 /** * Bold text * * @param {string} word */ const bold = function (word) { return `<b>${word}</b>`; }; /** * Delete non letter characters * * @param {string} word */ const clean = function (word) { return word.replace(/[^a-zA-Z0-9]/g, ''); }; /** * Transforms an array of words into a Bionic Reading format * * @param {string[]} words * @returns {string[]} */ const transformer = function (words) { if (!Array.isArray(words)) { throw new Error('words must be an array'); } return words.map(w => { const clear = clean(w); const length = clear.length; if (length === 0) { return w; } else if (length === 1) { return bold(w); } const offset = Math.max(0, w.search(/[a-zA-Z0-9]/)); const end = Math.ceil(length / 2); const extra = Math.floor(length / 8); const result = offset + end + extra; return bold(w.substring(0, result)) + w.substring(result); }); }; |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |