Skip to content

@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-validators

Usage ​

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 ​

FunctionDescription
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     # ESLint

Documentation ​

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:


Le Havre Normandie University     Campus Polytechnique des Territoires Maritimes et Portuaires     EUNICoast

License ​

MIT

Functions ​

FunctionDescription
ensureJsonContentTypeValidates that the request has a JSON content type. Throws InvalidContentTypeError if the content type is not application/json.
isEmailValidates if a string is a valid email address. Uses RFC 5322 compliant regex with ReDoS protection.
isHexadecimalValidates if a string contains only hexadecimal characters. Used for validating Appwrite user IDs and session tokens.
normalizeEmailNormalizes an email address. - Converts to lowercase - Removes subaddressing (everything after + in the local part)
parseJsonBodyParses and validates the JSON body of a request. Ensures the body is a valid JSON object (not an array or primitive).
validateAndParseJsonBodyValidates a request body with JSON content type and parses it. Combines ensureJsonContentType and parseJsonBody.