Get the overlapping part of two file paths
npm install --save file-overlap
file-overlap
provides utitlies for getting the overlap and difference of two paths.
.overlap
returns the path that two paths have in common.
.difference
returns the path that the first argument has that the second doesn't.
.differenceRight
returns the path that the second argument has the the first doesn't.
.tail
returns the difference at the end of the first argument when compared to b.
var overlap = require('file-overlap');
console.log( overlap.overlap('/foo/bar/baz', 'bar/baz/banana.js') ); // 'bar/baz'
console.log( overlap.difference('/foo/bar/baz', 'bar/baz/banana.js') ); // '/foo'
console.log( overlap.differenceRight('/foo/bar/baz', 'bar/baz/banana.js') ); // 'banana.js'
console.log( overlap.tail('/foo/bar/baz/banana.js', '/foo/bar/baz') ); // 'banana.js'
// N.B. Tail does not work in reverse (right now).
console.log( overlap.tail('/foo/bar/baz', '/foo/bar/baz/banana.js') ); // '/foo/bar/baz' <- obviously not correct
Serve dist/file-overlap.js
or dist/file-overlap.min.js
however you serve javascript, then access window.fileOverlap
.
Please see the contribution guidelines.