UNPKG

loccon

Version:

A simple local context storage and management tool with CLI and web interfaces. Store, search, and organize code snippets, notes, and development contexts with sharded JSON storage.

71 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Validator = exports.ValidationError = void 0; class ValidationError extends Error { constructor(message) { super(message); this.name = 'ValidationError'; } } exports.ValidationError = ValidationError; class Validator { static validateTag(tag) { if (!tag || typeof tag !== 'string') { throw new ValidationError('Tag must be a non-empty string'); } if (tag.trim() !== tag) { throw new ValidationError('Tag cannot have leading or trailing whitespace'); } if (tag.length === 0) { throw new ValidationError('Tag cannot be empty'); } if (tag.length > 100) { throw new ValidationError('Tag cannot be longer than 100 characters'); } // Check for invalid characters const invalidChars = /[<>:"/\\|?*\x00-\x1f]/; if (invalidChars.test(tag)) { throw new ValidationError('Tag contains invalid characters'); } } static validateContent(content) { if (typeof content !== 'string') { throw new ValidationError('Content must be a string'); } if (content.length === 0) { throw new ValidationError('Content cannot be empty'); } // Check for reasonable size limit (1MB) if (content.length > 1024 * 1024) { throw new ValidationError('Content cannot exceed 1MB'); } } static validateCategories(categories) { if (!Array.isArray(categories)) { throw new ValidationError('Categories must be an array'); } for (const category of categories) { if (typeof category !== 'string') { throw new ValidationError('All categories must be strings'); } if (category.trim() !== category) { throw new ValidationError('Categories cannot have leading or trailing whitespace'); } if (category.length === 0) { throw new ValidationError('Categories cannot be empty strings'); } if (category.length > 50) { throw new ValidationError('Categories cannot be longer than 50 characters'); } } if (categories.length > 20) { throw new ValidationError('Cannot have more than 20 categories'); } } static sanitizeInput(input) { // Remove null bytes and other control characters except newlines and tabs return input.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ''); } } exports.Validator = Validator; //# sourceMappingURL=validation.js.map