jukebox
All repositories: gitoria
3.7 KB
// lib/util.hl — small helpers every topic shares: env, the storage folders, lists, text folding for search and sorting,// numbers from text. Statics only; no topic logic here.import { env } from 'hl:proc'// a newline (the language has no \n escape in a string: a literal line break)static NL = ""// the separator of sort keys: lower than every character a name can hold, so "alt" sorts before "alt lied"static SEP = String.fromCharCode(1)// A KEY FOR AN INDEX HAS NO COMMA: hl:mpackdb keeps an index as lines `key,offset,length`, and a key with a comma is lost when the// table is opened again (repro .scratch/mpackdb-comma-key/). Every indexed text goes through here: the comma becomes character 2.static safeKey = (s) => { return s.replaceAll(',', String.fromCharCode(2)) }static envOr = (name, fallback) => {v = env(name)return v != null && v.trim() != '' ? v.trim() : fallback}// WHERE THE APP WRITES: the table folder of the mpackdb tables, the settings file and the cover cache. All under// storage/ of the project (JUKEBOX_STORAGE overrides). A relative path resolves against the ENTRY SCRIPT's directory.// The music library itself is never written (README "Read only").static storageRoot = envOr('JUKEBOX_STORAGE', './storage')static storageDir = storageRoot + '/mpackdb'static coverDir = storageRoot + '/covers'static settingsFile = storageRoot + '/settings.json'// an empty list read from hl:mpackdb comes back without a `.length`: every found list goes through herestatic countOfList = (list) => {if (list == null) { return 0 }n = list.lengthreturn n == null ? 0 : n}// ---- numbers out of text (the language has no parseInt) --------------------------------------------// the leading run of digits of a text as a Number, or null when it does not start with one ("11/21" → 11)static leadingInt = (s) => {if (s == null) { return null }let n = 0let i = 0let seen = falsewhile (i < s.length) {c = s.charCodeAt(i)if (c < 48 || c > 57) { break }n = n * 10 + (c - 48)seen = truei = i + 1}return seen ? n : null}// a Number as digits padded with zeros to `width` (sort keys: "007")static padNumber = (n, width) => {let s = '' + nwhile (s.length < width) { s = '0' + s }return s}// ---- text folding: lower case, accents folded away (search and sort keys) --------------------------------static foldMap = {'ä' = 'a' 'ö' = 'o' 'ü' = 'u' 'ß' = 'ss' 'à' = 'a' 'á' = 'a' 'â' = 'a' 'ã' = 'a' 'å' = 'a' 'æ' = 'ae''ç' = 'c' 'è' = 'e' 'é' = 'e' 'ê' = 'e' 'ë' = 'e' 'ì' = 'i' 'í' = 'i' 'î' = 'i' 'ï' = 'i' 'ð' = 'd''ñ' = 'n' 'ò' = 'o' 'ó' = 'o' 'ô' = 'o' 'õ' = 'o' 'ø' = 'o' 'ù' = 'u' 'ú' = 'u' 'û' = 'u' 'ý' = 'y''ÿ' = 'y' 'þ' = 'th' 'œ' = 'oe' 'š' = 's' 'ž' = 'z' 'č' = 'c' 'ć' = 'c' 'ł' = 'l' 'ń' = 'n' 'ř' = 'r''ś' = 's' 'ź' = 'z' 'ż' = 'z' 'ď' = 'd' 'ě' = 'e' 'ę' = 'e' 'ą' = 'a' 'ő' = 'o' 'ű' = 'u' 'ů' = 'u''ğ' = 'g' 'ı' = 'i' 'ş' = 's' 'ț' = 't' 'ť' = 't' 'ň' = 'n' 'ā' = 'a' 'ē' = 'e' 'ī' = 'i' 'ō' = 'o' 'ū' = 'u'}static fold = (s) => {if (s == null) { return '' }low = s.toLowerCase()let out = ''let i = 0while (i < low.length) {ch = low[i]r = foldMap[ch]out = out + (r == null ? ch : r)i = i + 1}return out}// the file name without folders and extensionstatic baseName = (path) => {let n = pathk = n.lastIndexOf('/')if (k >= 0) { n = n.slice(k + 1) }d = n.lastIndexOf('.')if (d > 0) { n = n.slice(0, d) }return n}static folderOf = (path) => {k = path.lastIndexOf('/')return k > 0 ? path.slice(0, k) : '/'}static extOf = (path) => {k = path.lastIndexOf('.')s = path.lastIndexOf('/')return k > s ? path.slice(k + 1).toLowerCase() : ''}
Branches
Latest commits
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre
- a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
- f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
- d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
- df7920ceRecords: R3 startedmre
- 0549f038Mission 010: jb20 livemre
- 273494e2STATUS rewrittenmre
- 227c9b96Records: jb19 livemre
- 9f365376README: the bar's controls (jb19)mre
- d18851fdjb19: pressed switches look different (whole selector), queue column cannot widen past the panel, gates follow the new bar (jb3, jb11, jb15)mre