Merge pull request '[1252] 일본의 전각 숫자, 반각 함수변경' (#298) from dev into dev-deploy

Reviewed-on: #298
This commit is contained in:
ysCha 2025-08-22 10:05:33 +09:00
commit 5f9f508413
2 changed files with 29 additions and 6 deletions

View File

@ -22,7 +22,7 @@ import { stuffSearchState } from '@/store/stuffAtom'
import { QcastContext } from '@/app/QcastProvider'
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
import { useSwal } from '@/hooks/useSwal'
import { sanitizeDecimalInputEvent} from '@/util/input-utils'
import { sanitizeIntegerInputEvent } from '@/util/input-utils'
export default function StuffDetail() {
const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState)

View File

@ -24,15 +24,38 @@ export const onlyNumberWithDotInputChange = (e, callback) => {
// Number normalization utilities
// =============================
// 1) Normalize any string to NFKC and keep only ASCII digits 0-9.
// 1) Normalize any string to keep only ASCII digits 0-9
export function normalizeDigits(value) {
return String(value ?? '').normalize('NFKC').replace(/[^0-9]/g, '')
if (value == null) return '';
// First convert full-width numbers to half-width
const str = String(value).replace(/[-]/g, s =>
String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
);
// Then remove all non-digit characters
return str.replace(/\D/g, '');
}
// 2) Normalize decimal numbers (allow one dot).
// 2) Normalize decimal numbers (allow one dot)
export function normalizeDecimal(value) {
const s = String(value ?? '').normalize('NFKC').replace(/[^0-9.]/g, '')
const [head, ...rest] = s.split('.')
return rest.length ? `${head}.${rest.join('').replace(/\./g, '')}` : head
if (value == null) return '';
// Convert full-width numbers and dot to half-width
let str = String(value).replace(/[-]/g, s =>
s === '' ? '.' : String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
);
// Handle multiple dots by keeping only the first one
const parts = str.split('.');
if (parts.length > 1) {
str = parts[0] + '.' + parts.slice(1).join('');
}
// Remove any remaining non-digit and non-dot characters
// and ensure only one dot remains
return str.replace(/[^\d.]/g, '')
.replace(/^(\d*\.\d*).*$/, '$1');
}
// 2-1) Limit fractional digits for decimal numbers. Default to 2 digits.