LICENSE000064400000001354151113167360005560 0ustar00The ISC License Copyright (c) Isaac Z. Schlueter Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. index.js000064400000000731151113167360006216 0ustar00const {parse, sep, normalize: norm} = require('path') function* commonArrayMembers (a, b) { const [l, s] = a.length > b.length ? [a, b] : [b, a] for (const x of s) { if (x === l.shift()) yield x else break } } const commonAncestorPath = (a, b) => a === b ? a : parse(a).root !== parse(b).root ? null : [...commonArrayMembers(norm(a).split(sep), norm(b).split(sep))].join(sep) module.exports = (...paths) => paths.reduce(commonAncestorPath) package.json000064400000001230151113167360007032 0ustar00{ "name": "common-ancestor-path", "version": "1.0.1", "files": [ "index.js" ], "description": "Find the common ancestor of 2 or more paths on Windows or Unix", "repository": { "type": "git", "url": "git+https://github.com/isaacs/common-ancestor-path" }, "author": "Isaac Z. Schlueter (https://izs.me)", "license": "ISC", "scripts": { "test": "tap", "snap": "tap", "preversion": "npm test", "postversion": "npm publish", "prepublishOnly": "git push origin --follow-tags" }, "tap": { "check-coverage": true }, "devDependencies": { "require-inject": "^1.4.4", "tap": "^14.10.7" } }