Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
readdir-sorted
Advanced tools
Like `fs.promise.readdir()`, but sorts the result based on `String#localeCompare()`
Like fs.promise.readdir()
but sorts the result based on String#localeCompare()
const readdirSorted = require('readdir-sorted');
(async () => {
await readdirSorted('.'); /* => [
'.editorconfig',
'.gitattributes',
'.gitignore',
'.travis.yml',
'index.js',
'LICENSE',
'package.json',
'README.md',
'test'
] */
})();
npm install readdir-sorted
const readdirSorted = require('readdir-sorted');
path: string | Buffer | URL
(directory path)
options: Object
Return: Promise<string[]|Buffer[]|fs.Dirent[]>
It returns a result of fs.promises.readdir()
with sorting entries based on String#localeCompare()
.
Both will be passed to fs.promises.readdir()
.
(async () => {
await readdirSorted('example');
//=> ['directory', 'file.txt', 'symlink']
await readdirSorted('example', {
encoding: 'base64',
withFileTypes: true
});
/* => [
Dirent { name: 'ZGlyZWN0b3J5', [Symbol(type)]: 2 },
Dirent { name: 'aW5kZXguanM=', [Symbol(type)]: 1 },
Dirent { name: 'c3ltbGluaw==', [Symbol(type)]: 3 }
] */
})();
locale
property will be passed to the second argument of String#localeCompare()
, and the rest will be used in the third argument.
(async () => {
await readdirSorted('/path/to/dir');
//=> ['10', '2', 'ä', 'z']
await readdirSorted('/path/to/dir', {
locale: 'sv',
numeric: true
});
//=> ['2', '10', 'z', 'ä']
})();
ISC License © 2017 - 2019 Watanabe Shinnosuke
FAQs
Like `fs.promise.readdir()`, but sorts the result based on `String#localeCompare()`
The npm package readdir-sorted receives a total of 212 weekly downloads. As such, readdir-sorted popularity was classified as not popular.
We found that readdir-sorted 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.