@univ-lehavre/atlas-validators ​
Shared validation utilities for Atlas applications.
About ​
This package provides reusable validation functions for Atlas applications, including email validation, JSON body parsing, and data normalization.
Features ​
- Email validation: RFC 5322 validation with ReDoS attack protection
- Hexadecimal validation: Appwrite identifiers and token validation
- JSON parsing: Content-Type validation and secure request body parsing
- Email normalization: Lowercase conversion and subaddressing removal
Installation ​
bash
pnpm add @univ-lehavre/atlas-validatorsUsage ​
typescript
import {
isEmail,
isHexadecimal,
normalizeEmail,
ensureJsonContentType,
parseJsonBody,
validateAndParseJsonBody,
} from '@univ-lehavre/atlas-validators';
// Validate an email
if (isEmail('user@example.com')) {
console.log('Valid email');
}
// Normalize an email
const normalized = normalizeEmail('User+tag@Example.COM');
// -> 'user@example.com'
// Validate and parse a request body
const body = await validateAndParseJsonBody(request);API ​
| Function | Description |
|---|---|
isEmail(email) | Validates if a string is a valid email |
isHexadecimal(str) | Validates if a string contains only hexadecimal characters |
normalizeEmail(email) | Normalizes an email (lowercase, without subaddressing) |
ensureJsonContentType(request) | Checks that Content-Type is application/json |
parseJsonBody(request) | Parses and validates the JSON body of a request |
validateAndParseJsonBody(request) | Combines ensureJsonContentType and parseJsonBody |
Scripts ​
bash
pnpm -F @univ-lehavre/atlas-validators dev # Development
pnpm -F @univ-lehavre/atlas-validators build # Build
pnpm -F @univ-lehavre/atlas-validators test # Tests
pnpm -F @univ-lehavre/atlas-validators lint # ESLintDocumentation ​
Organization ​
This package is part of Atlas, a set of tools developed by Le Havre Normandie University to facilitate research and collaboration between researchers.
Atlas is developed as part of two projects led by Le Havre Normandie University:
- Campus Polytechnique des Territoires Maritimes et Portuaires: research and training program focused on maritime and port issues
- EUNICoast: European university alliance bringing together institutions located in European coastal areas
License ​
MIT
Functions ​
| Function | Description |
|---|---|
| ensureJsonContentType | Validates that the request has a JSON content type. Throws InvalidContentTypeError if the content type is not application/json. |
| isEmail | Validates if a string is a valid email address. Uses RFC 5322 compliant regex with ReDoS protection. |
| isHexadecimal | Validates if a string contains only hexadecimal characters. Used for validating Appwrite user IDs and session tokens. |
| normalizeEmail | Normalizes an email address. - Converts to lowercase - Removes subaddressing (everything after + in the local part) |
| parseJsonBody | Parses and validates the JSON body of a request. Ensures the body is a valid JSON object (not an array or primitive). |
| validateAndParseJsonBody | Validates a request body with JSON content type and parses it. Combines ensureJsonContentType and parseJsonBody. |