2.0.0 • Published 5 years ago

list-utf8-files v2.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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

2.0.0

5 years ago

1.0.0

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago