Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/list-utf8-files
List all UTF8-encoded files in a given directory
https://github.com/shinnn/list-utf8-files
async encoding javascript list nodejs promise readdir set utf-8 utf8
Last synced: about 1 month ago
JSON representation
List all UTF8-encoded files in a given directory
- Host: GitHub
- URL: https://github.com/shinnn/list-utf8-files
- Owner: shinnn
- License: isc
- Created: 2017-09-05T10:39:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-05T15:01:48.000Z (about 6 years ago)
- Last Synced: 2024-11-21T19:20:06.570Z (about 2 months ago)
- Topics: async, encoding, javascript, list, nodejs, promise, readdir, set, utf-8, utf8
- Language: JavaScript
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# list-utf8-files
[![npm version](https://img.shields.io/npm/v/list-utf8-files.svg)](https://www.npmjs.com/package/list-utf8-files)
[![Build Status](https://travis-ci.com/shinnn/list-utf8-files.svg?branch=master)](https://travis-ci.com/shinnn/list-utf8-files)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/list-utf8-files.svg)](https://coveralls.io/github/shinnn/list-utf8-files?branch=master)List all [UTF-8](https://tools.ietf.org/html/rfc3629)-encoded files in a given directory
```javascript
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](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install list-utf8-files
```## API
```javascript
const listUtf8Files = require('list-utf8-files');
```### listUtf8Files(*dir* [, *options*])
*dir*: `string` (directory path)
*options*: `Object` ([`readdir-sorted`](https://github.com/shinnn/readdir-sorted) options)
Return: `Promise>`The promise will be fulfilled with a [`Set`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) of strings — absolute paths of all [UTF-8-encoded](https://github.com/wayfind/is-utf8) files included in the given directory.
Options are directly passed to the underlying [`readdir-sorted`](https://github.com/shinnn/readdir-sorted#readdirsortedpath--options) to control encoding and order of results.
```javascript
(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](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe