├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── favicon-32.png ├── manifest.json └── icon.svg ├── src ├── vite-env.d.ts ├── index.tsx ├── setupTests.ts ├── reportWebVitals.ts ├── App.css ├── index.css ├── components │ ├── FileUpload.tsx │ ├── Statistics.tsx │ ├── ExportPanel.tsx │ ├── BatchProcessor.tsx │ └── KLVBuilder.tsx ├── logo.svg ├── tests │ ├── helpers │ │ └── testUtils.ts │ ├── components │ │ ├── FileUpload.test.tsx │ │ ├── Statistics.test.tsx │ │ ├── ExportPanel.test.tsx │ │ ├── KLVBuilder.test.tsx │ │ ├── BatchProcessor.test.tsx │ │ └── App.test.tsx │ └── utils │ │ └── KLVParser.test.ts ├── utils │ └── KLVParser.ts └── App.tsx ├── .claude └── settings.local.json ├── tsconfig.node.json ├── index.html ├── tsconfig.json ├── LICENSE ├── .github └── workflows │ ├── deploy.yml │ └── ci.yml ├── vite.config.ts ├── package.json ├── .gitignore ├── CLAUDE.md └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ohmrefresh/klv-extractor/main/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ohmrefresh/klv-extractor/main/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ohmrefresh/klv-extractor/main/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ohmrefresh/klv-extractor/main/public/favicon-32.png -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare const __BUILD_DATE__: string; 4 | declare const __APP_VERSION__: string; 5 | -------------------------------------------------------------------------------- /.claude/settings.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "permissions": { 3 | "allow": [ 4 | "Bash(npm test:*)", 5 | "Bash(npm run test:ci:*)" 6 | ], 7 | "deny": [], 8 | "ask": [] 9 | } 10 | } -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "bundler", 7 | "allowSyntheticDefaultImports": true, 8 | "strict": true 9 | }, 10 | "include": ["vite.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | const root = ReactDOM.createRoot( 7 | document.getElementById('root') as HTMLElement 8 | ); 9 | root.render( 10 | 11 | 12 | 13 | ); -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | 7 | // Ensure proper DOM setup for React Testing Library 8 | import { configure } from '@testing-library/react'; 9 | configure({ testIdAttribute: 'data-testid' }); -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import type { Metric } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: (metric: Metric) => void) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => { 6 | onCLS(onPerfEntry); 7 | onINP(onPerfEntry); 8 | onFCP(onPerfEntry); 9 | onLCP(onPerfEntry); 10 | onTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "KLV Extractor", 3 | "name": "KLV Data Extraction Suite", 4 | "description": "Complete toolkit for KLV data processing, parsing, and analysis", 5 | "icons": [ 6 | { 7 | "src": "favicon.ico", 8 | "sizes": "64x64 32x32 24x24 16x16", 9 | "type": "image/x-icon" 10 | }, 11 | { 12 | "src": "logo192.png", 13 | "type": "image/png", 14 | "sizes": "192x192" 15 | }, 16 | { 17 | "src": "logo512.png", 18 | "type": "image/png", 19 | "sizes": "512x512" 20 | } 21 | ], 22 | "start_url": ".", 23 | "display": "standalone", 24 | "theme_color": "#3B82F6", 25 | "background_color": "#F9FAFB" 26 | } 27 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | KLV Extractor - Data Extraction Suite 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body { 6 | margin: 0; 7 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 8 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 9 | sans-serif; 10 | -webkit-font-smoothing: antialiased; 11 | -moz-osx-font-smoothing: grayscale; 12 | } 13 | 14 | code { 15 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 16 | monospace; 17 | } 18 | 19 | /* Custom scrollbar */ 20 | ::-webkit-scrollbar { 21 | width: 8px; 22 | } 23 | 24 | ::-webkit-scrollbar-track { 25 | background: #f1f1f1; 26 | } 27 | 28 | ::-webkit-scrollbar-thumb { 29 | background: #c1c1c1; 30 | border-radius: 4px; 31 | } 32 | 33 | ::-webkit-scrollbar-thumb:hover { 34 | background: #a8a8a8; 35 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": true, 19 | "noUnusedLocals": false, 20 | "noUnusedParameters": false, 21 | "noFallthroughCasesInSwitch": true, 22 | "allowJs": true, 23 | "esModuleInterop": true, 24 | "allowSyntheticDefaultImports": true, 25 | "forceConsistentCasingInFileNames": true, 26 | 27 | /* Vitest */ 28 | "types": ["vitest/globals"] 29 | }, 30 | "include": ["src"], 31 | "references": [{ "path": "./tsconfig.node.json" }] 32 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Ohm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to GitHub Pages 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | permissions: 10 | contents: read 11 | pages: write 12 | id-token: write 13 | 14 | concurrency: 15 | group: "pages" 16 | cancel-in-progress: false 17 | 18 | jobs: 19 | build: 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@v4 25 | 26 | - name: Setup Node.js 27 | uses: actions/setup-node@v4 28 | with: 29 | node-version: '20' 30 | cache: 'npm' 31 | 32 | - name: Install dependencies 33 | run: npm ci 34 | 35 | - name: Run tests 36 | run: npm run test:ci 37 | 38 | - name: Build 39 | run: npm run build 40 | env: 41 | BASE: /klv-extractor/ 42 | 43 | - name: Setup Pages 44 | uses: actions/configure-pages@v4 45 | 46 | - name: Upload artifact 47 | uses: actions/upload-pages-artifact@v3 48 | with: 49 | path: ./build 50 | 51 | deploy: 52 | environment: 53 | name: github-pages 54 | url: ${{ steps.deployment.outputs.page_url }} 55 | runs-on: ubuntu-latest 56 | needs: build 57 | if: github.ref == 'refs/heads/main' 58 | steps: 59 | - name: Deploy to GitHub Pages 60 | id: deployment 61 | uses: actions/deploy-pages@v4 -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig(({ mode }) => ({ 6 | plugins: [react()], 7 | define: { 8 | 'process.env.NODE_ENV': JSON.stringify(mode === 'test' ? 'test' : mode), 9 | '__BUILD_DATE__': JSON.stringify(new Date().toISOString()), 10 | '__APP_VERSION__': JSON.stringify(process.env.npm_package_version || '0.2.0'), 11 | }, 12 | resolve: { 13 | conditions: mode === 'test' ? ['development'] : [], 14 | }, 15 | base: '/klv-extractor/', 16 | build: { 17 | outDir: 'build', 18 | }, 19 | server: { 20 | port: 3000, 21 | open: true, 22 | }, 23 | test: { 24 | globals: true, 25 | environment: 'jsdom', 26 | setupFiles: './src/setupTests.ts', 27 | testTimeout: 10000, 28 | environmentOptions: { 29 | jsdom: { 30 | resources: 'usable', 31 | }, 32 | }, 33 | coverage: { 34 | provider: 'v8', 35 | alias: { 36 | '@/': new URL('./src/', import.meta.url).pathname, 37 | }, 38 | reporter: ['text', 'text-summary', 'lcov', 'json-summary', 'html', 'cobertura'], 39 | thresholds: { 40 | branches: 60, 41 | functions: 60, 42 | lines: 60, 43 | statements: 60, 44 | }, 45 | exclude: [ 46 | 'node_modules/', 47 | 'src/setupTests.ts', 48 | 'src/reportWebVitals.ts', 49 | '**/*.test.{ts,tsx}', 50 | '**/*.config.{ts,js}', 51 | 'src/tests/**' 52 | ] 53 | } 54 | } 55 | })) 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "klv-extractor", 3 | "version": "0.2.0", 4 | "private": true, 5 | "homepage": "https://ohmrefresh.github.io/klv-extractor", 6 | "dependencies": { 7 | "lucide-react": "^0.561.0", 8 | "react": "^19.2.3", 9 | "react-dom": "^19.2.3", 10 | "web-vitals": "^5.1.0" 11 | }, 12 | "devDependencies": { 13 | "@testing-library/dom": "^10.4.1", 14 | "@testing-library/jest-dom": "^6.9.1", 15 | "@testing-library/react": "^16.3.0", 16 | "@testing-library/user-event": "^14.6.1", 17 | "@types/node": "^25.0.1", 18 | "@types/react": "^19.2.7", 19 | "@types/react-dom": "^19.2.3", 20 | "@vitejs/plugin-react": "^5.1.2", 21 | "@vitest/coverage-v8": "^4.0.15", 22 | "@vitest/ui": "^4.0.15", 23 | "gh-pages": "^6.3.0", 24 | "jsdom": "^27.3.0", 25 | "tailwindcss": "^4.1.18", 26 | "typescript": "^5.9.3", 27 | "vite": "^7.2.7", 28 | "vitest": "^4.0.15" 29 | }, 30 | "scripts": { 31 | "start": "vite", 32 | "dev": "vite", 33 | "build": "tsc && vite build", 34 | "preview": "vite preview", 35 | "test": "vitest", 36 | "test:coverage": "vitest run --coverage", 37 | "test:ci": "vitest run --coverage", 38 | "test:ui": "vitest --ui", 39 | "predeploy": "npm run build", 40 | "deploy": "gh-pages -d build" 41 | }, 42 | "browserslist": { 43 | "production": [ 44 | ">0.2%", 45 | "not dead", 46 | "not op_mini all" 47 | ], 48 | "development": [ 49 | "last 1 chrome version", 50 | "last 1 firefox version", 51 | "last 1 safari version" 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/components/FileUpload.tsx: -------------------------------------------------------------------------------- 1 | import React, { useRef } from 'react'; 2 | import { Upload } from 'lucide-react'; 3 | 4 | interface FileUploadProps { 5 | onFileLoad: (content: string, filename: string) => void; 6 | } 7 | 8 | const FileUpload: React.FC = ({ onFileLoad }) => { 9 | const fileRef = useRef(null); 10 | 11 | const handleFileChange = async (e: React.ChangeEvent) => { 12 | const file = e.target.files?.[0]; 13 | if (!file) return; 14 | 15 | try { 16 | const text = await file.text(); 17 | onFileLoad(text, file.name); 18 | } catch (error) { 19 | console.error('Error reading file:', error); 20 | alert('Error reading file. Please try again.'); 21 | } 22 | 23 | e.target.value = ''; 24 | }; 25 | 26 | return ( 27 |
28 | 36 | 37 |

38 | Upload KLV data file (.txt, .log, .csv) 39 |

40 | 46 |
47 | ); 48 | }; 49 | 50 | export default FileUpload; -------------------------------------------------------------------------------- /src/components/Statistics.tsx: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'react'; 2 | import { KLVEntry } from '../utils/KLVParser'; 3 | 4 | interface StatisticsProps { 5 | results: KLVEntry[]; 6 | } 7 | 8 | interface StatsData { 9 | total: number; 10 | totalValueLength: number; 11 | knownKeys: number; 12 | unknownKeys: number; 13 | keyTypes: Record; 14 | } 15 | 16 | const Statistics: React.FC = ({ results }) => { 17 | const stats: StatsData = useMemo(() => { 18 | const keyTypes: Record = {}; 19 | let totalValueLength = 0; 20 | let knownKeys = 0; 21 | 22 | results.forEach(item => { 23 | const category = item.name !== 'Unknown' ? 'Known' : 'Unknown'; 24 | keyTypes[category] = (keyTypes[category] || 0) + 1; 25 | totalValueLength += item.len; 26 | if (item.name !== 'Unknown') knownKeys++; 27 | }); 28 | 29 | return { 30 | total: results.length, 31 | totalValueLength, 32 | knownKeys, 33 | unknownKeys: results.length - knownKeys, 34 | keyTypes 35 | }; 36 | }, [results]); 37 | 38 | if (results.length === 0) { 39 | return null; 40 | } 41 | 42 | return ( 43 |
44 |
45 |
{stats.total}
46 |
Total Entries
47 |
48 |
49 |
{stats.knownKeys}
50 |
Known Keys
51 |
52 |
53 |
{stats.unknownKeys}
54 |
Unknown Keys
55 |
56 |
57 |
{stats.totalValueLength}
58 |
Total Length
59 |
60 |
61 | ); 62 | }; 63 | 64 | export default Statistics; -------------------------------------------------------------------------------- /src/components/ExportPanel.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import KLVParser, { KLVEntry } from '../utils/KLVParser'; 3 | 4 | interface ExportPanelProps { 5 | results: KLVEntry[]; 6 | } 7 | 8 | type ExportFormat = 'json' | 'csv' | 'table'; 9 | 10 | const ExportPanel: React.FC = ({ results }) => { 11 | const downloadFile = (content: string, filename: string, type: string) => { 12 | const blob = new Blob([content], { type }); 13 | const url = URL.createObjectURL(blob); 14 | const a = document.createElement('a'); 15 | a.href = url; 16 | a.download = filename; 17 | document.body.appendChild(a); 18 | a.click(); 19 | document.body.removeChild(a); 20 | URL.revokeObjectURL(url); 21 | }; 22 | 23 | const exportData = (format: ExportFormat) => { 24 | const content = KLVParser.export(results, format); 25 | const timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-'); 26 | const extensions: Record = { json: 'json', csv: 'csv', table: 'txt' }; 27 | const mimeTypes: Record = { 28 | json: 'application/json', 29 | csv: 'text/csv', 30 | table: 'text/plain' 31 | }; 32 | 33 | downloadFile( 34 | content, 35 | `klv-data-${timestamp}.${extensions[format]}`, 36 | mimeTypes[format] 37 | ); 38 | }; 39 | 40 | if (results.length === 0) { 41 | return null; 42 | } 43 | 44 | return ( 45 |
46 | 53 | 60 | 67 |
68 | ); 69 | }; 70 | 71 | export default ExportPanel; -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # Snowpack dependency directory (https://snowpack.dev/) 45 | web_modules/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Optional stylelint cache 57 | .stylelintcache 58 | 59 | # Optional REPL history 60 | .node_repl_history 61 | 62 | # Output of 'npm pack' 63 | *.tgz 64 | 65 | # Yarn Integrity file 66 | .yarn-integrity 67 | 68 | # dotenv environment variable files 69 | .env 70 | .env.* 71 | !.env.example 72 | 73 | # parcel-bundler cache (https://parceljs.org/) 74 | .cache 75 | .parcel-cache 76 | 77 | # Next.js build output 78 | .next 79 | out 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and not Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # vuepress v2.x temp and cache directory 95 | .temp 96 | .cache 97 | 98 | # Sveltekit cache directory 99 | .svelte-kit/ 100 | 101 | # vitepress build output 102 | **/.vitepress/dist 103 | 104 | # vitepress cache directory 105 | **/.vitepress/cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # Firebase cache directory 120 | .firebase/ 121 | 122 | # TernJS port file 123 | .tern-port 124 | 125 | # Stores VSCode versions used for testing VSCode extensions 126 | .vscode-test 127 | 128 | # yarn v3 129 | .pnp.* 130 | .yarn/* 131 | !.yarn/patches 132 | !.yarn/plugins 133 | !.yarn/releases 134 | !.yarn/sdks 135 | !.yarn/versions 136 | 137 | # Vite logs files 138 | vite.config.js.timestamp-* 139 | vite.config.ts.timestamp-* 140 | 141 | build/* -------------------------------------------------------------------------------- /public/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | KLV 56 | 57 | -------------------------------------------------------------------------------- /src/tests/helpers/testUtils.ts: -------------------------------------------------------------------------------- 1 | import { vi } from 'vitest'; 2 | import { KLVEntry } from '../../utils/KLVParser'; 3 | 4 | // Mock KLV data for testing 5 | export const mockKLVEntries: KLVEntry[] = [ 6 | { 7 | key: '002', 8 | len: 6, 9 | value: 'AB48DE', 10 | pos: 0, 11 | name: 'Tracking Number' 12 | }, 13 | { 14 | key: '026', 15 | len: 4, 16 | value: '4577', 17 | pos: 11, 18 | name: 'Merchant Category Code' 19 | }, 20 | { 21 | key: '042', 22 | len: 15, 23 | value: 'MERCHANT_ID_123', 24 | pos: 20, 25 | name: 'Merchant Identifier' 26 | }, 27 | { 28 | key: '999', 29 | len: 4, 30 | value: 'TEST', 31 | pos: 40, 32 | name: 'Generic Key' 33 | } 34 | ]; 35 | 36 | export const mockValidKLVString = '00206AB48DE026044577042015MERCHANT_ID_12399904TEST'; 37 | export const mockInvalidKLVString = 'INVALID_KLV_DATA'; 38 | export const mockEmptyKLVString = ''; 39 | 40 | // Mock file content for testing file uploads 41 | export const mockFileContent = { 42 | validKLV: '00206AB48DE026044577\n042015MERCHANT_ID_123', 43 | invalidKLV: 'INVALID_DATA\nMORE_INVALID', 44 | empty: '' 45 | }; 46 | 47 | // Mock batch processing data 48 | export const mockBatchData = [ 49 | '00206AB48DE026044577', 50 | '042015MERCHANT_ID_123', 51 | 'INVALID_ENTRY', 52 | '99904TEST' 53 | ]; 54 | 55 | // Test utilities for component testing 56 | export const createMockFile = (content: string, name: string, type: string = 'text/plain'): File => { 57 | const file = new File([content], name, { type }); 58 | 59 | // Mock the text() method for testing 60 | (file as any).text = vi.fn().mockResolvedValue(content); 61 | 62 | return file; 63 | }; 64 | 65 | // Mock clipboard API 66 | export const mockClipboardAPI = () => { 67 | const mockWriteText = vi.fn().mockResolvedValue(undefined); 68 | 69 | Object.defineProperty(navigator, 'clipboard', { 70 | value: { 71 | writeText: mockWriteText 72 | }, 73 | configurable: true 74 | }); 75 | 76 | return mockWriteText; 77 | }; 78 | 79 | // Mock URL APIs for file downloads 80 | export const mockURLAPIs = () => { 81 | const mockCreateObjectURL = vi.fn().mockReturnValue('mock-blob-url'); 82 | const mockRevokeObjectURL = vi.fn(); 83 | 84 | Object.defineProperty(URL, 'createObjectURL', { 85 | value: mockCreateObjectURL, 86 | configurable: true 87 | }); 88 | 89 | Object.defineProperty(URL, 'revokeObjectURL', { 90 | value: mockRevokeObjectURL, 91 | configurable: true 92 | }); 93 | 94 | return { mockCreateObjectURL, mockRevokeObjectURL }; 95 | }; 96 | 97 | // Mock DOM methods for file downloads 98 | export const mockDOMFileDownload = () => { 99 | const mockClick = vi.fn(); 100 | const mockAppendChild = vi.fn(); 101 | const mockRemoveChild = vi.fn(); 102 | 103 | const mockElement = { 104 | click: mockClick, 105 | href: '', 106 | download: '', 107 | style: {} 108 | }; 109 | 110 | const originalCreateElement = document.createElement; 111 | document.createElement = vi.fn().mockReturnValue(mockElement); 112 | 113 | const originalAppendChild = document.body.appendChild; 114 | document.body.appendChild = mockAppendChild; 115 | 116 | const originalRemoveChild = document.body.removeChild; 117 | document.body.removeChild = mockRemoveChild; 118 | 119 | // Return cleanup function 120 | return { 121 | cleanup: () => { 122 | document.createElement = originalCreateElement; 123 | document.body.appendChild = originalAppendChild; 124 | document.body.removeChild = originalRemoveChild; 125 | }, 126 | mocks: { 127 | mockClick, 128 | mockAppendChild, 129 | mockRemoveChild, 130 | mockElement 131 | } 132 | }; 133 | }; 134 | 135 | // Helper to wait for promises to resolve 136 | export const waitForPromises = () => new Promise(resolve => setTimeout(resolve, 0)); 137 | 138 | // Mock console methods 139 | export const mockConsole = () => { 140 | const originalError = console.error; 141 | const originalLog = console.log; 142 | const originalWarn = console.warn; 143 | 144 | console.error = vi.fn(); 145 | console.log = vi.fn(); 146 | console.warn = vi.fn(); 147 | 148 | return { 149 | cleanup: () => { 150 | console.error = originalError; 151 | console.log = originalLog; 152 | console.warn = originalWarn; 153 | }, 154 | mocks: { 155 | error: console.error, 156 | log: console.log, 157 | warn: console.warn 158 | } 159 | }; 160 | }; 161 | 162 | // Assertion helpers 163 | export const expectValidKLVEntry = (entry: KLVEntry, expectedKey: string, expectedValue: string) => { 164 | expect(entry.key).toBe(expectedKey); 165 | expect(entry.value).toBe(expectedValue); 166 | expect(entry.len).toBe(expectedValue.length); 167 | expect(typeof entry.pos).toBe('number'); 168 | expect(typeof entry.name).toBe('string'); 169 | }; 170 | 171 | export const expectValidParseResult = (result: { results: KLVEntry[], errors: string[] }, expectedCount: number) => { 172 | expect(result.errors).toHaveLength(0); 173 | expect(result.results).toHaveLength(expectedCount); 174 | result.results.forEach(entry => { 175 | expect(entry).toHaveProperty('key'); 176 | expect(entry).toHaveProperty('len'); 177 | expect(entry).toHaveProperty('value'); 178 | expect(entry).toHaveProperty('pos'); 179 | expect(entry).toHaveProperty('name'); 180 | }); 181 | }; -------------------------------------------------------------------------------- /src/tests/components/FileUpload.test.tsx: -------------------------------------------------------------------------------- 1 | import { render, screen, fireEvent, waitFor } from '@testing-library/react'; 2 | import userEvent from '@testing-library/user-event'; 3 | import { vi } from 'vitest'; 4 | import FileUpload from '../../components/FileUpload'; 5 | 6 | // Mock file reading 7 | const mockFileContent = '00206AB48DE026044577'; 8 | const mockFileName = 'test-klv-data.txt'; 9 | 10 | describe('FileUpload', () => { 11 | const mockOnFileLoad = vi.fn(); 12 | 13 | beforeEach(() => { 14 | mockOnFileLoad.mockClear(); 15 | }); 16 | 17 | it('should render file upload component', () => { 18 | render(); 19 | 20 | expect(screen.getByText('Upload KLV data file (.txt, .log, .csv)')).toBeInTheDocument(); 21 | expect(screen.getByText('Choose File')).toBeInTheDocument(); 22 | expect(screen.getByLabelText('Upload KLV data file')).toBeInTheDocument(); 23 | }); 24 | 25 | it('should have correct file input attributes', () => { 26 | render(); 27 | 28 | const fileInput = screen.getByLabelText('Upload KLV data file'); 29 | expect(fileInput).toHaveAttribute('type', 'file'); 30 | expect(fileInput).toHaveAttribute('accept', '.txt,.log,.csv,.json'); 31 | expect(fileInput).toHaveClass('hidden'); 32 | }); 33 | 34 | it('should trigger file input when choose file button is clicked', async () => { 35 | const user = userEvent.setup(); 36 | render(); 37 | 38 | const chooseFileButton = screen.getByText('Choose File'); 39 | const fileInput = screen.getByLabelText('Upload KLV data file'); 40 | 41 | const clickSpy = vi.spyOn(fileInput, 'click'); 42 | 43 | await user.click(chooseFileButton); 44 | 45 | expect(clickSpy).toHaveBeenCalled(); 46 | 47 | clickSpy.mockRestore(); 48 | }); 49 | 50 | it('should handle file selection and call onFileLoad', async () => { 51 | render(); 52 | 53 | const fileInput = screen.getByLabelText('Upload KLV data file'); 54 | 55 | // Create a mock file with text() method 56 | const mockFile = new File([mockFileContent], mockFileName, { type: 'text/plain' }); 57 | 58 | // Mock the text() method on the File prototype 59 | const originalText = File.prototype.text; 60 | File.prototype.text = vi.fn().mockResolvedValue(mockFileContent); 61 | 62 | fireEvent.change(fileInput, { target: { files: [mockFile] } }); 63 | 64 | await waitFor(() => { 65 | expect(mockOnFileLoad).toHaveBeenCalledWith(mockFileContent, mockFileName); 66 | }); 67 | 68 | // Restore original method 69 | File.prototype.text = originalText; 70 | }); 71 | 72 | it('should clear input value after file processing', async () => { 73 | render(); 74 | 75 | const fileInput = screen.getByLabelText('Upload KLV data file') as HTMLInputElement; 76 | const mockFile = new File([mockFileContent], mockFileName, { type: 'text/plain' }); 77 | 78 | // Mock the text() method 79 | File.prototype.text = vi.fn().mockResolvedValue(mockFileContent); 80 | 81 | fireEvent.change(fileInput, { target: { files: [mockFile] } }); 82 | 83 | await waitFor(() => { 84 | expect(mockOnFileLoad).toHaveBeenCalled(); 85 | }); 86 | 87 | expect(fileInput.value).toBe(''); 88 | }); 89 | 90 | it('should handle file reading errors gracefully', async () => { 91 | const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); 92 | const alertSpy = vi.spyOn(window, 'alert').mockImplementation(() => {}); 93 | 94 | render(); 95 | 96 | const fileInput = screen.getByLabelText('Upload KLV data file'); 97 | const mockFile = new File([mockFileContent], mockFileName, { type: 'text/plain' }); 98 | 99 | // Mock text() to throw an error 100 | File.prototype.text = vi.fn().mockRejectedValue(new Error('File read error')); 101 | 102 | fireEvent.change(fileInput, { target: { files: [mockFile] } }); 103 | 104 | await waitFor(() => { 105 | expect(consoleSpy).toHaveBeenCalledWith('Error reading file:', expect.any(Error)); 106 | expect(alertSpy).toHaveBeenCalledWith('Error reading file. Please try again.'); 107 | }); 108 | 109 | expect(mockOnFileLoad).not.toHaveBeenCalled(); 110 | 111 | consoleSpy.mockRestore(); 112 | alertSpy.mockRestore(); 113 | }); 114 | 115 | it('should not process when no file is selected', async () => { 116 | render(); 117 | 118 | const fileInput = screen.getByLabelText('Upload KLV data file'); 119 | 120 | fireEvent.change(fileInput, { target: { files: [] } }); 121 | 122 | expect(mockOnFileLoad).not.toHaveBeenCalled(); 123 | }); 124 | 125 | it('should have proper styling classes', () => { 126 | render(); 127 | 128 | const uploadArea = screen.getByText('Upload KLV data file (.txt, .log, .csv)').closest('div'); 129 | expect(uploadArea).toHaveClass('border-2', 'border-dashed', 'border-gray-300', 'rounded', 'p-4'); 130 | 131 | const button = screen.getByText('Choose File'); 132 | expect(button).toHaveClass('px-4', 'py-2', 'bg-blue-500', 'text-white', 'rounded'); 133 | }); 134 | }); -------------------------------------------------------------------------------- /CLAUDE.md: -------------------------------------------------------------------------------- 1 | # CLAUDE.md 2 | 3 | This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. 4 | 5 | ## Project Overview 6 | 7 | This is a React-based KLV (Key-Length-Value) data extraction and processing suite for Paymentology transaction data. The application provides a complete toolkit for parsing, building, and batch processing KLV formatted data. 8 | 9 | ## Development Commands 10 | 11 | - `npm start` - Runs the app in development mode with Vite (http://localhost:3000 or next available port) 12 | - `npm run dev` - Alternative command to start development server 13 | - `npm run build` - Builds the app for production to the `build` folder using TypeScript and Vite 14 | - `npm run preview` - Preview the production build locally 15 | - `npm test` - Launches Vitest test runner in interactive watch mode 16 | - `npm run test:coverage` - Runs all tests with coverage report 17 | - `npm run test:ci` - Runs tests in CI mode with coverage (no watch) 18 | - `npm run test:ui` - Opens Vitest UI for interactive test running 19 | 20 | ## Core Architecture 21 | 22 | ### KLV Parser Engine (`src/utils/KLVParser.ts`) 23 | The heart of the application is the KLVParser utility which: 24 | - Contains complete KLV definitions for 100+ Paymentology fields (keys 002-999) 25 | - Parses KLV strings with format validation and error handling 26 | - Exports data to JSON, CSV, and table formats 27 | - Builds KLV strings from component entries 28 | - Validates KLV data structure and integrity 29 | 30 | ### Component Architecture 31 | The application uses a tab-based interface with four main sections: 32 | 33 | **Main App (`src/App.jsx`)** 34 | - Manages application state (activeTab, klvInput, searchTerm, history) 35 | - Handles file uploads and history management 36 | - Coordinates between different processing modes 37 | 38 | **Core Components:** 39 | - `FileUpload` - Handles file input for KLV data 40 | - `ExportPanel` - Provides export functionality to various formats 41 | - `Statistics` - Shows parsing statistics and data insights 42 | - `KLVBuilder` - Interactive form for constructing KLV strings 43 | - `BatchProcessor` - Processes multiple KLV entries simultaneously 44 | 45 | ### Data Flow 46 | 1. Input: KLV strings via manual input, file upload, or builder 47 | 2. Processing: KLVParser validates and parses data into structured format 48 | 3. Display: Results shown with search/filter capabilities 49 | 4. Export: Data can be exported to multiple formats 50 | 5. History: Successful parses saved to processing history 51 | 52 | ### Key Features 53 | - **Real-time parsing** with immediate error feedback 54 | - **Search and filter** across parsed results 55 | - **Batch processing** for multiple KLV entries 56 | - **Interactive builder** for creating KLV strings 57 | - **Export capabilities** (JSON, CSV, table format) 58 | - **Processing history** with load/copy functionality 59 | - **Sample data** for testing and demonstration 60 | 61 | ## Technology Stack 62 | 63 | - **React 18** with functional components and hooks 64 | - **TypeScript** for type safety and better development experience 65 | - **Vite** - Modern build tool and development server 66 | - **Vitest** - Fast unit test framework with Jest-compatible API 67 | - **Tailwind CSS** for styling (included as dev dependency) 68 | - **Lucide React** for icons 69 | 70 | ## KLV Data Format 71 | 72 | The application processes Key-Length-Value data with the structure: 73 | - 3-digit key (002-999) 74 | - 2-digit length field (hexadecimal) 75 | - Variable-length value field 76 | - Example: `00206AB48DE` = Key=002, Length=06, Value=AB48DE 77 | 78 | ## Development Notes 79 | 80 | - Components follow React functional patterns with hooks and TypeScript interfaces 81 | - State management is handled at the App level and passed down via typed props 82 | - Error handling is built into the parsing engine with proper type safety 83 | - The application uses TypeScript for compile-time type checking and better IDE support 84 | - All interfaces and types are properly defined for KLV data structures 85 | - The application is designed for defensive security (data parsing and analysis only) 86 | - No server-side dependencies - pure client-side processing 87 | 88 | ## TypeScript Interfaces 89 | 90 | Key interfaces defined in the codebase: 91 | - `KLVEntry` - Represents a parsed KLV entry with key, length, value, position, and name 92 | - `KLVParseResult` - Contains parsing results and any errors 93 | - `KLVValidationResult` - Validation results for KLV data 94 | - `KLVBuildEntry` - Entry format for building KLV strings 95 | 96 | ## Testing 97 | 98 | The application includes comprehensive unit and integration tests: 99 | 100 | ### Test Structure 101 | - **Unit tests** for KLV Parser utility (`src/tests/utils/KLVParser.test.ts`) 102 | - **Component tests** for React components (`src/tests/components/*.test.tsx`) 103 | - **Integration tests** for full application workflows (`src/tests/integration/*.test.tsx`) 104 | - **Test utilities** for mocking and shared test helpers (`src/tests/helpers/testUtils.ts`) 105 | 106 | ### Test Coverage 107 | Tests cover: 108 | - KLV parsing with valid and invalid data 109 | - Error handling and edge cases 110 | - Component rendering and user interactions 111 | - File upload functionality 112 | - Export operations 113 | - Search and filtering 114 | - Tab navigation and state management 115 | - Clipboard operations 116 | - History management 117 | 118 | ### Running Tests 119 | ```bash 120 | npm test # Interactive test runner 121 | npm run test:coverage # Tests with coverage report 122 | npm run test:ci # CI-friendly test run 123 | ``` 124 | 125 | ### Test Dependencies 126 | - Vitest (test framework with Jest-compatible API) 127 | - React Testing Library (component testing) 128 | - @testing-library/jest-dom (DOM assertions) 129 | - @testing-library/user-event (user interaction simulation) 130 | - @vitest/coverage-v8 (code coverage) -------------------------------------------------------------------------------- /src/components/BatchProcessor.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { CheckCircle, AlertCircle, FileText } from 'lucide-react'; 3 | import KLVParser, { KLVParseResult } from '../utils/KLVParser'; 4 | 5 | interface BatchResult extends KLVParseResult { 6 | line: number; 7 | input: string; 8 | } 9 | 10 | interface BatchProcessorProps { 11 | onProcess: (results: BatchResult[]) => void; 12 | } 13 | 14 | const BatchProcessor: React.FC = ({ onProcess }) => { 15 | const [batchInput, setBatchInput] = useState(''); 16 | const [processing, setProcessing] = useState(false); 17 | const [results, setResults] = useState([]); 18 | 19 | const processBatch = async () => { 20 | setProcessing(true); 21 | const lines = batchInput.split('\n').filter(line => line.trim()); 22 | 23 | const batchResults: BatchResult[] = lines.map((line, index) => ({ 24 | line: index + 1, 25 | input: line.trim(), 26 | ...KLVParser.parse(line.trim()) 27 | })); 28 | 29 | // Simulate processing delay for better UX 30 | await new Promise(resolve => setTimeout(resolve, 500)); 31 | 32 | setResults(batchResults); 33 | setProcessing(false); 34 | onProcess(batchResults); 35 | }; 36 | 37 | const loadSampleBatch = () => { 38 | const sampleData = [ 39 | '00206AB48DE026044577', 40 | '04210000050010008USD04305Test Merchant', 41 | '25103EMV25107Visa26105542200015INVALID_ENTRY', 42 | '04210050026055422600512345678042036MERCHANT_ID_12343015Test Transaction' 43 | ].join('\n'); 44 | setBatchInput(sampleData); 45 | }; 46 | 47 | const clearBatch = () => { 48 | setBatchInput(''); 49 | setResults([]); 50 | }; 51 | 52 | return ( 53 |
54 |
55 |

56 | 57 | Batch Processor 58 |

59 |
60 | 66 | 72 |
73 |
74 | 75 |
76 | 79 |