UNPKG

@amth/druuid

Version:

Simple and secure file renaming utility using UUID

28 lines (27 loc) 1.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = __importDefault(require("./index")); describe('druuid', () => { it('should generate a UUID with correct extension', () => { const result = (0, index_1.default)({ extname: 'jpg' }); expect(result).toMatch(/^[a-f0-9]{36}\.jpg$/); }); it('should respect custom length parameter', () => { const result = (0, index_1.default)({ extname: 'png' }, 8); expect(result).toMatch(/^[a-f0-9]{8}\.png$/); }); it('should throw error if extension is missing', () => { expect(() => (0, index_1.default)({})).toThrow('File extension is required'); }); it('should limit length to maximum of 36', () => { const result = (0, index_1.default)({ extname: 'pdf' }, 50); expect(result).toMatch(/^[a-f0-9]{36}\.pdf$/); }); it('should handle minimum length of 1', () => { const result = (0, index_1.default)({ extname: 'txt' }, 0); expect(result).toMatch(/^[a-f0-9]{1}\.txt$/); }); });