ZDDC/classifier/js/validator.js
ZDDC ea385b5366 Initial commit
ZDDC — Zero Day Document Control. A file-naming convention plus five
single-file HTML tools (archive, transmittal, classifier, mdedit,
landing) and an optional Go HTTP server (zddc-server) with ACL and a
virtual archive index. Self-contained, offline-capable, dependency-free.

See README.md for an overview, AGENTS.md and ARCHITECTURE.md for the
build/release/architecture detail, bootstrap/README.md for the
two-level deployment install pattern, and zddc/README.md for the
HTTP server.
2026-04-27 11:05:47 -05:00

48 lines
1.4 KiB
JavaScript

/**
* ZDDC Validation Module
* Validates file names against ZDDC conventions using the shared zddc library.
*/
(function() {
'use strict';
/**
* Validate a filename and return a detailed result.
* Delegates ZDDC pattern checking to the shared zddc.parseFilename() library.
*/
function validateFilename(filename) {
const errors = [];
const warnings = [];
if (!filename) {
errors.push('Filename is empty.');
return { isValid: false, warnings, errors };
}
const parsed = zddc.parseFilename(filename);
if (!parsed || !parsed.valid) {
errors.push('Filename does not match ZDDC format: trackingNumber_revision (status) - title.ext');
} else if (!zddc.isValidStatus(parsed.status)) {
errors.push('Invalid status code "' + parsed.status + '". Valid codes: ' + zddc.STATUSES.join(', '));
}
if (filename.length > 255) {
warnings.push('Filename is very long (>255 characters)');
}
const invalidChars = /[<>:"|?*]/;
if (invalidChars.test(filename)) {
errors.push('Filename contains invalid characters: < > : " | ? *');
}
return {
isValid: errors.length === 0,
warnings,
errors
};
}
window.app.modules.validator = {
validateFilename
};
})();