Skip to content

TypeScript API / laikacms/sanitizer / Sanitizer

Interface: Sanitizer ​

Abstract sanitizer interface

Implementations should:

  • Throw errors for unsupported file types (unless in ignoreExtensions)
  • Throw errors for corrupted files
  • Throw errors for files exceeding maxFileSize
  • Return sanitized data with metadata about what was stripped

Methods ​

canSanitize() ​

ts
canSanitize(data): object;

Check if a file can be sanitized (without actually sanitizing it) Useful for validation before upload

Parameters ​

ParameterType
dataUint8Array

Returns ​

object

canSanitize ​
ts
canSanitize: boolean;
detectedType ​
ts
detectedType: string;
reason? ​
ts
optional reason?: string;

getSupportedFileTypes() ​

ts
getSupportedFileTypes(): readonly string[];

Get a list of supported file types/extensions

Returns ​

readonly string[]


sanitize() ​

ts
sanitize(
   data, 
   options?, 
   expectedMimeType?
): Promise<SanitizeResult>;

Sanitize a file, stripping privacy-sensitive metadata

Parameters ​

ParameterTypeDescription
dataUint8ArrayThe file data as a Uint8Array
options?SanitizeOptionsSanitization options
expectedMimeType?stringOptional expected MIME type for validation

Returns ​

Promise<SanitizeResult>

SanitizeResult - the sanitized file data and metadata

Throws ​

Error if file type is not supported, file is corrupted, or file is too large

Released under the MIT License.