@lxf2513/readdir-sync-recursive
Advanced tools
+10
-20
| 'use strict'; | ||
| const fs = require('node:fs'); | ||
| const nodePath = require('node:path'); | ||
| const process = require('node:process'); | ||
| const node_fs = require('node:fs'); | ||
| const node_path = require('node:path'); | ||
| const node_process = require('node:process'); | ||
| function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } | ||
| const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); | ||
| const nodePath__default = /*#__PURE__*/_interopDefaultCompat(nodePath); | ||
| const process__default = /*#__PURE__*/_interopDefaultCompat(process); | ||
| function isDirectory(path) { | ||
| try { | ||
| const stat = fs__default.statSync(path); | ||
| return stat.isDirectory(); | ||
| return node_fs.statSync(path).isDirectory(); | ||
| } catch { | ||
@@ -29,9 +22,8 @@ return false; | ||
| try { | ||
| const readdirResult = fs__default.readdirSync(dirpath, { encoding: "utf-8" }); | ||
| const readdirResult = node_fs.readdirSync(dirpath, { encoding: "utf-8" }); | ||
| for (let i = 0; i < readdirResult.length; i++) { | ||
| const resultPath = nodePath__default.join(dirpath, readdirResult[i]); | ||
| const relativeResultPath = nodePath__default.relative(path, resultPath); | ||
| const absolutePath = nodePath__default.join(process__default.cwd(), resultPath); | ||
| let pushPath = relativeResultPath; | ||
| returnType === "relativePath" ? pushPath = resultPath : returnType === "absolutePath" ? pushPath = absolutePath : relativeResultPath; | ||
| const resultPath = node_path.join(dirpath, readdirResult[i]); | ||
| const relativeResultPath = node_path.relative(path, resultPath); | ||
| const absolutePath = node_path.join(node_process.cwd(), resultPath); | ||
| const pushPath = returnType === "relativePath" ? resultPath : returnType === "absolutePath" ? absolutePath : relativeResultPath; | ||
| readdirResults.push(pushPath); | ||
@@ -46,5 +38,3 @@ if (isDirectory(resultPath)) { | ||
| } | ||
| for (let i = 0; i < pathsQueue.length; i++) { | ||
| readdir(pathsQueue[i]); | ||
| } | ||
| pathsQueue.forEach((i) => readdir(i)); | ||
| return readdirResults; | ||
@@ -51,0 +41,0 @@ } |
+10
-14
@@ -1,9 +0,8 @@ | ||
| import fs from 'node:fs'; | ||
| import nodePath from 'node:path'; | ||
| import process from 'node:process'; | ||
| import { statSync, readdirSync } from 'node:fs'; | ||
| import { join, relative } from 'node:path'; | ||
| import { cwd } from 'node:process'; | ||
| function isDirectory(path) { | ||
| try { | ||
| const stat = fs.statSync(path); | ||
| return stat.isDirectory(); | ||
| return statSync(path).isDirectory(); | ||
| } catch { | ||
@@ -21,9 +20,8 @@ return false; | ||
| try { | ||
| const readdirResult = fs.readdirSync(dirpath, { encoding: "utf-8" }); | ||
| const readdirResult = readdirSync(dirpath, { encoding: "utf-8" }); | ||
| for (let i = 0; i < readdirResult.length; i++) { | ||
| const resultPath = nodePath.join(dirpath, readdirResult[i]); | ||
| const relativeResultPath = nodePath.relative(path, resultPath); | ||
| const absolutePath = nodePath.join(process.cwd(), resultPath); | ||
| let pushPath = relativeResultPath; | ||
| returnType === "relativePath" ? pushPath = resultPath : returnType === "absolutePath" ? pushPath = absolutePath : relativeResultPath; | ||
| const resultPath = join(dirpath, readdirResult[i]); | ||
| const relativeResultPath = relative(path, resultPath); | ||
| const absolutePath = join(cwd(), resultPath); | ||
| const pushPath = returnType === "relativePath" ? resultPath : returnType === "absolutePath" ? absolutePath : relativeResultPath; | ||
| readdirResults.push(pushPath); | ||
@@ -38,5 +36,3 @@ if (isDirectory(resultPath)) { | ||
| } | ||
| for (let i = 0; i < pathsQueue.length; i++) { | ||
| readdir(pathsQueue[i]); | ||
| } | ||
| pathsQueue.forEach((i) => readdir(i)); | ||
| return readdirResults; | ||
@@ -43,0 +39,0 @@ } |
+1
-1
| { | ||
| "name": "@lxf2513/readdir-sync-recursive", | ||
| "version": "1.1.0", | ||
| "version": "1.2.0", | ||
| "description": "Reads the contents of the directory synchronously and recursively.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
5880
-8.77%77
-13.48%1
Infinity%