fix some bugs
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const DEFAULT_MAIN_METAL = 'طلا'
|
||||
|
||||
const mainMetalRef = ref(DEFAULT_MAIN_METAL)
|
||||
|
||||
export function resolveMainMetal(value?: string | number | null): string {
|
||||
const normalized = value?.toString().trim()
|
||||
return normalized || DEFAULT_MAIN_METAL
|
||||
}
|
||||
|
||||
export function setCachedMainMetal(value?: string | number | null): void {
|
||||
mainMetalRef.value = resolveMainMetal(value)
|
||||
}
|
||||
|
||||
export function getMainMetal(): string {
|
||||
return mainMetalRef.value
|
||||
}
|
||||
|
||||
export function useMainMetalRef() {
|
||||
return mainMetalRef
|
||||
}
|
||||
|
||||
/** جایگزینی طلایی/طلای/طلا با نام فلز — بدون صفت مسی/طلایی */
|
||||
export function applyMainMetalText(text: string, mainMetal = getMainMetal()): string {
|
||||
if (!text || mainMetal === DEFAULT_MAIN_METAL) return text
|
||||
|
||||
return text
|
||||
.replace(/طلایی/g, mainMetal)
|
||||
.replace(/طلای/g, mainMetal)
|
||||
.replace(/طلا/g, mainMetal)
|
||||
}
|
||||
|
||||
export function m(text: string): string {
|
||||
return applyMainMetalText(text)
|
||||
}
|
||||
Reference in New Issue
Block a user