Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 6.4KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # readdirp [![Weekly downloads](https://img.shields.io/npm/dw/readdirp.svg)](https://github.com/paulmillr/readdirp)
  2. > Recursive version of [fs.readdir](https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback). Exposes a **stream api** and a **promise api**.
  3. [![NPM](https://nodei.co/npm/readdirp.png?downloads=true&stars=true)](https://www.npmjs.com/package/readdirp)
  4. ```sh
  5. npm install readdirp
  6. ```
  7. ```javascript
  8. const readdirp = require('readdirp');
  9. // Use streams to achieve small RAM & CPU footprint.
  10. // 1) Streams example with for-await. Node.js 10+ only.
  11. for await (const entry of readdirp('.')) {
  12. const {path} = entry;
  13. console.log(`${JSON.stringify({path})}`);
  14. }
  15. // 2) Streams example, non for-await.
  16. // Print out all JS files along with their size within the current folder & subfolders.
  17. readdirp('.', {fileFilter: '*.js', alwaysStat: true})
  18. .on('data', (entry) => {
  19. const {path, stats: {size}} = entry;
  20. console.log(`${JSON.stringify({path, size})}`);
  21. })
  22. // Optionally call stream.destroy() in `warn()` in order to abort and cause 'close' to be emitted
  23. .on('warn', error => console.error('non-fatal error', error))
  24. .on('error', error => console.error('fatal error', error))
  25. .on('end', () => console.log('done'));
  26. // 3) Promise example. More RAM and CPU than streams.
  27. const files = await readdirp.promise('.');
  28. console.log(files.map(file => file.path));
  29. // Other options.
  30. readdirp('test', {
  31. fileFilter: '*.js',
  32. directoryFilter: ['!.git', '!*modules']
  33. // directoryFilter: (di) => di.basename.length === 9
  34. type: 'files_directories',
  35. depth: 1
  36. });
  37. ```
  38. For more examples, check out `examples` directory.
  39. # API
  40. `const stream = readdirp(root[, options])` — **Stream API**
  41. - Reads given root recursively and returns a `stream` of [entry infos](#entryinfo)
  42. - Optionally can be used like `for await (const entry of stream)` with node.js 10+ (`asyncIterator`).
  43. - `on('data', (entry) => {})` [entry info](#entryinfo) for every file / dir.
  44. - `on('warn', (error) => {})` non-fatal `Error` that prevents a file / dir from being processed. Example: inaccessible to the user.
  45. - `on('error', (error) => {})` fatal `Error` which also ends the stream. Example: illegal options where passed.
  46. - `on('end')` — we are done. Called when all entries were found and no more will be emitted.
  47. - `on('close')` — stream is destroyed via `stream.destroy()`.
  48. Could be useful if you want to manually abort even on a non fatal error.
  49. At that point the stream is no longer `readable` and no more entries, warning or errors are emitted
  50. - To learn more about streams, consult the very detailed [nodejs streams documentation](https://nodejs.org/api/stream.html)
  51. or the [stream-handbook](https://github.com/substack/stream-handbook)
  52. `const entries = await readdirp.promise(root[, options])` — **Promise API**. Returns a list of [entry infos](#entryinfo).
  53. First argument is awalys `root`, path in which to start reading and recursing into subdirectories.
  54. ### options
  55. - `fileFilter: ["*.js"]`: filter to include or exclude files. A `Function`, Glob string or Array of glob strings.
  56. - **Function**: a function that takes an entry info as a parameter and returns true to include or false to exclude the entry
  57. - **Glob string**: a string (e.g., `*.js`) which is matched using [picomatch](https://github.com/micromatch/picomatch), so go there for more
  58. information. Globstars (`**`) are not supported since specifying a recursive pattern for an already recursive function doesn't make sense. Negated globs (as explained in the minimatch documentation) are allowed, e.g., `!*.txt` matches everything but text files.
  59. - **Array of glob strings**: either need to be all inclusive or all exclusive (negated) patterns otherwise an error is thrown.
  60. `['*.json', '*.js']` includes all JavaScript and Json files.
  61. `['!.git', '!node_modules']` includes all directories except the '.git' and 'node_modules'.
  62. - Directories that do not pass a filter will not be recursed into.
  63. - `directoryFilter: ['!.git']`: filter to include/exclude directories found and to recurse into. Directories that do not pass a filter will not be recursed into.
  64. - `depth: 5`: depth at which to stop recursing even if more subdirectories are found
  65. - `type: 'files'`: determines if data events on the stream should be emitted for `'files'` (default), `'directories'`, `'files_directories'`, or `'all'`. Setting to `'all'` will also include entries for other types of file descriptors like character devices, unix sockets and named pipes.
  66. - `alwaysStat: false`: always return `stats` property for every file. Setting it to `true` can double readdir execution time - use it only when you need file `size`, `mtime` etc. Cannot be enabled on node <10.10.0.
  67. - `lstat: false`: include symlink entries in the stream along with files. When `true`, `fs.lstat` would be used instead of `fs.stat`
  68. ### `EntryInfo`
  69. Has the following properties:
  70. - `path: 'assets/javascripts/react.js'`: path to the file/directory (relative to given root)
  71. - `fullPath: '/Users/dev/projects/app/assets/javascripts/react.js'`: full path to the file/directory found
  72. - `basename: 'react.js'`: name of the file/directory
  73. - `dirent: fs.Dirent`: built-in [dir entry object](https://nodejs.org/api/fs.html#fs_class_fs_dirent) - only with `alwaysStat: false`
  74. - `stats: fs.Stats`: built in [stat object](https://nodejs.org/api/fs.html#fs_class_fs_stats) - only with `alwaysStat: true`
  75. # Changelog
  76. 3.1 (Jul 7, 2019) brings `bigint` support to `stat` outputs on windows. This is backwards-incompatible for some cases.
  77. Be careful. It you use it incorrectly, you'll see "TypeError: Cannot mix BigInt and other types, use explicit conversions".
  78. Version 3 brings huge performance improvements and stream backpressure support.
  79. - Upgrading 2.x to 3.x:
  80. - Signature changed from `readdirp(options)` to `readdirp(root, options)`
  81. - Replaced callback API with promise API.
  82. - Renamed `entryType` option to `type`
  83. - Renamed `entryType: 'both'` to `'files_directories'`
  84. - `EntryInfo`
  85. - Renamed `stat` to `stats`
  86. - Emitted only when `alwaysStat: true`
  87. - `dirent` is emitted instead of `stats` by default with `alwaysStat: false`
  88. - Renamed `name` to `basename`
  89. - Removed `parentDir` and `fullParentDir` properties
  90. - Supported node.js versions:
  91. - 3.x: node 8+
  92. - 2.x: node 0.6+
  93. # License
  94. Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com)
  95. MIT License, see LICENSE file.