Files
zCode-CLI-X/~/.npm-cache/bidi-js@1.0.3@@@1/src/mirroring.js
admin 875c7f9b91 feat: Complete zCode CLI X with Telegram bot integration
- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
2026-05-05 09:01:26 +00:00

49 lines
1.3 KiB
JavaScript

import data from './data/bidiMirroring.data.js'
import { parseCharacterMap } from './util/parseCharacterMap.js'
let mirrorMap
function parse () {
if (!mirrorMap) {
//const start = performance.now()
const { map, reverseMap } = parseCharacterMap(data, true)
// Combine both maps into one
reverseMap.forEach((value, key) => {
map.set(key, value)
})
mirrorMap = map
//console.log(`mirrored chars parsed in ${performance.now() - start}ms`)
}
}
export function getMirroredCharacter (char) {
parse()
return mirrorMap.get(char) || null
}
/**
* Given a string and its resolved embedding levels, build a map of indices to replacement chars
* for any characters in right-to-left segments that have defined mirrored characters.
* @param string
* @param embeddingLevels
* @param [start]
* @param [end]
* @return {Map<number, string>}
*/
export function getMirroredCharactersMap(string, embeddingLevels, start, end) {
let strLen = string.length
start = Math.max(0, start == null ? 0 : +start)
end = Math.min(strLen - 1, end == null ? strLen - 1 : +end)
const map = new Map()
for (let i = start; i <= end; i++) {
if (embeddingLevels[i] & 1) { //only odd (rtl) levels
const mirror = getMirroredCharacter(string[i])
if (mirror !== null) {
map.set(i, mirror)
}
}
}
return map
}