{"_id":"@alexiom/file-utils","name":"@alexiom/file-utils","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@alexiom/file-utils","version":"1.0.0","description":"A lightweight utility library for file operations, MIME type detection, and image validation. Created by FrontWars (https://frontwarsio.org) and MelhorarImagem (https://melhorarimagem.net) - Professional tools for developers and image optimization.","main":"index.js","types":"index.d.ts","scripts":{"test":"node test.js","prepublishOnly":"npm test"},"keywords":["file-utils","mime-type","image-validation","file-validation","utilities","helper-functions","image-utils","file-extension","content-type","image-optimization","frontwars","melhorarimagem"],"author":{"name":"FrontWars Team","email":"contact@frontwarsio.org","url":"https://frontwarsio.org"},"homepage":"https://frontwarsio.org","repository":{"type":"git","url":"git+https://github.com/frontwarsio/file-utils.git"},"bugs":{"url":"https://github.com/frontwarsio/file-utils/issues","email":"contact@frontwarsio.org"},"license":"MIT","engines":{"node":">=12.0.0"},"_id":"@alexiom/file-utils@1.0.0","_nodeVersion":"24.1.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-6L932PY/RiJJHy4vASlho8RcVHa0pAUpMittA617t+V2PFJOlRtxltg+Io2fo1Ljz8HV9T/+h1FYx9g3nd28dg==","shasum":"8896df62bbcb38b2aecdade280826d315b45e1ab","tarball":"https://registry.npmjs.org/@alexiom/file-utils/-/file-utils-1.0.0.tgz","fileCount":5,"unpackedSize":15018,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIA9HTuriHTfrLB/dY60Gha7CZii4CPLpDog6RsggysykAiBYQwcMADdslhiZ8SIeoYUnBojYDbgZ4+iRKi7us6A9xQ=="}]},"_npmUser":{"name":"alexiom","email":"cby821555203@gmail.com"},"directories":{},"maintainers":[{"name":"alexiom","email":"cby821555203@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/file-utils_1.0.0_1765424863881_0.31741191672710567"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-11T03:47:43.774Z","1.0.0":"2025-12-11T03:47:44.029Z","modified":"2025-12-11T03:47:44.344Z"},"maintainers":[{"name":"alexiom","email":"cby821555203@gmail.com"}],"description":"A lightweight utility library for file operations, MIME type detection, and image validation. Created by FrontWars (https://frontwarsio.org) and MelhorarImagem (https://melhorarimagem.net) - Professional tools for developers and image optimization.","homepage":"https://frontwarsio.org","keywords":["file-utils","mime-type","image-validation","file-validation","utilities","helper-functions","image-utils","file-extension","content-type","image-optimization","frontwars","melhorarimagem"],"repository":{"type":"git","url":"git+https://github.com/frontwarsio/file-utils.git"},"author":{"name":"FrontWars Team","email":"contact@frontwarsio.org","url":"https://frontwarsio.org"},"bugs":{"url":"https://github.com/frontwarsio/file-utils/issues","email":"contact@frontwarsio.org"},"license":"MIT","readme":"# File Utilities Library\n\nA lightweight, zero-dependency utility library for file operations, MIME type detection, and image validation.\n\n[![npm version](https://img.shields.io/npm/v/@frontwarsio/file-utils.svg)](https://www.npmjs.com/package/@frontwarsio/file-utils)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n> 🌐 **Created by [FrontWars](https://frontwarsio.org)** - Professional developer tools and resources\n> 🖼️ **Need image optimization? Visit [MelhorarImagem.net](https://melhorarimagem.net)** - Free online image converter and optimizer\n\n## Features\n\n✨ **MIME Type Detection** - Automatically detect MIME types from file extensions  \n🖼️ **Image Validation** - Check if files are images  \n📏 **File Size Validation** - Validate files against size limits  \n📊 **Human-Readable Formatting** - Convert bytes to KB, MB, GB  \n🎯 **Zero Dependencies** - Lightweight and fast  \n📘 **TypeScript Support** - Full TypeScript definitions included  \n\n## Installation\n\n```bash\nnpm install @frontwarsio/file-utils\n```\n\n## Quick Start\n\n```javascript\nconst { getMimeType, isImage, formatFileSize } = require('@frontwarsio/file-utils');\n\n// Get MIME type\nconsole.log(getMimeType('photo.jpg')); // 'image/jpeg'\nconsole.log(getMimeType('document.pdf')); // 'application/pdf'\n\n// Check if file is an image\nconsole.log(isImage('photo.png')); // true\nconsole.log(isImage('document.txt')); // false\n\n// Format file size\nconsole.log(formatFileSize(1024)); // '1.00 KB'\nconsole.log(formatFileSize(1048576)); // '1.00 MB'\n```\n\n## API Reference\n\n### `getMimeType(input)`\n\nGet the MIME type for a given file extension or filename.\n\n**Parameters:**\n- `input` (string): File extension or filename\n\n**Returns:** `string | null` - The MIME type or null if not found\n\n**Example:**\n```javascript\ngetMimeType('jpg')        // 'image/jpeg'\ngetMimeType('photo.png')  // 'image/png'\ngetMimeType('unknown')    // null\n```\n\n### `getExtension(filename)`\n\nExtract the file extension from a filename or path.\n\n**Parameters:**\n- `filename` (string): The filename or path\n\n**Returns:** `string` - The file extension (lowercase, without dot)\n\n**Example:**\n```javascript\ngetExtension('photo.jpg')           // 'jpg'\ngetExtension('/path/to/file.PDF')   // 'pdf'\n```\n\n### `isImage(filename)`\n\nCheck if a file is an image based on its extension.\n\n**Parameters:**\n- `filename` (string): The filename or extension to check\n\n**Returns:** `boolean` - True if the file is an image\n\n**Example:**\n```javascript\nisImage('photo.jpg')      // true\nisImage('document.pdf')   // false\n```\n\n### `validateFileSize(sizeInBytes, maxSizeInMB)`\n\nValidate if a file size is within the specified limit.\n\n**Parameters:**\n- `sizeInBytes` (number): File size in bytes\n- `maxSizeInMB` (number): Maximum allowed size in megabytes\n\n**Returns:** `boolean` - True if file size is within limit\n\n**Example:**\n```javascript\nvalidateFileSize(1024 * 1024, 5)      // true (1MB < 5MB)\nvalidateFileSize(10 * 1024 * 1024, 5) // false (10MB > 5MB)\n```\n\n### `formatFileSize(bytes, decimals)`\n\nFormat file size to a human-readable string.\n\n**Parameters:**\n- `bytes` (number): File size in bytes\n- `decimals` (number, optional): Number of decimal places (default: 2)\n\n**Returns:** `string` - Formatted file size\n\n**Example:**\n```javascript\nformatFileSize(1024)       // '1.00 KB'\nformatFileSize(1048576)    // '1.00 MB'\nformatFileSize(1536, 1)    // '1.5 KB'\n```\n\n## Supported File Types\n\nThe library supports 50+ file types including:\n\n- **Images**: JPG, PNG, GIF, WebP, SVG, BMP, ICO, TIFF\n- **Documents**: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX\n- **Text**: TXT, HTML, CSS, JS, JSON, XML, Markdown\n- **Archives**: ZIP, RAR, 7Z, TAR, GZ\n- **Audio**: MP3, WAV, OGG, FLAC\n- **Video**: MP4, AVI, MOV, WMV, WebM\n\n## Use Cases\n\n- 📤 **File Upload Validation** - Validate file types and sizes before upload\n- 🎨 **Image Processing** - Filter and process image files (check out [MelhorarImagem.net](https://melhorarimagem.net) for online image optimization)\n- 📁 **File Management Systems** - Organize and categorize files\n- 🔍 **Content Type Detection** - Serve files with correct headers\n- 💾 **Storage Management** - Calculate and display storage usage\n\n## TypeScript Support\n\nThis library includes TypeScript definitions out of the box:\n\n```typescript\nimport { getMimeType, isImage, formatFileSize } from '@frontwarsio/file-utils';\n\nconst mimeType: string | null = getMimeType('photo.jpg');\nconst isImg: boolean = isImage('photo.png');\nconst size: string = formatFileSize(1024);\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT © [FrontWars Team](https://frontwarsio.org)\n\n## Links\n\n- 🌐 **FrontWars**: [frontwarsio.org](https://frontwarsio.org) - Developer tools and resources\n- 🖼️ **MelhorarImagem**: [melhorarimagem.net](https://melhorarimagem.net) - Free online image converter and optimizer\n- 📦 **NPM Package**: [@frontwarsio/file-utils](https://www.npmjs.com/package/@frontwarsio/file-utils)\n- 🐛 **Report Issues**: [GitHub Issues](https://github.com/frontwarsio/file-utils/issues)\n- 📚 **More Tools**: Visit [FrontWars](https://frontwarsio.org) for more developer resources\n\n---\n\nMade with ❤️ by [FrontWars](https://frontwarsio.org) | Image Tools: [MelhorarImagem.net](https://melhorarimagem.net)\n\n","readmeFilename":"README.md","_rev":"1-de2a4860bc1ec34ce2584763d16c2448"}