
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Utility functions used to list all files in a directory recursively, synchronously or asynchronously.
This npm module provides utility functions for listing all files in a directory either synchronously or asynchronously.
$ npm install recfs
First, we need to require the module:
const recfs = require('recfs')
Inside the recfs module, there are two functions:
readdir(directory[, options[, regex]])
and
readdirSync(directory[, options[, regex]])
.
directory
is the directiory we would like to list all files recursively from.options
is the same options as provided to fs.readdir
and fs.readdirSync
(by having this set to undefined
, the character encoding will default to utf8
).regex
allows us to specify a search pattern. If a file does not match this pattern, it will not be returned.Furthermore, readdirSync
returns a Promise
, whilst readdir
returns the
list of files located.
For the following two examples, let us assume we have the directory structure:
cache/
more/
love.js
test.htm
test.c
test.js
readdir
To read a directory asynchronously, we can do:
recfs.readdir('cache').then((files) => {
console.log(files)
}).catch((err) => {
throw err
})
// Expected output: [ 'cache/test.c', 'cache/test.js', 'cache/more/love.js', 'cache/more/test.htm' ]
Furthermore, if we are only interested in files ending in '.js', we can add a regular expression:
recfs.readdir('cache', undefined, /^.*\.js$/).then((files) => {
console.log(files)
}).catch((err) => {
throw err
})
// Expected output: [ 'cache/test.js', 'cache/more/love.js' ]
This allows us to retrieve a more specific set of files.
readdirSync
To read a directory synchronously, we can do:
let files = recfs.readdirSync('cache')
console.log(files)
// Expected output: [ 'cache/test.c', 'cache/test.js', 'cache/more/love.js', 'cache/more/test.htm' ]
Like with the asynchronous version of the function, we can provide it with a regular expression to retrieve a more specific set of files:
let files = recfs.readdirSync('cache', undefined, /^.*\.js$/)
console.log(files)
// Expected output: [ 'cache/test.js', 'cache/more/love.js' ]
This module, and the code therein, is licensed under ISC.
FAQs
Utility functions used to list all files in a directory recursively, synchronously or asynchronously.
We found that recfs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.