Skip to content

Instantly share code, notes, and snippets.

View benoitv-code's full-sized avatar

Benoit V. benoitv-code

View GitHub Profile
@benoitv-code
benoitv-code / require-to-import.js
Last active September 27, 2022 07:32
Automatically converts `require` to `import` syntax (Node.js ES5 to TypeScript / ES6)
#!/usr/bin/env node
// from https://github.com/jameswomack/replace-require-with-import/blob/master/index.js
// changes: support importing files with a `@` in their names, support require with multiple keys `{ funcA, funcB }`
// usage: `node ./require-to-import.js ./src/**/*.ts`
const FS = require('fs')
const globby = require('globby')
const r1 = /^(let|var|const) +([a-zA-Z_$][a-zA-Z0-9_$]*) +\= +(require)\((('|")[@a-zA-Z0-9-_.\/]+('|"))\)/gm // const createStore = require('redux')
@benoitv-code
benoitv-code / index.js
Last active November 13, 2022 18:21
d3, jsdom, node.js: server-side rendering
// Instructions:
// npm install --save d3 jsdom
const fs = require('fs');
const d3 = require('d3');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const fakeDom = new JSDOM('<!DOCTYPE html><html><body></body></html>');