Skip to content

Instantly share code, notes, and snippets.

View aralroca's full-sized avatar
💫
Implementing tiny, easy and powerful things

Aral Roca Gomez aralroca

💫
Implementing tiny, easy and powerful things
View GitHub Profile
@aralroca
aralroca / convertSvgToFormat.ts
Last active November 9, 2022 08:41
Convert SVG to another format in Node.js (Requires inkscape installed)
import fs from 'fs';
import { spawn } from 'child_process';
type Format =
| 'dxf'
| 'emf'
| 'eps'
| 'fxg'
| 'gpl'
| 'hpgl'
const isNode = typeof window === 'undefined'
// Regex from: https://stackoverflow.com/a/475217/4467741
const encodedRegex = new RegExp('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')
export function decode(text: string) {
return isNode ? Buffer.from(text, 'base64').toString() : atob(text)
}
export function encode(text: string) {