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
- d105d8a9Records: mpackdb integrity check cleanmre
- 6e980c53Records: mpackdb rule refinementmre
- 6d335ac4Records: storage copy rulingmre
- 7eb2898dRecords: mpackdb second-opener rule until day38mre
- b011f98eRecords: style form live on day35mre
- 60d90cb2Records: L1 woken for the restartmre
- 75ae544fRecords: restart waits for the connection to closemre
- e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
- f2b5db98styles: format styles with nested rules and bare queriesmre
- f036bab4search: format styles with nested rules and bare queriesmre
- ef9a9d4asongs: format styles with nested rules and bare queriesmre
- f22f9aacmain: format styles with nested rules and bare queriesmre
- f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
- d56e5054Sync theme and shared tokens from layouts 17e0f03mre
- b1362547Re-vendor to Hybriel set day35mre
- 89e10f08Records: mission 002 rollback wordingmre
- 9485dee7Records: mission 002 brief (live step)mre
- 9ba68fe7Records: S1b reviewedmre
- 193dfff1Records: S1 result, S1b startedmre
- 028ed776Records: mission 001 continuation S1bmre