Description
We have Path.format
/ Path.parse
functions.
They can be chained which is very convenient.
import Path from "path";
let path = "/foo/bar/bazz.js";
let pathP = Path.format(Path.parse(path));
Currently parse
converts string to an object with such structure
{ root: '/',
dir: '/Users/ivankleshnin/Projects/demo',
base: 'config.yml',
ext: '.yml',
name: 'config' }
This object contains denormalized data between base
, name
and ext
key values.
Now let's try to replace file extension.
import Path from "path";
import {assoc} from "ramda"
let path = "/Users/ivankleshnin/Projects/demo/config.js";
let pathP = assoc("ext", ".json", Path.parse(path));
/* {...
base: 'config.js', -- these two are
ext: '.json', -- unsynced!
...} */
console.log(Path.format(pathP)); // extension weren't changed :(
The simplest task is going to be not so simple?!
Now if format
took into consideration ext
and name
rather than base
this could lead to an equal problem with changes to base
key being ignored.
Can we get rid of this base
key? It's always parsed.name + parsed.ext
formula, not a big deal to make it manually. Example of hidden file parse: { base: '.gitignore', ext: '', name: '.gitignore' }
- same rule apply.
We can probably also implement it in a backward-compatibile way,
keeping base
but using JS getter / setter for it's evaluation.