parentPaths.js 385 B

123456789101112131415161718
  1. 'use strict';
  2. const dotRE = /\./g;
  3. module.exports = function parentPaths(path) {
  4. if (path.indexOf('.') === -1) {
  5. return [path];
  6. }
  7. const pieces = path.split(dotRE);
  8. const len = pieces.length;
  9. const ret = new Array(len);
  10. let cur = '';
  11. for (let i = 0; i < len; ++i) {
  12. cur += (cur.length !== 0) ? '.' + pieces[i] : pieces[i];
  13. ret[i] = cur;
  14. }
  15. return ret;
  16. };