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
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
- 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
- 1fecd6a7Merge branch 'records-day39' into mainJukebox
- d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
- 5fa19e89Merge branch 'day39' into mainJukebox
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox