|
| 1 | +# Vertopal-JS |
| 2 | + |
| 3 | +Vertopal-JS is a JavaScript library for easy access to the |
| 4 | +[Vertopal file conversion API](https://www.vertopal.com/en/developer/api). |
| 5 | + |
| 6 | +Using Vertopal-JS, you can quickly integrate support for |
| 7 | +converting **350+ file formats** directly into your Node.js or |
| 8 | +browser-based projects. |
| 9 | + |
| 10 | +## Installing Vertopal-JS |
| 11 | + |
| 12 | +Vertopal-JS is available on |
| 13 | +[npm](https://www.npmjs.com/package/vertopal-js) and can be installed using |
| 14 | +[npm](https://www.npmjs.com/): |
| 15 | + |
| 16 | +```bash |
| 17 | +npm install vertopal-js |
| 18 | +``` |
| 19 | + |
| 20 | +If you're not using npm, you can also download the most recent version of |
| 21 | +Vertopal-JS source code as a ZIP file from the |
| 22 | +[release page](https://github.com/vertopal/vertopal-js/releases/latest) and |
| 23 | +import it manually into your project. |
| 24 | + |
| 25 | +## Using Vertopal-JS |
| 26 | + |
| 27 | +## JavaScript Usage |
| 28 | + |
| 29 | +This package includes a public default credential (app: `free`, token: |
| 30 | +`FREE-TOKEN`) that lets you quickly experiment without creating an account. |
| 31 | +This credential is intended for personal testing and evaluation and comes |
| 32 | +with daily rate limits. For production workloads, or if you expect to exceed |
| 33 | +the free limits, you should |
| 34 | +[obtain a private Application ID and Security Token](https://www.vertopal.com/en/account/api/app/new) |
| 35 | +from your Vertopal account and configure them for full access. |
| 36 | + |
| 37 | +The following code illustrates |
| 38 | +[GIF to APNG](https://www.vertopal.com/en/convert/gif-to-apng) conversion using |
| 39 | +the Vertopal JavaScript library. |
| 40 | + |
| 41 | +```javascript |
| 42 | +// Import Vertopal classes |
| 43 | +import { Credential, Converter } from 'vertopal'; |
| 44 | +import { FileInput, FileOutput } from 'vertopal/io'; |
| 45 | + |
| 46 | +// Create a client credential instance using your app ID and security token |
| 47 | +const app = "free"; |
| 48 | +const token = "FREE-TOKEN"; |
| 49 | +const credential = new Credential(app, token); |
| 50 | + |
| 51 | +/** |
| 52 | + * Initialize input and output file streams |
| 53 | + * |
| 54 | + * Node.js-compatible file I/O: |
| 55 | + * - `FileInput` reads from a local file path (e.g., "./MickeyMouse.gif") |
| 56 | + * - `FileOutput` writes to a local file path (e.g., "./MickeyMouse.apng") |
| 57 | + * |
| 58 | + * Browser-compatible file I/O: |
| 59 | + * - `BrowserFileInput` reads from browser sources (e.g., <input type="file"> or drag-and-drop) |
| 60 | + * - `BrowserFileOutput` writes to browser sinks (e.g., triggering a download or streaming to canvas) |
| 61 | + */ |
| 62 | +const source = new FileInput("./MickeyMouse.gif"); |
| 63 | +const sink = new FileOutput("./MickeyMouse.apng"); |
| 64 | + |
| 65 | +// Convert and download your file using the Converter class |
| 66 | +(async () => { |
| 67 | + const converter = new Converter(credential); |
| 68 | + const conversion = await converter.convert(source, sink, "apng"); |
| 69 | + await conversion.wait(); |
| 70 | + if (conversion.successful()) { |
| 71 | + await conversion.download(); |
| 72 | + } |
| 73 | +})(); |
| 74 | +``` |
0 commit comments