├── .gitignore ├── .npmignore ├── tsup.config.ts ├── tsconfig.json ├── package.json ├── README.MD └── src └── index.ts /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Build files 3 | /dist 4 | 5 | # Node Modules 6 | /node_modules 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | 2 | # Build files 3 | /src 4 | 5 | # Node Modules 6 | /node_modules 7 | 8 | # TS stuff 9 | tsconfig.json 10 | tsup.config.ts 11 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup'; 2 | 3 | export default defineConfig({ 4 | format: ['cjs', 'esm'], 5 | entry: ['./src/index.ts'], 6 | dts: true, 7 | shims: true, 8 | skipNodeModulesBundle: true, 9 | clean: true, 10 | }); -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "noImplicitAny": true, 5 | "esModuleInterop": true, 6 | "strictNullChecks": true, 7 | "target": "ES2022", 8 | "moduleResolution": "Node10", 9 | "module": "CommonJS", 10 | "declaration": true, 11 | "isolatedModules": true, 12 | "noEmit": true, 13 | "outDir": "dist" 14 | }, 15 | "include": ["src"], 16 | "exclude": ["node_modules"] 17 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "use-blob-to-file", 3 | "description": "A React hook for converting Data URLs / Blob files into File objects with a preview URL for easy viewing and uploading.", 4 | "version": "0.0.4", 5 | "main": "./dist/index.js", 6 | "module": "./dist/index.mjs", 7 | "types": "./dist/index.d.ts", 8 | "homepage": "https://github.com/MohammedIbrahim8887/use-blob-to-file", 9 | "repository": { 10 | "url": "https://github.com/MohammedIbrahim8887/use-blob-to-file" 11 | }, 12 | "scripts": { 13 | "build": "tsup" 14 | }, 15 | "keywords": [ 16 | "react", 17 | "hook", 18 | "blob", 19 | "file", 20 | "typescript", 21 | "blob to file", 22 | "data url to file" 23 | ], 24 | "author": "doughnut4641", 25 | "license": "MIT", 26 | "devDependencies": { 27 | "@types/react": "^18.3.3", 28 | "tsup": "^8.2.4", 29 | "typescript": "^5.5.4", 30 | "react": "^18.3.1" 31 | }, 32 | "dependencies": {} 33 | } -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # `useBlobToFile` 2 | 3 | A React hook for effortlessly converting Data URLs / Blob files into File objects, complete with a preview URL for easy viewing and uploading. 4 | 5 | ## 📦 Installation 6 | 7 | You can install the package using npm, Yarn, pnpm, or Bun: 8 | 9 | ### Using npm 10 | 11 | ```bash 12 | npm install use-blob-to-file 13 | ``` 14 | 15 | ### Using Yarn 16 | 17 | ```bash 18 | yarn add use-blob-to-file 19 | ``` 20 | 21 | ### Using pnpm 22 | 23 | ```bash 24 | pnpm add use-blob-to-file 25 | ``` 26 | 27 | ### Using Bun 28 | 29 | ```bash 30 | bun add use-blob-to-file 31 | ``` 32 | 33 | ## 🔧 Usage 34 | 35 | Import and use the `useBlobToFile` hook in your React components: 36 | 37 | ```jsx 38 | import React from 'react'; 39 | import useBlobToFile from 'use-blob-to-file'; 40 | 41 | const MyComponent = () => { 42 | const dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA...'; // Replace with your Data URL 43 | const filename = 'my-image.png'; 44 | 45 | const { file, previewUrl } = useBlobToFile({ dataUrl, filename }); 46 | 47 | return ( 48 |