SHA256
Обновить учёт поддержки, лайки и профиль перед MVP
This commit is contained in:
@@ -19,10 +19,10 @@ export function hexHash32(value) {
|
||||
return Uint8Array.from({ length: 32 }, (_, i) => parseInt(hex.slice(i * 2, i * 2 + 2), 16));
|
||||
}
|
||||
|
||||
/** Integer Star cents: 0.10 minimum, exactly two decimal places maximum. */
|
||||
/** Сумма поддержки: минимум и шаг 0,1 звезды. */
|
||||
export function parseStarCents(input) {
|
||||
const value = String(input ?? '').trim().replace(',', '.');
|
||||
if (!/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/.test(value)) throw new Error('Введите сумму ⭐ с точностью до 0,01');
|
||||
if (!/^(?:0|[1-9]\d*)(?:\.\d{1})?$/.test(value)) throw new Error('Введите сумму ⭐ с точностью до 0,1');
|
||||
const [whole, frac = ''] = value.split('.');
|
||||
const cents = BigInt(whole) * 100n + BigInt(frac.padEnd(2, '0') || '0');
|
||||
if (cents < 10n || cents > 0xffff_ffff_ffff_ffffn) throw new Error('Минимальная поддержка — 0,10 ⭐');
|
||||
@@ -31,10 +31,16 @@ export function parseStarCents(input) {
|
||||
/** Только число («0.10»): для вёрстки, где единица показана отдельной SVG-иконкой. */
|
||||
export function formatStarAmount(value) {
|
||||
const cents = BigInt(value);
|
||||
return `${cents / 100n}.${String(cents % 100n).padStart(2, '0')}`;
|
||||
const tenths = (cents + 5n) / 10n;
|
||||
return tenths === 0n ? '' : `${tenths / 10n}.${tenths % 10n}`;
|
||||
}
|
||||
export function formatStars(value) {
|
||||
return `${formatStarAmount(value)} ⭐`;
|
||||
const amount = formatStarAmount(value);
|
||||
return amount ? `${amount} ⭐` : '⭐';
|
||||
}
|
||||
export function formatExactStars(value) {
|
||||
const cents = BigInt(value);
|
||||
return `${cents / 100n}.${String(cents % 100n).padStart(2, '0')} ⭐`;
|
||||
}
|
||||
export function splitStarCents(value) {
|
||||
const cents = BigInt(value);
|
||||
|
||||
Reference in New Issue
Block a user