This package solves the issue of file read/writes being confusing with vague syntax. Using the idea of URLs for local paths.
npm install cute-fs
await url('').soft.write(''); // write never overwrites
await url('').hard.write(''); // hard creates directories along the way
await url('').soft.overwrite(''); // overwrite will overwrite
await url('').hard.overwrite(''); // hard will create the dirs along the way
await url('').soft.read(''); // it also works with web urls
await url('').hard.read(''); // hard will create an empty file + dirs if the file is not there
import url from 'cute-fs';
await url('C:\\WindowsLikePathOr\\LinuxLike\\Path.txt').soft.write('any text');
await url('path/to/file.txt').hard.overwrite(`any text`);
await url('https://raw.githubusercontent.com/planetrenox/cute-npm-init/main/index.js').soft.read();
- soft will not create dirs along the way and will error.
- hard will create dirs along the way if they dont exist.
- write does not overwrite.
- overwrite overwrites.
- hard.read will create the dirs and an empty file if its not there.
The writing functionality for web URLs is not documented because it is still in testing. Feel free to look at the repo.