Extract DAG.js

Extracts DAG.js into a standalone lib.
There's a PR coming with that too. I can split it out if you think it's worth spending the time and running tests over