xref: /third_party/node/deps/npm/node_modules/common-ancestor-path/index.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/deps/npm/node_modules/common-ancestor-path/
11cb0ef41Sopenharmony_ciconst {parse, sep, normalize: norm} = require('path')
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cifunction* commonArrayMembers (a, b) {
41cb0ef41Sopenharmony_ci  const [l, s] = a.length > b.length ? [a, b] : [b, a]
51cb0ef41Sopenharmony_ci  for (const x of s) {
61cb0ef41Sopenharmony_ci    if (x === l.shift())
71cb0ef41Sopenharmony_ci      yield x
81cb0ef41Sopenharmony_ci    else
91cb0ef41Sopenharmony_ci      break
101cb0ef41Sopenharmony_ci  }
111cb0ef41Sopenharmony_ci}
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst commonAncestorPath = (a, b) => a === b ? a
141cb0ef41Sopenharmony_ci  : parse(a).root !== parse(b).root ? null
151cb0ef41Sopenharmony_ci  : [...commonArrayMembers(norm(a).split(sep), norm(b).split(sep))].join(sep)
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cimodule.exports = (...paths) => paths.reduce(commonAncestorPath)
18

Indexes created Thu Nov 07 10:32:03 CST 2024