list-utf8-files

    2.0.0 • Public • Published

    list-utf8-files

    npm version Build Status Coverage Status

    List all UTF-8-encoded files in a given directory

    const listUtf8Files = require('list-utf8-files');
     
    /*
      ./dir/foo.txt: plain text file
      ./dir/node   : binary file
      ./dir/dir    : directory
      ./dir/bar.txt: empty file
    */
     
    (async () => {
      await listUtf8Files('dir');
      //=> Set {'/Users/example/dir/foo.txt', '/Users/example/dir/bar.txt'}
    })();

    Installation

    Use npm.

    npm install list-utf8-files
    

    API

    const listUtf8Files = require('list-utf8-files');

    listUtf8Files(dir [, options])

    dir: string (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 UTF-8-encoded files included in the given directory.

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

    (async () => {
      const iterator = (await Utf8Files('/example')).values();
     
      iterator.next().value; //=> '/example/10.js'
      iterator.next().value; //=> '/example/2a.js'
      iterator.next().value; //=> '/example/2A.js'
    })();
     
    (async () => {
      const iterator = (await Utf8Files('/example')).values({
        numeric: true,
        caseFirst: 'upper',
        encoding: 'buffer'
      });
     
      iterator.next().value; //=> Buffer.from('/dirs/2A.js')
      iterator.next().value; //=> Buffer('/dirs/2a.js')
      iterator.next().value; //=> Buffer.from('/dirs/10.js')
    })();

    License

    ISC License © 2017 - 2018 Shinnosuke Watanabe

    Install

    npm i list-utf8-files

    DownloadsWeekly Downloads

    2

    Version

    2.0.0

    License

    ISC

    Unpacked Size

    4.45 kB

    Total Files

    4

    Last publish

    Collaborators

    • shinnn