Files
P4RS3LT0NGV3/src/transformers/encoding/base45.js
T
Dustin Farley dc10a90851 refactor: migrate to modular tool-based architecture
- Implement tool registry system with individual tool modules
- Reorganize transformers into categorized source modules
- Remove emojiLibrary.js, consolidate into EmojiUtils and emojiData
- Fix mobile close button and tooltip functionality
- Add build system for transforms and emoji data
- Migrate from Python backend to pure JavaScript
- Add comprehensive documentation and testing
- Improve code organization and maintainability
- Ignore generated files (transforms-bundle.js, emojiData.js)
2025-12-02 20:26:32 -08:00

45 lines
1.8 KiB
JavaScript

// base45 transform
import BaseTransformer from '../BaseTransformer.js';
export default new BaseTransformer({
name: 'Base45',
priority: 290,
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:',
func: function(text) {
const bytes = new TextEncoder().encode(text);
const chars = [];
for (let i=0;i<bytes.length;i+=2) {
if (i+1 < bytes.length) {
const x = 256*bytes[i] + bytes[i+1];
const e = x % 45; const d = Math.floor(x/45) % 45; const c = Math.floor(x/45/45);
chars.push(this.alphabet[e], this.alphabet[d], this.alphabet[c]);
} else {
const x = bytes[i];
const e = x % 45; const d = Math.floor(x/45);
chars.push(this.alphabet[e], this.alphabet[d]);
}
}
return chars.join('');
},
preview: function(text) {
if (!text) return 'QED8W';
return this.func(text.slice(0,3));
},
reverse: function(text) {
const index = {}; for (let i=0;i<this.alphabet.length;i++) index[this.alphabet[i]] = i;
const codes = [...text].map(c => index[c]).filter(v => v !== undefined);
const out = [];
for (let i=0;i<codes.length;i+=3) {
if (i+2 < codes.length) {
const x = codes[i] + codes[i+1]*45 + codes[i+2]*45*45;
out.push(x >> 8, x & 0xFF);
} else if (i+1 < codes.length) {
const x = codes[i] + codes[i+1]*45;
out.push(x & 0xFF);
}
}
return new TextDecoder().decode(Uint8Array.from(out));
}
});