Files
SnowLuma/.pnpm-store/v11/files/53/58a07abfeec61c69ae1ecfcc9d9188ad78258a85ee3f97b0f18216f846025d486e5754146ffdbc4580a46c814acc96f1d039c107f0ccafc3eba9b010144009
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

38 lines
1.1 KiB
Plaintext

import { LooseObject, MatchExtended } from '../types'
export const empty = (obj: LooseObject) => Object.keys(obj).length === 0
export const extend = (listToExtend: any[], list: any[]) =>
// eslint-disable-next-line prefer-spread
listToExtend.push.apply(listToExtend, list)
export const translate = (string: string, chrMap: LooseObject) => {
const keys = Object.keys(chrMap)
if (keys.length === 0) {
return string
}
const pattern = keys
.map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
.join('|')
const regex = new RegExp(pattern, 'g')
return string.replace(regex, (matched) => chrMap[matched])
}
// mod implementation that works for negative numbers
export const mod = (n: number, m: number) => ((n % m) + m) % m
// sort on i primary, j secondary
export const sorted = (matches: MatchExtended[]) =>
matches.sort((m1, m2) => m1.i - m2.i || m1.j - m2.j)
export const buildRankedDictionary = (orderedList: any[]) => {
const result: LooseObject = {}
let counter = 1 // rank starts at 1, not 0
orderedList.forEach((word) => {
result[word] = counter
counter += 1
})
return result
}