source: trip-planner-front/node_modules/commondir/index.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 802 bytes
Line 
1var path = require('path');
2
3module.exports = function (basedir, relfiles) {
4 if (relfiles) {
5 var files = relfiles.map(function (r) {
6 return path.resolve(basedir, r);
7 });
8 }
9 else {
10 var files = basedir;
11 }
12
13 var res = files.slice(1).reduce(function (ps, file) {
14 if (!file.match(/^([A-Za-z]:)?\/|\\/)) {
15 throw new Error('relative path without a basedir');
16 }
17
18 var xs = file.split(/\/+|\\+/);
19 for (
20 var i = 0;
21 ps[i] === xs[i] && i < Math.min(ps.length, xs.length);
22 i++
23 );
24 return ps.slice(0, i);
25 }, files[0].split(/\/+|\\+/));
26
27 // Windows correctly handles paths with forward-slashes
28 return res.length > 1 ? res.join('/') : '/'
29};
Note: See TracBrowser for help on using the repository browser.