@magic/fs 0.0.23 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -238,7 +238,10 @@ update dependencies
238
238
  ##### 0.0.22
239
239
  update dependencies
240
240
 
241
- ##### 0.0.23 - unreleased
241
+ ##### 0.0.23
242
+ getFiles: allow files to be filtered by extension, using the .extension key of the second parameter
243
+
244
+ ##### 0.0.24 - unreleased
242
245
  ...
243
246
 
244
247
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/fs",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "author": "Wizards & Witches",
5
5
  "description": "nodejs fs promises + goodies",
6
6
  "license": "AGPL-3.0",
package/src/getFiles.mjs CHANGED
@@ -14,13 +14,18 @@ export const getFiles = async (dir, depth = true, root = 'deprecated') => {
14
14
  if (root !== 'deprecated') {
15
15
  log.warn('E_DEPRECATED', 'you have used fs.getFiles with a third argument.')
16
16
  log.info('Please use the new syntax instead:')
17
- log.info('fs.getFiles(dir, { depth: true, root: false })')
17
+ log.info("fs.getFiles(dir, { depth: true, root: false, extension: 'md' })")
18
18
  } else {
19
19
  root = false
20
20
  }
21
21
 
22
+ let extension
23
+
22
24
  if (!is.empty(depth) && is.objectNative(depth)) {
23
25
  root = root || depth?.root
26
+ extension = depth?.extension
27
+
28
+ /* make sure this is the last action in this if */
24
29
  depth = depth?.depth
25
30
  }
26
31
 
@@ -57,6 +62,7 @@ export const getFiles = async (dir, depth = true, root = 'deprecated') => {
57
62
  deep
58
63
  .flatten(files)
59
64
  .filter(a => a)
65
+ .filter(a => !extension || a.endsWith(extension))
60
66
  .filter(async f => {
61
67
  const stat = await fs.stat(f)
62
68
  return stat.isFile()