cd

chdir in chainer fashion + read file

Usage no npm install needed!

<script type="module">
  import cd from 'https://cdn.skypack.dev/cd';
</script>

README

cd

Change directory in chaining fashion.

Rules:

1. Reading .json file will strip comments and converte into JSON object.
2. Reading .js file is equivalent of require('dir/to/file')
3. Other files are just read.
4. Supply file as argument on last call. No chaning afterwards.
5. Module is syncro, but if you have good idea how to make it async please let me know.

Usage:

var Cd = require('cd');
var cd = new Cd('.');

// Read lol.json from current directory
var lol = cd('lol.json');

// Read wtf.js from test directory.
var wtf = cd().test('wtf.js');
console.log('wtf:'+JSON.stringify(wtf));

// Chain as you like
var file = cd().dir1().dir2(file_in_dir2);