mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
# Description of Changes - Addition of the remove pages tool - Addition of the remove blank pages tool --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details.
24 lines
903 B
TypeScript
24 lines
903 B
TypeScript
export const validatePageNumbers = (pageNumbers: string): boolean => {
|
|
if (!pageNumbers.trim()) return false;
|
|
|
|
// Normalize input for validation: remove spaces around commas and other spaces
|
|
const normalized = pageNumbers.replace(/\s*,\s*/g, ',').replace(/\s+/g, '');
|
|
const parts = normalized.split(',');
|
|
|
|
// Regular expressions for different page number formats
|
|
const allToken = /^all$/i; // Select all pages
|
|
const singlePageRegex = /^[1-9]\d*$/; // Single page: positive integers only (no 0)
|
|
const rangeRegex = /^[1-9]\d*-(?:[1-9]\d*)?$/; // Range: 1-5 or open range 10-
|
|
const mathRegex = /^(?=.*n)[0-9n+\-*/() ]+$/; // Mathematical expressions with n and allowed chars
|
|
|
|
return parts.every(part => {
|
|
if (!part) return false;
|
|
return (
|
|
allToken.test(part) ||
|
|
singlePageRegex.test(part) ||
|
|
rangeRegex.test(part) ||
|
|
mathRegex.test(part)
|
|
);
|
|
});
|
|
};
|