Рефакторинг
This commit is contained in:
25
src/lib/common/utils/file.util.js
Normal file
25
src/lib/common/utils/file.util.js
Normal file
@ -0,0 +1,25 @@
|
||||
// lib/common/utils/file.util.js
|
||||
|
||||
/**
|
||||
* Определение типа файла
|
||||
* @param {File} file
|
||||
* @returns {'image' | 'pdf' | 'other'}
|
||||
*/
|
||||
export function detectFileType(file) {
|
||||
if (!file) return 'other';
|
||||
if (file.type.startsWith('image/')) return 'image';
|
||||
if (file.type === 'application/pdf') return 'pdf';
|
||||
return 'other';
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирование текстовой метки выбранных страниц
|
||||
* @param {import('$lib/pages/print/stores/print.store.svelte').FileEntry} entry
|
||||
*/
|
||||
export function pagesLabel(entry) {
|
||||
if (!entry.totalPages || entry.totalPages === 0) return '...';
|
||||
if (!entry.selectedPages || entry.selectedPages.size === 0) return 'Нет';
|
||||
if (entry.selectedPages.size === entry.totalPages) return 'Все';
|
||||
if (entry.selectedPages.size === 1) return `стр. ${[...entry.selectedPages][0]}`;
|
||||
return `${entry.selectedPages.size} из ${entry.totalPages}`;
|
||||
}
|
||||
37
src/lib/common/utils/pricing.util.js
Normal file
37
src/lib/common/utils/pricing.util.js
Normal file
@ -0,0 +1,37 @@
|
||||
// lib/common/utils/pricing.util.js
|
||||
|
||||
export const QUALITIES = [
|
||||
{ id: 'low', label: 'Эконом' },
|
||||
{ id: 'medium', label: 'Стандарт' },
|
||||
{ id: 'high', label: 'Максимум' }
|
||||
];
|
||||
|
||||
export const COLOR_MODES = [
|
||||
{ id: 'bw', label: 'Чб' },
|
||||
{ id: 'color', label: 'Цвет' }
|
||||
];
|
||||
|
||||
export const FORMATS = ['A4', 'A5'];
|
||||
|
||||
/**
|
||||
* Расчет цены за страницу в зависимости от объема
|
||||
*/
|
||||
export function getPricePerPage(pagesCount) {
|
||||
if (pagesCount >= 1000) return 4;
|
||||
if (pagesCount >= 25) return 9;
|
||||
return 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Плюрализация
|
||||
*/
|
||||
export function pluralize(n, forms) {
|
||||
const mod10 = n % 10;
|
||||
const mod100 = n % 100;
|
||||
if (mod10 === 1 && mod100 !== 11) return forms[0];
|
||||
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 10 || mod100 > 14)) return forms[1];
|
||||
return forms[2];
|
||||
}
|
||||
|
||||
export const plFiles = (n) => pluralize(n, ['файл', 'файла', 'файлов']);
|
||||
export const plCopies = (n) => pluralize(n, ['копия', 'копии', 'копий']);
|
||||
Reference in New Issue
Block a user