JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q37982F
  • License MIT

Run `fs.lstat` for all contents in a given directory

Package Exports

  • enumerate-files

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (enumerate-files) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lstat-dir

NPM version Build Status Coverage Status

Run fs.lstat for all contents in a given directory

const lstatDir = require('lstat-dir');

lstatDir('node_modules/lstat-dir').then(result => {
  result;
  /* Map {
    'LICENSE' => {mode: 33188, size: 1086, ...},
    'README.md' => {mode: 33188, size: 2060, ...}
    'index.js' => {mode: 33188, size: 124, ...}
    'package.json' => {mode: 33188, size: 922, ...}
  } */
});

Installation

Use npm.

npm install lstat-dir

API

const readUtf8File = require('lstat-dir');

readUtf8File(filePath [, options])

filePath: String (file path)
options: Object (fs.readFile options except for encoding)
Return: Promise of String (entire file contents except for BOM)

// file-with-bom.txt: '\uFEFFabc'

readUtf8File('file-with-bom.txt').then(contents => {
  contents; //=> 'abc'
});

Note that if the file is not UTF-8 encoded, the promise will be rejected. So this module is more suitable than built-in fs.readFile for the case when your application doesn't accept non-UTF-8 files.

readUtf8File('/path/to/non-utf8-file.exe').catch(err => {
  err.message; //=> "Error: Expected a UTF-8 file, but the file at '/path/to/non-utf8-file.exe' is not UTF-8 encoded."
});

License

Copyright (c) 2016 Shinnosuke Watanabe

Licensed under the MIT License.