Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/get-common-path.js

36 lines
4.8 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
function getCommonPathFragmentsCount(fragmentedPath1, fragmentedPath2) {
const maxCommonPathFragmentsCount = Math.min(fragmentedPath1.length, fragmentedPath2.length);
let commonPathFragmentsIndex = 0;
while (commonPathFragmentsIndex < maxCommonPathFragmentsCount) {
if (fragmentedPath1[commonPathFragmentsIndex] !== fragmentedPath2[commonPathFragmentsIndex])
break;
commonPathFragmentsIndex++;
}
return commonPathFragmentsIndex;
}
function getCommonPathFragments(fragmentedPaths) {
const lastFragmentedPath = fragmentedPaths.pop();
const commonPathFragmentsCounts = fragmentedPaths
.map(fragmentedPath => getCommonPathFragmentsCount(fragmentedPath, lastFragmentedPath));
return lastFragmentedPath.splice(0, Math.min(...commonPathFragmentsCounts));
}
function default_1(paths) {
if (!paths)
return null;
if (paths.length === 1)
return paths[0];
const fragmentedPaths = paths.map(item => item.split(path_1.default.sep));
const commonPathFragments = getCommonPathFragments(fragmentedPaths);
if (!commonPathFragments.length)
return null;
return commonPathFragments.join(path_1.default.sep);
}
exports.default = default_1;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0LWNvbW1vbi1wYXRoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2dldC1jb21tb24tcGF0aC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLGdEQUF3QjtBQUd4QixTQUFTLDJCQUEyQixDQUFFLGVBQWUsRUFBRSxlQUFlO0lBQ2xFLE1BQU0sMkJBQTJCLEdBQUcsSUFBSSxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUMs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