list-utf8-files
v2.0.0
Published
List all UTF-8-encoded files in a given directory
Downloads
5
Maintainers
Readme
list-utf8-files
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
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