s3-key-validator
Version:
AWS S3 object key validation library for TypeScript
51 lines (45 loc) • 1.65 kB
TypeScript
type ValidationMode = 'strict' | 'standard' | 'permissive';
interface ValidationOptions {
mode?: ValidationMode;
specialChars?: {
allowSlash?: boolean;
allowColon?: boolean;
allowSpace?: boolean;
allowAt?: boolean;
allowAmpersand?: boolean;
allowDollar?: boolean;
};
languages?: {
allowJapanese?: boolean;
allowKorean?: boolean;
allowChinese?: boolean;
allowCJK?: boolean;
};
additionalChars?: string[];
maxLength?: number;
allowRelativePaths?: boolean;
allowDotPrefix?: boolean;
}
interface ValidationResult {
isValid: boolean;
errors: ValidationError[];
warnings?: ValidationWarning[];
suggestions?: string[];
}
interface ValidationError {
type: 'LENGTH' | 'CHARACTER' | 'PATH' | 'ENCODING';
message: string;
position?: number;
character?: string;
}
interface ValidationWarning {
type: 'COMPATIBILITY' | 'PERFORMANCE' | 'SECURITY' | 'ENCODING';
message: string;
}
declare const strictPreset: ValidationOptions;
declare const standardPreset: ValidationOptions;
declare const permissivePreset: ValidationOptions;
declare function validateS3Key(key: string, options?: ValidationOptions): ValidationResult;
declare function isValidS3Key(key: string, options?: ValidationOptions): boolean;
declare function sanitizeS3Key(key: string, options?: ValidationOptions): string;
export { type ValidationError, type ValidationMode, type ValidationOptions, type ValidationResult, type ValidationWarning, isValidS3Key, permissivePreset, sanitizeS3Key, standardPreset, strictPreset, validateS3Key };