core utils updates

This commit is contained in:
Raven Scott
2026-04-03 22:34:08 -04:00
parent 32d3eaa833
commit 35ac6633ea
206 changed files with 12728 additions and 1080 deletions
+27 -3
View File
@@ -1,3 +1,27 @@
const TR_CLASS = {
'[:alnum:]':
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
'[:alpha:]': 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'[:blank:]': ' \t',
'[:cntrl:]': [...Array(32).keys()].map((i) => String.fromCharCode(i)).join('') + '\x7f',
'[:digit:]': '0123456789',
'[:lower:]': 'abcdefghijklmnopqrstuvwxyz',
'[:print:]': [...Array(95).keys()].map((i) => String.fromCharCode(i + 32)).join(''),
'[:punct:]': '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~',
'[:space:]': ' \t\n\r\v\f',
'[:upper:]': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'[:xdigit:]': '0123456789abcdefABCDEF'
}
/** @param {string} s */
function trExpandClasses(s) {
let out = s
for (const [name, chars] of Object.entries(TR_CLASS)) {
out = out.split(name).join(chars)
}
return out
}
async function run(ctx, argv) {
let del = false
const sets = []
@@ -12,14 +36,14 @@ async function run(ctx, argv) {
}
const s = bareStdin(ctx)
if (del) {
const kill = new Set(sets[0].split(''))
const kill = new Set(trExpandClasses(sets[0]).split(''))
let o = ''
for (const ch of s) if (!kill.has(ch)) o += ch
ctx.console.log(o)
return
}
const from = sets[0]
const to = sets[1]
const from = trExpandClasses(sets[0])
const to = trExpandClasses(sets[1])
const map = Object.create(null)
const n = Math.max(from.length, to.length)
for (let i = 0; i < n; i++) {