|
| 1 | +# Slicer Meta Parser |
| 2 | + |
| 3 | +A TypeScript library for parsing metadata from 3D printing slicer files. This library extracts key information from G-Code, GX, and 3MF files, such as slicer information, print settings, and filament usage. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Parses metadata from various slicer file formats. |
| 8 | +- Supports G-Code, GX, and 3MF files. |
| 9 | +- Automatically detects the file type based on the extension. |
| 10 | +- Provides a simple, unified interface for different file types. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +To install this package, you need to configure npm to use the GitHub Packages registry. |
| 15 | + |
| 16 | +Add the following to a `.npmrc` file in your project's root directory: |
| 17 | + |
| 18 | +``` |
| 19 | +@parallel-7:registry=https://npm.pkg.github.com/ |
| 20 | +``` |
| 21 | + |
| 22 | +Then, install the package as usual: |
| 23 | + |
| 24 | +```bash |
| 25 | +npm install @parallel-7/slicer-meta |
| 26 | +``` |
| 27 | + |
| 28 | +You will need to authenticate with GitHub Packages to download private packages. |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +The primary way to use the library is with the `parseSlicerFile` function, which automatically handles different file formats. |
| 33 | + |
| 34 | +```typescript |
| 35 | +import { parseSlicerFile } from '@parallel-7/slicer-meta'; |
| 36 | + |
| 37 | +async function main() { |
| 38 | + try { |
| 39 | + const filePath = 'path/to/your/file.gcode'; |
| 40 | + const metadata = await parseSlicerFile(filePath); |
| 41 | + |
| 42 | + console.log('Slicer Info:', metadata.slicer); |
| 43 | + console.log('File Info:', metadata.file); |
| 44 | + |
| 45 | + if (metadata.threeMf) { |
| 46 | + console.log('3MF Specific Info:', metadata.threeMf); |
| 47 | + } |
| 48 | + } catch (error) { |
| 49 | + console.error('Failed to parse file:', error); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +main(); |
| 54 | +``` |
| 55 | + |
| 56 | +## Advanced Usage |
| 57 | + |
| 58 | +For more specific use cases, you can use the individual parsers directly. This can be useful if you know the file type in advance or need more control over the parsing process. |
| 59 | + |
| 60 | +The following parsers are available: |
| 61 | + |
| 62 | +- `GCodeParser` |
| 63 | +- `FlashPrintParser` |
| 64 | +- `OrcaFlashForgeParser` |
| 65 | +- `GXParser` |
| 66 | +- `ThreeMfParser` |
| 67 | + |
| 68 | +### Example |
| 69 | + |
| 70 | +```typescript |
| 71 | +import { GCodeParser } from '@parallel-7/slicer-meta'; |
| 72 | + |
| 73 | +async function parseGCode() { |
| 74 | + const parser = new GCodeParser(); |
| 75 | + await parser.parse('path/to/your/file.gcode'); |
| 76 | + |
| 77 | + console.log('Slicer Info:', parser.slicerInfo); |
| 78 | + console.log('File Info:', parser.fileInfo); |
| 79 | +} |
| 80 | + |
| 81 | +parseGCode(); |
| 82 | +``` |
0 commit comments