Skip to content

Feature: directoriesNames method in path.js

Rodrigo Muino Tomonari requested to merge github/fork/jy95/path-directories into master
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Description

I find out a random behaviour when testing the dirname method of lib/path.js with a windows path :

const path = require("path")
path.dirname("D:\\DDL\\ANIME\\les chevaliers du zodiaques\\whateverFile.avi");
// it gives "." at least on https://npm.runkit.com ^^

Since this method seems to work with no Windows path(s), I thought about a cross-platform version.

Here is my suggestion :

The path.directoriesNames() method returns an array that contains all directories names contained in a path

const path = require('path');
// Windows path - gives [ 'D:', 'DDL', 'ANIME', 'les chevaliers du zodiaques' ]
path.directoriesNames('D:\\DDL\\ANIME\\les chevaliers du zodiaques\\aFile.avi');
// POSIX path - gives [ '/' ]
path.directoriesNames('/foo');

For what it would useful ? Kind of dirname + ^^

Edit : sorry for the duplicate history - I wrote a wrong message . Commit squashing should be ok.

Merge request reports

Loading