huan-file-tool 1.0.0
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/.eslintignore +30 -0
- package/.eslintrc.cjs +127 -0
- package/.npmignore +67 -0
- package/.prettierrc.cjs +14 -0
- package/LICENSE +8 -0
- package/README.md +25 -0
- package/REEPORT +15 -0
- package/package.json +46 -0
- package/src/internal/commonjs/filewalk.cjs +45 -0
- package/src/internal/esmodule/filewalk.mjs +45 -0
- package/src/main.cjs +5 -0
- package/src/main.mjs +5 -0
package/.eslintignore
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Logs
|
2
|
+
logs
|
3
|
+
*.log
|
4
|
+
npm-debug.log*
|
5
|
+
yarn-debug.log*
|
6
|
+
yarn-error.log*
|
7
|
+
pnpm-debug.log*
|
8
|
+
lerna-debug.log*
|
9
|
+
|
10
|
+
node_modules
|
11
|
+
dist
|
12
|
+
dist-ssr
|
13
|
+
dist-*
|
14
|
+
dist-development
|
15
|
+
dist-production
|
16
|
+
dist-dev
|
17
|
+
dist-prod
|
18
|
+
docs
|
19
|
+
*.local
|
20
|
+
|
21
|
+
# Editor directories and files
|
22
|
+
.vscode/*
|
23
|
+
!.vscode/extensions.json
|
24
|
+
.idea
|
25
|
+
.DS_Store
|
26
|
+
*.suo
|
27
|
+
*.ntvs*
|
28
|
+
*.njsproj
|
29
|
+
*.sln
|
30
|
+
*.sw?
|
package/.eslintrc.cjs
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
/*!
|
2
|
+
* https://eslint.bootcss.com/docs/rules/
|
3
|
+
* https://eslint.vuejs.org/rules/
|
4
|
+
*/
|
5
|
+
|
6
|
+
module.exports = {
|
7
|
+
root: true,
|
8
|
+
env: {
|
9
|
+
browser: true,
|
10
|
+
node: true,
|
11
|
+
es6: true
|
12
|
+
},
|
13
|
+
parserOptions: {
|
14
|
+
sourceType: 'module'
|
15
|
+
},
|
16
|
+
extends: ['prettier', 'eslint:recommended', 'plugin:prettier/recommended'],
|
17
|
+
plugins: ['prettier'],
|
18
|
+
rules: {
|
19
|
+
'no-undef': 'off',
|
20
|
+
'prettier/prettier': 'warn',
|
21
|
+
'no-unused-vars': 'warn',
|
22
|
+
// 禁用debugger
|
23
|
+
'no-debugger': 'warn',
|
24
|
+
// 禁止出现重复的 case 标签
|
25
|
+
'no-duplicate-case': 'warn',
|
26
|
+
// 禁止出现空语句块
|
27
|
+
// 'no-empty': 'warn',
|
28
|
+
// 禁止不必要的括号
|
29
|
+
'no-extra-parens': 'off',
|
30
|
+
// 禁止对 function 声明重新赋值
|
31
|
+
'no-func-assign': 'warn',
|
32
|
+
// 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
|
33
|
+
'no-unreachable': 'warn',
|
34
|
+
// 强制所有控制语句使用一致的括号风格
|
35
|
+
curly: 'warn',
|
36
|
+
// 要求 switch 语句中有 default 分支
|
37
|
+
'default-case': 'warn',
|
38
|
+
// 强制尽可能地使用点号
|
39
|
+
'dot-notation': 'warn',
|
40
|
+
// 要求使用 === 和 !==
|
41
|
+
// eqeqeq: 'warn',
|
42
|
+
// 禁止 if 语句中 return 语句之后有 else 块
|
43
|
+
'no-else-return': 'warn',
|
44
|
+
// 禁止出现空函数
|
45
|
+
// 'no-empty-function': 'warn',
|
46
|
+
// 禁用不必要的嵌套块
|
47
|
+
'no-lone-blocks': 'warn',
|
48
|
+
// 禁止使用多个空格
|
49
|
+
'no-multi-spaces': 'warn',
|
50
|
+
// 禁止多次声明同一变量
|
51
|
+
'no-redeclare': 'warn',
|
52
|
+
// 禁止在 return 语句中使用赋值语句
|
53
|
+
'no-return-assign': 'warn',
|
54
|
+
// 禁用不必要的 return await
|
55
|
+
'no-return-await': 'warn',
|
56
|
+
// 禁止自我赋值
|
57
|
+
'no-self-assign': 'warn',
|
58
|
+
// 禁止自身比较
|
59
|
+
'no-self-compare': 'warn',
|
60
|
+
// 禁止不必要的 catch 子句
|
61
|
+
'no-useless-catch': 'warn',
|
62
|
+
// 禁止多余的 return 语句
|
63
|
+
'no-useless-return': 'warn',
|
64
|
+
// 禁止变量声明与外层作用域的变量同名
|
65
|
+
'no-shadow': 'off',
|
66
|
+
// 允许delete变量
|
67
|
+
'no-delete-var': 'off',
|
68
|
+
// 强制数组方括号中使用一致的空格
|
69
|
+
'array-bracket-spacing': 'warn',
|
70
|
+
// 强制在代码块中使用一致的大括号风格
|
71
|
+
'brace-style': 'warn',
|
72
|
+
// 强制使用骆驼拼写法命名约定
|
73
|
+
// camelcase: 'warn',
|
74
|
+
// 强制使用一致的缩进
|
75
|
+
indent: 'off',
|
76
|
+
// 强制在 JSX 属性中一致地使用双引号或单引号
|
77
|
+
// 'jsx-quotes': 'warn',
|
78
|
+
// 强制可嵌套的块的最大深度4
|
79
|
+
'max-depth': 'warn',
|
80
|
+
// 强制最大行数 300
|
81
|
+
// "max-lines": ["warn", { "max": 1200 }],
|
82
|
+
// 强制函数最大代码行数 50
|
83
|
+
// 'max-lines-per-function': ['warn', { max: 70 }],
|
84
|
+
// 强制函数块最多允许的的语句数量20
|
85
|
+
'max-statements': ['warn', 100],
|
86
|
+
// 强制回调函数最大嵌套深度
|
87
|
+
'max-nested-callbacks': ['warn', 5],
|
88
|
+
// 强制每一行中所允许的最大语句数量
|
89
|
+
'max-statements-per-line': ['warn', { max: 1 }],
|
90
|
+
// 要求方法链中每个调用都有一个换行符
|
91
|
+
'newline-per-chained-call': ['warn', { ignoreChainWithDepth: 3 }],
|
92
|
+
// 禁止 if 作为唯一的语句出现在 else 语句中
|
93
|
+
'no-lonely-if': 'warn',
|
94
|
+
// 禁止空格和 tab 的混合缩进
|
95
|
+
'no-mixed-spaces-and-tabs': 'warn',
|
96
|
+
// 禁止出现多行空行
|
97
|
+
'no-multiple-empty-lines': 'warn',
|
98
|
+
// 禁止出现;
|
99
|
+
semi: ['warn', 'never'],
|
100
|
+
// 强制在块之前使用一致的空格
|
101
|
+
'space-before-blocks': 'warn',
|
102
|
+
// 强制在 function的左括号之前使用一致的空格
|
103
|
+
// 'space-before-function-paren': ['warn', 'never'],
|
104
|
+
// 强制在圆括号内使用一致的空格
|
105
|
+
'space-in-parens': 'warn',
|
106
|
+
// 要求操作符周围有空格
|
107
|
+
'space-infix-ops': 'warn',
|
108
|
+
// 强制在一元操作符前后使用一致的空格
|
109
|
+
'space-unary-ops': 'warn',
|
110
|
+
// 强制在注释中 // 或 /* 使用一致的空格
|
111
|
+
// "spaced-comment": "warn",
|
112
|
+
// 强制在 switch 的冒号左右有空格
|
113
|
+
'switch-colon-spacing': 'warn',
|
114
|
+
// 强制箭头函数的箭头前后使用一致的空格
|
115
|
+
'arrow-spacing': 'warn',
|
116
|
+
'no-var': 'warn',
|
117
|
+
'prefer-const': 'warn',
|
118
|
+
'prefer-rest-params': 'warn',
|
119
|
+
'no-useless-escape': 'warn',
|
120
|
+
'no-irregular-whitespace': 'warn',
|
121
|
+
'no-prototype-builtins': 'warn',
|
122
|
+
'no-fallthrough': 'warn',
|
123
|
+
'no-extra-boolean-cast': 'warn',
|
124
|
+
'no-case-declarations': 'warn',
|
125
|
+
'no-async-promise-executor': 'warn'
|
126
|
+
}
|
127
|
+
}
|
package/.npmignore
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Logs
|
2
|
+
logs
|
3
|
+
*.log
|
4
|
+
npm-debug.log*
|
5
|
+
yarn-debug.log*
|
6
|
+
yarn-error.log*
|
7
|
+
pnpm-debug.log*
|
8
|
+
lerna-debug.log*
|
9
|
+
|
10
|
+
# Node
|
11
|
+
node_modules
|
12
|
+
.npmrc
|
13
|
+
|
14
|
+
# Build
|
15
|
+
dist
|
16
|
+
dist-*
|
17
|
+
dist-ssr
|
18
|
+
dist-dev
|
19
|
+
dist-prod
|
20
|
+
|
21
|
+
# Git
|
22
|
+
.git
|
23
|
+
.gitignore
|
24
|
+
|
25
|
+
# Github
|
26
|
+
github-page
|
27
|
+
docs
|
28
|
+
.github
|
29
|
+
|
30
|
+
# Local
|
31
|
+
*.local
|
32
|
+
|
33
|
+
# Hidden
|
34
|
+
.*
|
35
|
+
!.prettierrc.cjs
|
36
|
+
!.npmignore
|
37
|
+
!.eslintignore
|
38
|
+
!.eslintrc.cjs
|
39
|
+
!public/.__ignore__
|
40
|
+
|
41
|
+
# IDE
|
42
|
+
.vscode
|
43
|
+
.idea
|
44
|
+
|
45
|
+
# System
|
46
|
+
.DS_Store
|
47
|
+
desktop.ini
|
48
|
+
thumbs.db
|
49
|
+
iconcache.db
|
50
|
+
IconCache.db
|
51
|
+
ntuser.dat
|
52
|
+
ntuser.dat.log
|
53
|
+
hiberfil.sys
|
54
|
+
pagefile.sys
|
55
|
+
$Recycle.Bin
|
56
|
+
Recycle Bin
|
57
|
+
|
58
|
+
# Other
|
59
|
+
*.suo
|
60
|
+
*.ntvs*
|
61
|
+
*.njsproj
|
62
|
+
*.sln
|
63
|
+
*.sw?
|
64
|
+
*.bak
|
65
|
+
|
66
|
+
# Pack
|
67
|
+
huan-*.tgz
|
package/.prettierrc.cjs
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module.exports = {
|
2
|
+
printWidth: 120, // 换行字符串阈值
|
3
|
+
tabWidth: 2, // 设置工具每一个水平缩进的空格数
|
4
|
+
useTabs: false,
|
5
|
+
semi: false, // 句末是否加分号
|
6
|
+
vueIndentScriptAndStyle: true,
|
7
|
+
singleQuote: true, // 用单引号
|
8
|
+
trailingComma: 'none', // 最后一个对象元素符加逗号
|
9
|
+
bracketSpacing: true,
|
10
|
+
jsxBracketSameLine: true, // jsx > 是否另取一行
|
11
|
+
arrowParens: 'always', // 不需要写文件开头的 @prettier
|
12
|
+
insertPragma: false, // 不需要自动在文件开头加入 @prettier
|
13
|
+
endOfLine: 'lf' // 换行符使用
|
14
|
+
}
|
package/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright (c) 2025 宋子桓(Song Zihuan)
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# 简易文件处理程序(Huan-File-Tool)
|
2
|
+
|
3
|
+
这是一个使用JavaScript编写的建议文件处理程序,使用`ES Module`模式。
|
4
|
+
|
5
|
+
目前,所有导出函数位于:`src/main.cjs`和`src/main.mjs`文件中,此文件也是本项目的入口文件。
|
6
|
+
|
7
|
+
注意:本项目同时支持`CommonJS`和`ESModule`两种模式。
|
8
|
+
|
9
|
+
## 作者信息
|
10
|
+
作者:宋子桓(Song Zihuan)
|
11
|
+
|
12
|
+
作者 Github:[github.com/SongZihuan](https://github.com/SongZihuan)
|
13
|
+
|
14
|
+
作者主页:[song-zh.com](https://song-zh.com)
|
15
|
+
|
16
|
+
作者邮箱:songzihuan@song-zh.com
|
17
|
+
|
18
|
+
## 项目信息
|
19
|
+
项目托管地址:[github.com/SongZihuan/js-file-tool](https://github.com/SongZihuan/js-file-tool)
|
20
|
+
GitHub托管地址:[github.com/SongZihuan/js-file-tool](https://github.com/SongZihuan/js-file-tool)
|
21
|
+
|
22
|
+
最后更新时间:2025年1月22日。
|
23
|
+
|
24
|
+
## 特别注意
|
25
|
+
备注:以上README为作者原文。
|
package/REEPORT
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
如何报告 JavaScript-File-Tool
|
2
|
+
|
3
|
+
作者:宋子桓(Song Zihuan)
|
4
|
+
作者 Github:https://github.com/SongZihuan
|
5
|
+
作者主页:https://song-zh.com
|
6
|
+
作者邮箱:songzihuan@song-zh.com
|
7
|
+
|
8
|
+
Github:https://github.com/SongZihuan/js-file-tool
|
9
|
+
Github Issues:https://github.com/SongZihuan/js-file-tool/issues
|
10
|
+
|
11
|
+
报告:您可以通过 Github Issues 或作者邮箱报告问题并联系作者。
|
12
|
+
质量保证:如果您仅拥有此项目根目录下的 LICENSE 文件中的许可证,您将无法获得任何质量保证。但作者很乐意为您解决问题,除非此项目已存档为只读。
|
13
|
+
其他 Fork 版本:请联系 Fork 版本的作者寻求帮助。
|
14
|
+
|
15
|
+
备注:以上REPORT为作者原文。
|
package/package.json
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"name": "huan-file-tool",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "简单的文件处理工具",
|
5
|
+
"private": false,
|
6
|
+
"keywords": [
|
7
|
+
"javaascript",
|
8
|
+
"commonjs",
|
9
|
+
"esmodule",
|
10
|
+
"nodejs",
|
11
|
+
"file-tool",
|
12
|
+
"web-demo"
|
13
|
+
],
|
14
|
+
"main": "./src/main.cjs",
|
15
|
+
"module": "./src/main.mjs",
|
16
|
+
"exports": {
|
17
|
+
".": {
|
18
|
+
"require": "./src/main.cjs",
|
19
|
+
"import": "./src/main.mjs",
|
20
|
+
"default": "./src/main.mjs"
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"author": "宋子桓(Song Zihuan)",
|
24
|
+
"license": "MIT LICENSE",
|
25
|
+
"repository": "https://github.com/SongZihuan/js-file-tool",
|
26
|
+
"bug": "https://github.com/SongZihuan/js-file-tool/issues",
|
27
|
+
"homepage": "https://github.com/SongZihuan/js-file-tool",
|
28
|
+
"engines": {
|
29
|
+
"node": ">=18",
|
30
|
+
"pnpm": ">=8"
|
31
|
+
},
|
32
|
+
"devDependencies": {
|
33
|
+
"eslint": "^8.38.0",
|
34
|
+
"eslint-config-prettier": "^8.8.0",
|
35
|
+
"eslint-plugin-prettier": "^4.2.1",
|
36
|
+
"prettier": "^2.8.7"
|
37
|
+
},
|
38
|
+
"dependencies": {},
|
39
|
+
"scripts": {
|
40
|
+
"init": "npx pnpm install",
|
41
|
+
"lint": "eslint --ext .js,.mjs,.cjs,.ts --fix .",
|
42
|
+
"lint:debug": "eslint --ext .js,.mjs,.cjs,.ts --debug --fix .",
|
43
|
+
"pack": "npx pnpm run init && npx pnpm run lint && npx pnpm pack",
|
44
|
+
"login": "npx pnpm login --registry=https://registry.npmjs.org"
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
const path = require('path')
|
2
|
+
const fs = require('fs')
|
3
|
+
|
4
|
+
function getAllFilePaths(dir) {
|
5
|
+
return _getAllFilePaths(dir, './', 5)
|
6
|
+
}
|
7
|
+
|
8
|
+
function _getAllFilePaths(filePath, localpath, deep) {
|
9
|
+
if (deep === 0) {
|
10
|
+
return [], []
|
11
|
+
}
|
12
|
+
|
13
|
+
let filePathResult = []
|
14
|
+
let localPathResult = []
|
15
|
+
|
16
|
+
// 读取目录中的所有文件和子目录
|
17
|
+
fs.readdirSync(filePath).forEach(function (file) {
|
18
|
+
const newFilePath = path.join(filePath, file)
|
19
|
+
const newLocalPath = path.join(localpath, file)
|
20
|
+
|
21
|
+
// 如果是目录,则递归读取该目录下的文件
|
22
|
+
if (fs.statSync(newFilePath).isDirectory()) {
|
23
|
+
const { filePathResult: _filrPath, localPathResult: _localPath } = _getAllFilePaths(
|
24
|
+
newFilePath,
|
25
|
+
newLocalPath,
|
26
|
+
deep - 1
|
27
|
+
)
|
28
|
+
filePathResult = filePathResult.concat(_filrPath)
|
29
|
+
localPathResult = localPathResult.concat(_localPath)
|
30
|
+
} else {
|
31
|
+
// 如果是文件,则直接加入结果数组
|
32
|
+
filePathResult.push(newFilePath)
|
33
|
+
localPathResult.push(newLocalPath)
|
34
|
+
}
|
35
|
+
})
|
36
|
+
|
37
|
+
return {
|
38
|
+
filePathResult,
|
39
|
+
localPathResult
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
module.exports = {
|
44
|
+
getAllFilePaths
|
45
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import path from 'path'
|
2
|
+
import fs from 'fs'
|
3
|
+
|
4
|
+
export default {
|
5
|
+
getAllFilePaths
|
6
|
+
}
|
7
|
+
|
8
|
+
export function getAllFilePaths(dir) {
|
9
|
+
return _getAllFilePaths(dir, './', 5)
|
10
|
+
}
|
11
|
+
|
12
|
+
function _getAllFilePaths(filePath, localpath, deep) {
|
13
|
+
if (deep === 0) {
|
14
|
+
return [], []
|
15
|
+
}
|
16
|
+
|
17
|
+
let filePathResult = []
|
18
|
+
let localPathResult = []
|
19
|
+
|
20
|
+
// 读取目录中的所有文件和子目录
|
21
|
+
fs.readdirSync(filePath).forEach(function (file) {
|
22
|
+
const newFilePath = path.join(filePath, file)
|
23
|
+
const newLocalPath = path.join(localpath, file)
|
24
|
+
|
25
|
+
// 如果是目录,则递归读取该目录下的文件
|
26
|
+
if (fs.statSync(newFilePath).isDirectory()) {
|
27
|
+
const { filePathResult: _filrPath, localPathResult: _localPath } = _getAllFilePaths(
|
28
|
+
newFilePath,
|
29
|
+
newLocalPath,
|
30
|
+
deep - 1
|
31
|
+
)
|
32
|
+
filePathResult = filePathResult.concat(_filrPath)
|
33
|
+
localPathResult = localPathResult.concat(_localPath)
|
34
|
+
} else {
|
35
|
+
// 如果是文件,则直接加入结果数组
|
36
|
+
filePathResult.push(newFilePath)
|
37
|
+
localPathResult.push(newLocalPath)
|
38
|
+
}
|
39
|
+
})
|
40
|
+
|
41
|
+
return {
|
42
|
+
filePathResult,
|
43
|
+
localPathResult
|
44
|
+
}
|
45
|
+
}
|
package/src/main.cjs
ADDED