Notorious Party Muppets

    list-directories

    1.1.0 • Public • Published

    list-directories

    npm version Build Status Coverage Status

    List all directories in a given directory

    const listDirectories = require('list-directories');
     
    /*
      ./my-dir/a: file
      ./my-dir/b: directory
      ./my-dir/c: symlink to a directory
      ./my-dir/d: directory
    */
     
    (async () => {
      await listDirectories('my-dir');
      /* => Set {
        '/Users/example/my-dir/b',
        '/Users/example/my-dir/d'
      } */
    })();

    Installation

    Use npm.

    npm install list-directories
    

    API

    const listDirectories = require('list-directories');

    listDirectories(dir)

    dir: string Buffer URL (directory path)
    options: Object (readdir-sorted options)
    Return: Promise<Set<string>>

    The promise will be fulfilled with a Set of strings — absolute paths of all directories included in the given directory.

    Options are directly passed to the underlying readdir-sorted to control the order of results.

    listDirectories('/dirs').then(files => {
      const iterator = files[Symbol.iterator];
     
      iterator.next().value; //=> '/dirs/10'
      iterator.next().value; //=> '/dirs/2a'
      iterator.next().value; //=> '/dirs/2A'
    });
     
    listDirectories('/dirs', {
      numeric: true,
      caseFirst: 'upper'
    }).then(files => {
      const iterator = files[Symbol.iterator];
     
      iterator.next().value; //=> '/dirs/2A'
      iterator.next().value; //=> '/dirs/2a'
      iterator.next().value; //=> '/dirs/10'
    });

    License

    ISC License © 2018 Shinnosuke Watanabe

    Install

    npm i list-directories

    DownloadsWeekly Downloads

    629

    Version

    1.1.0

    License

    ISC

    Last publish

    Collaborators

    • shinnn