mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-04 01:03:25 +00:00
* FIX - repair inventory metadata and ESX contracts Use the stable core_inventory metadata setter and validate the complete inventory adapter contract after provider bridges load. Preserve the real ESX configuration error instead of cascading into a missing RegisterUsableItem failure. * FIX - clarify phone opening without SIM * FIX - harden inventory and device contracts Validate SIM number configuration before item handling, preserve QB metadata mutation contracts, and propagate phone-open failures to callers. Extend regression coverage for inventory bridges and device bootstrap errors. * FIX - resolve reported phone interaction issues Stop game-input passthrough while NUI text fields are focused and add an independent hold-to-look option. Propagate SIM number formatting to the frontend, migrate configured currency symbols to utf8mb4, and clarify SkyRide, VaultX, and DarkChat behavior with focused contract coverage. * FIX - detect missing packaged phone UI Validate the generated NUI entrypoint, its referenced assets, and required static media when the resource starts. Print an actionable server-console warning for incomplete source archives, package phone sounds through the manifest, and cover the detection contract with Lua regressions.
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import type { PhoneNumberFormat } from '@/types/phone'
|
|
|
|
export const PHONE_NUMBER_LENGTH = 10
|
|
const DEFAULT_PHONE_NUMBER_FORMAT: PhoneNumberFormat = {
|
|
groups: [3, 3, 4],
|
|
length: PHONE_NUMBER_LENGTH,
|
|
}
|
|
let phoneNumberFormat: PhoneNumberFormat = DEFAULT_PHONE_NUMBER_FORMAT
|
|
|
|
export function configurePhoneNumberFormat(value?: PhoneNumberFormat): void {
|
|
const length = value?.length
|
|
const groups = value?.groups
|
|
if (
|
|
typeof length !== 'number' ||
|
|
!Number.isInteger(length) ||
|
|
length < 1 ||
|
|
length > 24 ||
|
|
!Array.isArray(groups) ||
|
|
groups.length === 0 ||
|
|
groups.some((group) => !Number.isInteger(group) || group < 1)
|
|
) {
|
|
phoneNumberFormat = DEFAULT_PHONE_NUMBER_FORMAT
|
|
return
|
|
}
|
|
|
|
phoneNumberFormat = {
|
|
groups: [...groups],
|
|
length,
|
|
}
|
|
}
|
|
|
|
export function normalizePhoneNumber(value: string): string | null {
|
|
const digits = value.replace(/\D/g, '')
|
|
return digits.length === phoneNumberFormat.length ? digits : null
|
|
}
|
|
|
|
export function formatPhoneNumber(value: string | number): string {
|
|
const digits = String(value)
|
|
.replace(/\D/g, '')
|
|
.slice(0, phoneNumberFormat.length)
|
|
const formatted: string[] = []
|
|
let offset = 0
|
|
|
|
for (const size of phoneNumberFormat.groups) {
|
|
const group = digits.slice(offset, offset + size)
|
|
if (!group) break
|
|
formatted.push(group)
|
|
offset += size
|
|
}
|
|
if (offset < digits.length) formatted.push(digits.slice(offset))
|
|
|
|
return formatted.join(' ')
|
|
}
|