Socket
Socket
Sign inDemoInstall

@fcostarodrigo/walk

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fcostarodrigo/walk - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0

.editorconfig

4

CHANGELOG.md

@@ -0,3 +1,7 @@

# v6.0.0
Update to ESM.
# v5.0.0
- Removed the readdir argument

78

package.json
{
"name": "@fcostarodrigo/walk",
"version": "5.0.1",
"version": "6.0.0",
"description": "Transverse files recursively",
"main": "src/walk.js",
"scripts": {
"test": "jest unit int --coverage",
"pretest": "eslint src",
"format": "prettier --write ."
},
"main": "src/index.js",
"types": "src/index.d.ts",
"repository": {

@@ -31,60 +27,20 @@ "type": "git",

},
"dependencies": {},
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^14.14.2",
"eslint": "^7.12.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.14.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-tsc": "^2.0.0",
"husky": "^4.3.0",
"jest": "^26.6.1",
"lint-staged": "^10.4.2",
"prettier": "^2.1.2",
"typescript": "^4.0.3"
"@types/node": "^20.12.8",
"husky": "^9.0.11",
"vitest": "^1.5.3",
"xo": "^0.58.0"
},
"eslintConfig": {
"extends": [
"airbnb-base",
"plugin:jest/recommended",
"prettier"
],
"plugins": [
"prettier",
"jest",
"tsc"
],
"rules": {
"no-continue": "off",
"no-await-in-loop": "off",
"no-restricted-syntax": "off",
"prettier/prettier": "error",
"tsc/config": [
"error",
{
"configFile": "tsconfig.json"
}
]
}
"xo": {
"prettier": true
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
"prettier": {
"singleQuote": false,
"bracketSpacing": true,
"trailingComma": "all",
"printWidth": 100
},
"lint-staged": {
"*.{yaml,yml,json,md}": [
"prettier --write"
],
"*.{js,jsx,mjs}": [
"eslint src --fix",
"jest --findRelatedTests"
]
},
"prettier": {
"trailingComma": "all"
"scripts": {
"test": "xo --fix src && vitest run"
}
}
}
# Walk
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/57550a6a14ac4915a5502e0277654c0f)](https://app.codacy.com/app/fcostarodrigo/walk?utm_source=github.com&utm_medium=referral&utm_content=fcostarodrigo/walk&utm_campaign=Badge_Grade_Dashboard)
[![Build Status](https://travis-ci.org/fcostarodrigo/walk.svg?branch=master)](https://travis-ci.org/fcostarodrigo/walk)
[![codecov](https://codecov.io/gh/fcostarodrigo/walk/branch/master/graph/badge.svg)](https://codecov.io/gh/fcostarodrigo/walk)
Simple node module to transverse files recursively.

@@ -18,11 +14,7 @@

```javascript
const walk = require("@fcostarodrigo/walk");
import { walk } from "@fcostarodrigo/walk";
async function main() {
for await (const file of walk()) {
console.log(file);
}
for await (const file of walk()) {
console.log(file);
}
main();
```

@@ -29,0 +21,0 @@

@@ -1,7 +0,10 @@

const path = require("path");
const walk = require("./walk");
import { join } from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
import { describe, beforeAll, it, expect } from "vitest";
import { walk } from "./walk.js";
describe("walk", () => {
beforeAll(() => {
process.chdir(path.join(__dirname, "test"));
process.chdir(join(fileURLToPath(import.meta.url), "..", "test"));
});

@@ -11,2 +14,3 @@

const files = [];
for await (const file of walk()) {

@@ -17,5 +21,5 @@ files.push(file);

const expectedFiles = [
path.join("foods", "egg"),
path.join("foods", "pizza"),
path.join("foods", "fruits", "banana"),
join("foods", "egg"),
join("foods", "pizza"),
join("foods", "fruits", "banana"),
].sort();

@@ -34,7 +38,7 @@

".",
path.join("foods"),
path.join("foods", "egg"),
path.join("foods", "pizza"),
path.join("foods", "fruits"),
path.join("foods", "fruits", "banana"),
join("foods"),
join("foods", "egg"),
join("foods", "pizza"),
join("foods", "fruits"),
join("foods", "fruits", "banana"),
].sort();

@@ -46,4 +50,3 @@

it("should not transverse some folders", async () => {
const walkFolder = (folderPath) =>
folderPath !== path.join("foods", "fruits");
const walkFolder = (folderPath) => folderPath !== join("foods", "fruits");

@@ -55,6 +58,3 @@ const files = [];

const expectedFiles = [
path.join("foods", "egg"),
path.join("foods", "pizza"),
].sort();
const expectedFiles = [join("foods", "egg"), join("foods", "pizza")].sort();

@@ -65,3 +65,3 @@ expect(files.sort()).toEqual(expectedFiles);

it("should yield the first argument when it is a file", async () => {
const filePath = path.join("foods", "egg");
const filePath = join("foods", "egg");

@@ -68,0 +68,0 @@ const files = [];

@@ -1,15 +0,7 @@

const fs = require("fs").promises;
const path = require("path");
import fs from "node:fs";
import path from "node:path";
/**
* Transverse files recursively
*
* @param {string} root
* @param {boolean} listFolders
* @param {(folderPath: string) => boolean} walkFolder
* @returns {AsyncIterableIterator<string>}
*/
async function* walk(root = ".", listFolders = false, walkFolder = () => true) {
export async function* walk(root = ".", listFolders = false, walkFolder = () => true) {
try {
const files = await fs.readdir(root);
const files = await fs.promises.readdir(root);

@@ -33,3 +25,1 @@ if (listFolders) {

}
module.exports = walk;

@@ -1,16 +0,17 @@

/** @typedef {{promises: { readdir: jest.Mock}}} MockedFs */
import fs from "node:fs";
import { vi, describe, it, expect } from "vitest";
import { walk } from "./walk.js";
const fs = require("fs").promises;
const walk = require("./walk");
vi.mock("node:fs", () => ({ default: { promises: { readdir: vi.fn() } } }));
const mockReaddir = /** @type {jest.MockedFunction<typeof fs.readdir>} */ (fs.readdir);
const fsMock = vi.mocked(fs);
jest.mock("fs", () => ({ promises: { readdir: jest.fn() } }));
describe("walk", () => {
it("should throw errors thrown by the file system", () => {
const error = new Error();
mockReaddir.mockRejectedValueOnce(error);
const error = new Error("Error");
fsMock.promises.readdir.mockRejectedValueOnce(error);
return expect(walk().next()).rejects.toBe(error);
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc