@ainc/fs 0.1.16 → 0.1.17

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.
Files changed (255) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +18 -42
  3. package/dist/findUp.d.ts +6 -0
  4. package/dist/findUp.js +36 -0
  5. package/dist/index.d.ts +7 -38
  6. package/dist/index.js +21 -80
  7. package/dist/jsonc.d.ts +4 -20
  8. package/dist/jsonc.js +14 -31
  9. package/dist/lookup.d.ts +18 -0
  10. package/dist/lookup.js +64 -0
  11. package/dist/readFile.d.ts +1 -25
  12. package/dist/readFile.js +9 -12
  13. package/dist/relative.d.ts +12 -1
  14. package/dist/relative.js +47 -16
  15. package/dist/resolveFile.d.ts +6 -0
  16. package/dist/resolveFile.js +41 -0
  17. package/dist/{extname.d.ts → rm.d.ts} +2 -3
  18. package/dist/rm.js +35 -0
  19. package/dist/stat.d.ts +1 -16
  20. package/dist/stat.js +4 -11
  21. package/dist/{helpers → utils}/stripComments.d.ts +1 -2
  22. package/dist/utils/stripComments.js +120 -0
  23. package/package.json +33 -30
  24. package/bin/clean.js +0 -45
  25. package/bin/cli.js +0 -42
  26. package/bin/git.js +0 -40
  27. package/bin/run.js +0 -41
  28. package/dist/basename.d.ts +0 -7
  29. package/dist/basename.d.ts.map +0 -1
  30. package/dist/basename.js +0 -17
  31. package/dist/basename.js.map +0 -1
  32. package/dist/copy.d.ts +0 -41
  33. package/dist/copy.d.ts.map +0 -1
  34. package/dist/copy.js +0 -90
  35. package/dist/copy.js.map +0 -1
  36. package/dist/cpdir.d.ts +0 -20
  37. package/dist/cpdir.d.ts.map +0 -1
  38. package/dist/cpdir.js +0 -29
  39. package/dist/cpdir.js.map +0 -1
  40. package/dist/cwd.d.ts +0 -7
  41. package/dist/cwd.d.ts.map +0 -1
  42. package/dist/cwd.js +0 -17
  43. package/dist/cwd.js.map +0 -1
  44. package/dist/dirname.d.ts +0 -7
  45. package/dist/dirname.d.ts.map +0 -1
  46. package/dist/dirname.js +0 -31
  47. package/dist/dirname.js.map +0 -1
  48. package/dist/extname.d.ts.map +0 -1
  49. package/dist/extname.js +0 -17
  50. package/dist/extname.js.map +0 -1
  51. package/dist/filename.d.ts +0 -7
  52. package/dist/filename.d.ts.map +0 -1
  53. package/dist/filename.js +0 -25
  54. package/dist/filename.js.map +0 -1
  55. package/dist/find.d.ts +0 -27
  56. package/dist/find.d.ts.map +0 -1
  57. package/dist/find.js +0 -73
  58. package/dist/find.js.map +0 -1
  59. package/dist/findFile.d.ts +0 -21
  60. package/dist/findFile.d.ts.map +0 -1
  61. package/dist/findFile.js +0 -40
  62. package/dist/findFile.js.map +0 -1
  63. package/dist/finddir.d.ts +0 -21
  64. package/dist/finddir.d.ts.map +0 -1
  65. package/dist/finddir.js +0 -40
  66. package/dist/finddir.js.map +0 -1
  67. package/dist/helpers/FileResolver.d.ts +0 -54
  68. package/dist/helpers/FileResolver.d.ts.map +0 -1
  69. package/dist/helpers/FileResolver.js +0 -184
  70. package/dist/helpers/FileResolver.js.map +0 -1
  71. package/dist/helpers/compose.d.ts +0 -14
  72. package/dist/helpers/compose.d.ts.map +0 -1
  73. package/dist/helpers/compose.js +0 -38
  74. package/dist/helpers/compose.js.map +0 -1
  75. package/dist/helpers/each.d.ts +0 -7
  76. package/dist/helpers/each.d.ts.map +0 -1
  77. package/dist/helpers/each.js +0 -21
  78. package/dist/helpers/each.js.map +0 -1
  79. package/dist/helpers/match.d.ts +0 -7
  80. package/dist/helpers/match.d.ts.map +0 -1
  81. package/dist/helpers/match.js +0 -30
  82. package/dist/helpers/match.js.map +0 -1
  83. package/dist/helpers/normalizePath.d.ts +0 -23
  84. package/dist/helpers/normalizePath.d.ts.map +0 -1
  85. package/dist/helpers/normalizePath.js +0 -37
  86. package/dist/helpers/normalizePath.js.map +0 -1
  87. package/dist/helpers/safeCall.d.ts +0 -7
  88. package/dist/helpers/safeCall.d.ts.map +0 -1
  89. package/dist/helpers/safeCall.js +0 -24
  90. package/dist/helpers/safeCall.js.map +0 -1
  91. package/dist/helpers/split.d.ts +0 -7
  92. package/dist/helpers/split.d.ts.map +0 -1
  93. package/dist/helpers/split.js +0 -25
  94. package/dist/helpers/split.js.map +0 -1
  95. package/dist/helpers/stripBOM.d.ts +0 -7
  96. package/dist/helpers/stripBOM.d.ts.map +0 -1
  97. package/dist/helpers/stripBOM.js +0 -19
  98. package/dist/helpers/stripBOM.js.map +0 -1
  99. package/dist/helpers/stripComments.d.ts.map +0 -1
  100. package/dist/helpers/stripComments.js +0 -147
  101. package/dist/helpers/stripComments.js.map +0 -1
  102. package/dist/homedir.d.ts +0 -7
  103. package/dist/homedir.d.ts.map +0 -1
  104. package/dist/homedir.js +0 -32
  105. package/dist/homedir.js.map +0 -1
  106. package/dist/includePaths.d.ts +0 -7
  107. package/dist/includePaths.d.ts.map +0 -1
  108. package/dist/includePaths.js +0 -54
  109. package/dist/includePaths.js.map +0 -1
  110. package/dist/index.d.ts.map +0 -1
  111. package/dist/index.js.map +0 -1
  112. package/dist/indir.d.ts +0 -14
  113. package/dist/indir.d.ts.map +0 -1
  114. package/dist/indir.js +0 -27
  115. package/dist/indir.js.map +0 -1
  116. package/dist/isAbsolutePath.d.ts +0 -7
  117. package/dist/isAbsolutePath.d.ts.map +0 -1
  118. package/dist/isAbsolutePath.js +0 -25
  119. package/dist/isAbsolutePath.js.map +0 -1
  120. package/dist/isDirectory.d.ts +0 -13
  121. package/dist/isDirectory.d.ts.map +0 -1
  122. package/dist/isDirectory.js +0 -27
  123. package/dist/isDirectory.js.map +0 -1
  124. package/dist/isRelativePath.d.ts +0 -7
  125. package/dist/isRelativePath.d.ts.map +0 -1
  126. package/dist/isRelativePath.js +0 -45
  127. package/dist/isRelativePath.js.map +0 -1
  128. package/dist/json.d.ts +0 -22
  129. package/dist/json.d.ts.map +0 -1
  130. package/dist/json.js +0 -35
  131. package/dist/json.js.map +0 -1
  132. package/dist/jsonc.d.ts.map +0 -1
  133. package/dist/jsonc.js.map +0 -1
  134. package/dist/lstat.d.ts +0 -23
  135. package/dist/lstat.d.ts.map +0 -1
  136. package/dist/lstat.js +0 -31
  137. package/dist/lstat.js.map +0 -1
  138. package/dist/mapdir.d.ts +0 -23
  139. package/dist/mapdir.d.ts.map +0 -1
  140. package/dist/mapdir.js +0 -43
  141. package/dist/mapdir.js.map +0 -1
  142. package/dist/mkdir.d.ts +0 -7
  143. package/dist/mkdir.d.ts.map +0 -1
  144. package/dist/mkdir.js +0 -38
  145. package/dist/mkdir.js.map +0 -1
  146. package/dist/parseJSON.d.ts +0 -16
  147. package/dist/parseJSON.d.ts.map +0 -1
  148. package/dist/parseJSON.js +0 -29
  149. package/dist/parseJSON.js.map +0 -1
  150. package/dist/readFile.d.ts.map +0 -1
  151. package/dist/readFile.js.map +0 -1
  152. package/dist/readStream.d.ts +0 -37
  153. package/dist/readStream.d.ts.map +0 -1
  154. package/dist/readStream.js +0 -20
  155. package/dist/readStream.js.map +0 -1
  156. package/dist/readdir.d.ts +0 -17
  157. package/dist/readdir.d.ts.map +0 -1
  158. package/dist/readdir.js +0 -35
  159. package/dist/readdir.js.map +0 -1
  160. package/dist/readline.d.ts +0 -17
  161. package/dist/readline.d.ts.map +0 -1
  162. package/dist/readline.js +0 -25
  163. package/dist/readline.js.map +0 -1
  164. package/dist/realpath.d.ts +0 -13
  165. package/dist/realpath.d.ts.map +0 -1
  166. package/dist/realpath.js +0 -33
  167. package/dist/realpath.js.map +0 -1
  168. package/dist/relative.d.ts.map +0 -1
  169. package/dist/relative.js.map +0 -1
  170. package/dist/resolve.d.ts +0 -27
  171. package/dist/resolve.d.ts.map +0 -1
  172. package/dist/resolve.js +0 -54
  173. package/dist/resolve.js.map +0 -1
  174. package/dist/resolvePath.d.ts +0 -27
  175. package/dist/resolvePath.d.ts.map +0 -1
  176. package/dist/resolvePath.js +0 -178
  177. package/dist/resolvePath.js.map +0 -1
  178. package/dist/rmdir.d.ts +0 -7
  179. package/dist/rmdir.d.ts.map +0 -1
  180. package/dist/rmdir.js +0 -41
  181. package/dist/rmdir.js.map +0 -1
  182. package/dist/stat.d.ts.map +0 -1
  183. package/dist/stat.js.map +0 -1
  184. package/dist/supdir.d.ts +0 -22
  185. package/dist/supdir.d.ts.map +0 -1
  186. package/dist/supdir.js +0 -63
  187. package/dist/supdir.js.map +0 -1
  188. package/dist/symlink.d.ts +0 -23
  189. package/dist/symlink.d.ts.map +0 -1
  190. package/dist/symlink.js +0 -40
  191. package/dist/symlink.js.map +0 -1
  192. package/dist/unlink.d.ts +0 -7
  193. package/dist/unlink.d.ts.map +0 -1
  194. package/dist/unlink.js +0 -29
  195. package/dist/unlink.js.map +0 -1
  196. package/dist/usedir.d.ts +0 -7
  197. package/dist/usedir.d.ts.map +0 -1
  198. package/dist/usedir.js +0 -25
  199. package/dist/usedir.js.map +0 -1
  200. package/dist/writeFile.d.ts +0 -34
  201. package/dist/writeFile.d.ts.map +0 -1
  202. package/dist/writeFile.js +0 -50
  203. package/dist/writeFile.js.map +0 -1
  204. package/dist/writeStream.d.ts +0 -36
  205. package/dist/writeStream.d.ts.map +0 -1
  206. package/dist/writeStream.js +0 -20
  207. package/dist/writeStream.js.map +0 -1
  208. package/src/basename.ts +0 -15
  209. package/src/copy.ts +0 -141
  210. package/src/cpdir.ts +0 -47
  211. package/src/cwd.ts +0 -15
  212. package/src/dirname.ts +0 -34
  213. package/src/extname.ts +0 -15
  214. package/src/filename.ts +0 -25
  215. package/src/find.ts +0 -106
  216. package/src/findFile.ts +0 -61
  217. package/src/finddir.ts +0 -61
  218. package/src/helpers/FileResolver.ts +0 -282
  219. package/src/helpers/compose.ts +0 -49
  220. package/src/helpers/each.ts +0 -19
  221. package/src/helpers/match.ts +0 -31
  222. package/src/helpers/normalizePath.ts +0 -51
  223. package/src/helpers/safeCall.ts +0 -21
  224. package/src/helpers/split.ts +0 -25
  225. package/src/helpers/stripBOM.ts +0 -17
  226. package/src/helpers/stripComments.ts +0 -173
  227. package/src/homedir.ts +0 -34
  228. package/src/includePaths.ts +0 -62
  229. package/src/index.ts +0 -52
  230. package/src/indir.ts +0 -45
  231. package/src/isAbsolutePath.ts +0 -25
  232. package/src/isDirectory.ts +0 -28
  233. package/src/isRelativePath.ts +0 -52
  234. package/src/json.ts +0 -62
  235. package/src/jsonc.ts +0 -81
  236. package/src/lstat.ts +0 -40
  237. package/src/mapdir.ts +0 -59
  238. package/src/mkdir.ts +0 -43
  239. package/src/parseJSON.ts +0 -40
  240. package/src/readFile.ts +0 -64
  241. package/src/readStream.ts +0 -53
  242. package/src/readdir.ts +0 -51
  243. package/src/readline.ts +0 -42
  244. package/src/realpath.ts +0 -35
  245. package/src/relative.ts +0 -43
  246. package/src/resolve.ts +0 -83
  247. package/src/resolvePath.ts +0 -234
  248. package/src/rmdir.ts +0 -44
  249. package/src/stat.ts +0 -40
  250. package/src/supdir.ts +0 -79
  251. package/src/symlink.ts +0 -67
  252. package/src/unlink.ts +0 -31
  253. package/src/usedir.ts +0 -25
  254. package/src/writeFile.ts +0 -86
  255. package/src/writeStream.ts +0 -52
@@ -1,62 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-25 22:34:41
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { resolve, sep } from 'path';
16
- import { isAbsolutePath } from './isAbsolutePath';
17
- import { isRelativePath } from './isRelativePath';
18
-
19
-
20
- /**
21
- *****************************************
22
- * 解析路径别名
23
- *****************************************
24
- */
25
- export function includePaths(paths: string[]): (source: string) => boolean {
26
- const rules = paths.map(value => {
27
-
28
- // 处理相对路径
29
- if (isRelativePath(value)) {
30
- value = resolve(value);
31
- }
32
-
33
- // 处理组对目录
34
- if (isAbsolutePath(value)) {
35
- const prefix = value + sep;
36
-
37
- // 添加匹配规则
38
- return (source: string) => source === value || source.startsWith(prefix);
39
- }
40
-
41
- // 切分路径分段
42
- const chunks = value.split('/');
43
-
44
- // 生成匹配函数
45
- return (source: string) => {
46
- const list = source.split(sep);
47
-
48
- // 匹配是否包含路径
49
- for (let idx = 0, len = list.length - chunks.length + 1; idx < len; idx ++) {
50
- if (chunks.every((chunk, offset) => chunk === list[idx + offset])) {
51
- return true;
52
- }
53
- }
54
-
55
- // 匹配失败
56
- return false;
57
- };
58
- });
59
-
60
- // 返回匹配函数
61
- return (source: string) => rules.some(rule => rule(source));
62
- }
package/src/index.ts DELETED
@@ -1,52 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 15:59:39
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 抛出模块
13
- *****************************************
14
- */
15
- export { homedir } from './homedir';
16
- export { cwd } from './cwd';
17
- export { realpath } from './realpath';
18
- export { dirname } from './dirname';
19
- export { filename } from './filename';
20
- export { basename } from './basename';
21
- export { extname } from './extname';
22
- export { stat } from './stat';
23
- export { lstat } from './lstat';
24
- export { isDirectory } from './isDirectory';
25
- export { indir } from './indir';
26
- export { json } from './json';
27
- export { jsonc } from './jsonc';
28
- export { parseJSON } from './parseJSON';
29
- export { copy } from './copy';
30
- export { cpdir } from './cpdir';
31
- export { find } from './find';
32
- export { readFile } from './readFile';
33
- export { readline } from './readline';
34
- export { readStream } from './readStream';
35
- export { writeFile } from './writeFile';
36
- export { writeStream } from './writeStream';
37
- export { findFile } from './findFile';
38
- export { resolve } from './resolve';
39
- export { relative } from './relative';
40
- export { unlink } from './unlink';
41
- export { readdir } from './readdir';
42
- export { mkdir } from './mkdir';
43
- export { finddir } from './finddir';
44
- export { rmdir } from './rmdir';
45
- export { mapdir } from './mapdir';
46
- export { symlink } from './symlink';
47
- export { usedir } from './usedir';
48
- export { supdir } from './supdir';
49
- export { resolvePath } from './resolvePath';
50
- export { includePaths } from './includePaths';
51
- export { isAbsolutePath } from './isAbsolutePath';
52
- export { isRelativePath } from './isRelativePath';
package/src/indir.ts DELETED
@@ -1,45 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-03-20 22:17:38
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as path from 'path';
16
-
17
-
18
- /**
19
- *****************************************
20
- * 判断是否在目录内
21
- *****************************************
22
- */
23
- function indir(dir: string): (file: string) => boolean;
24
- function indir(dir: string, file: string): boolean;
25
- function indir(dir: string, file?: string): boolean | ((file: string) => boolean) {
26
-
27
- // 解析目录
28
- dir = path.resolve(dir) + path.sep;
29
-
30
- // 匹配文件
31
- if (typeof file === 'string') {
32
- return path.resolve(file).startsWith(dir);
33
- }
34
-
35
- // 返回匹配函数
36
- return (file: string) => path.resolve(file).startsWith(dir);
37
- }
38
-
39
-
40
- /**
41
- *****************************************
42
- * 抛出接口
43
- *****************************************
44
- */
45
- export { indir };
@@ -1,25 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-25 22:23:32
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as path from 'path';
16
-
17
-
18
- /**
19
- *****************************************
20
- * 判断是否为绝对路径
21
- *****************************************
22
- */
23
- export function isAbsolutePath(source: string): boolean {
24
- return path.isAbsolute(source);
25
- }
@@ -1,28 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:15:04
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { stat } from './stat';
16
-
17
-
18
- /**
19
- *****************************************
20
- * 判断是否为文件夹
21
- *****************************************
22
- */
23
- export function isDirectory(dir: string): ReturnType<typeof stat> {
24
- const stats = stat(dir);
25
-
26
- // 返回状态判断
27
- return stats && stats.isDirectory() ? stats : null;
28
- }
@@ -1,52 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-25 22:23:32
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { sep } from 'path';
16
-
17
-
18
- /**
19
- *****************************************
20
- * 判断是否为路径分隔符
21
- *****************************************
22
- */
23
- function isSep(ch: string): boolean {
24
-
25
- // 模块相对标识
26
- if (ch === '/' || ch === '') {
27
- return true;
28
- }
29
-
30
- // 路径相对标识
31
- return ch === sep;
32
- }
33
-
34
-
35
- /**
36
- *****************************************
37
- * 判断是否为相对路径
38
- *****************************************
39
- */
40
- export function isRelativePath(source: string): boolean {
41
-
42
- // 非相对标识
43
- if (source.charAt(0) !== '.') {
44
- return false;
45
- }
46
-
47
- // 位1字符
48
- const ch1 = source.charAt(1);
49
-
50
- // 非相对路径
51
- return ch1 === '.' ? isSep(source.charAt(2)) : isSep(ch1);
52
- }
package/src/json.ts DELETED
@@ -1,62 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 21:27:52
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { stat } from './stat';
16
- import { readFile } from './readFile';
17
- import { writeFile } from './writeFile';
18
- import { stripBOM } from './helpers/stripBOM';
19
-
20
-
21
- /**
22
- *****************************************
23
- * 数据接口
24
- *****************************************
25
- */
26
- interface Data {
27
- [key: string]: unknown;
28
- }
29
-
30
-
31
- /**
32
- *****************************************
33
- * 读取/写入【json】文件
34
- *****************************************
35
- */
36
- function json<T = Data>(path: string): T | null;
37
- function json<T = Data>(path: string, data: T): T;
38
- function json<T = Data>(...args: [string] | [string, T]): T | null {
39
- const [name, data] = args;
40
-
41
- // 读写数据
42
- if (args.length > 1) {
43
- writeFile(name, JSON.stringify(data));
44
- } else {
45
- const stats = stat(name);
46
-
47
- if (stats && stats.isFile()) {
48
- return JSON.parse(stripBOM(readFile(stats.path)));
49
- }
50
- }
51
-
52
- // 返回数据
53
- return data || null;
54
- }
55
-
56
-
57
- /**
58
- *****************************************
59
- * 抛出接口
60
- *****************************************
61
- */
62
- export { json };
package/src/jsonc.ts DELETED
@@ -1,81 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 21:27:52
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { stat } from './stat';
16
- import { readFile } from './readFile';
17
- import { writeFile } from './writeFile';
18
- import { stripComments } from './helpers/stripComments';
19
-
20
-
21
- /**
22
- *****************************************
23
- * 数据接口
24
- *****************************************
25
- */
26
- interface Data {
27
- [key: string]: unknown;
28
- }
29
-
30
-
31
- /**
32
- *****************************************
33
- * 解析内容
34
- *****************************************
35
- */
36
- function parse<T = Data>(content: string): T | null {
37
-
38
- // 格式化内容
39
- content = stripComments(content);
40
-
41
- // 打印输出
42
- // console.log(content);
43
-
44
- // 解析文件
45
- return content ? JSON.parse(content) : null;
46
- }
47
-
48
-
49
- /**
50
- *****************************************
51
- * 读取/写入【jsonc】文件
52
- *****************************************
53
- */
54
- function jsonc<T = Data>(path: string): T | null;
55
- function jsonc<T = Data>(path: string, data: T): T;
56
- function jsonc<T = Data>(...args: [string] | [string, T]): T | null {
57
- const [name, data] = args;
58
-
59
- // 读写数据
60
- if (args.length > 1) {
61
- writeFile(name, JSON.stringify(data));
62
- } else {
63
- const stats = stat(name);
64
-
65
- // 解析文件
66
- if (stats && stats.isFile()) {
67
- return parse(readFile(stats.path));
68
- }
69
- }
70
-
71
- // 返回数据
72
- return data || null;
73
- }
74
-
75
-
76
- /**
77
- *****************************************
78
- * 抛出接口
79
- *****************************************
80
- */
81
- export { jsonc, parse };
package/src/lstat.ts DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:06:57
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as fs from 'fs';
16
- import * as path from 'path';
17
-
18
-
19
- /**
20
- *****************************************
21
- * 状态
22
- *****************************************
23
- */
24
- interface State extends fs.Stats {
25
- path: string;
26
- }
27
-
28
-
29
- /**
30
- *****************************************
31
- * 获取文件状态
32
- *****************************************
33
- */
34
- export function lstat(dir: string): State | null {
35
- try {
36
- return Object.assign(fs.lstatSync(dir), { path: path.resolve(dir) });
37
- } catch (err) {
38
- return null;
39
- }
40
- }
package/src/mapdir.ts DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-09 16:35:57
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as fs from 'fs';
16
- import * as path from 'path';
17
- import { stat } from './stat';
18
-
19
-
20
- /**
21
- *****************************************
22
- * 遍历回调
23
- *****************************************
24
- */
25
- interface Handler<T> {
26
- (path: string, stats: fs.Stats): T;
27
- }
28
-
29
-
30
- /**
31
- *****************************************
32
- * 遍历目录
33
- *****************************************
34
- */
35
- export function mapdir<T>(dir: string, handler: Handler<T>): T[] {
36
- let stats = stat(dir),
37
- result: T[] = [];
38
-
39
- // 存在目录
40
- if (stats) {
41
- let dirname = stats.path,
42
- ignore = ['node_modules', '.DS_Store'];
43
-
44
- // 遍历子文件
45
- if (stats.isDirectory()) {
46
- fs.readdirSync(stats.path).forEach(name => {
47
- if (!ignore.includes(name)) {
48
- result.push(...mapdir(path.join(dirname, name), handler));
49
- }
50
- });
51
- }
52
-
53
- // 执行回调
54
- result.push(handler(dirname, stats));
55
- }
56
-
57
- // 返回结果
58
- return result;
59
- }
package/src/mkdir.ts DELETED
@@ -1,43 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:48:57
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as fs from 'fs';
16
- import * as path from 'path';
17
- import { isDirectory } from './isDirectory';
18
- import { dirname } from './dirname';
19
-
20
-
21
- /**
22
- *****************************************
23
- * 创建目录
24
- *****************************************
25
- */
26
- export function mkdir(dir: string): string {
27
-
28
- // 解析目录
29
- dir = path.resolve(dir);
30
-
31
- // 创建目录
32
- if (!isDirectory(dir)) {
33
-
34
- // 创建上级目录
35
- mkdir(dirname(dir));
36
-
37
- // 创建目录
38
- fs.mkdirSync(dir);
39
- }
40
-
41
- // 返回目录
42
- return dir;
43
- }
package/src/parseJSON.ts DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2022-01-01 21:01:19
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { stripBOM } from './helpers/stripBOM';
16
- import { stripComments } from './helpers/stripComments';
17
-
18
-
19
- /**
20
- *****************************************
21
- * 选项
22
- *****************************************
23
- */
24
- interface Options {
25
- comments?: boolean;
26
- }
27
-
28
-
29
- /**
30
- *****************************************
31
- * 解析【JSON】文件
32
- *****************************************
33
- */
34
- export function parseJSON<T>(content: string, options: Options = {}): T {
35
- const normalized = options.comments ? stripComments(content) : stripBOM(content);
36
- const source = normalized.trim();
37
-
38
- // 解析内容
39
- return source ? JSON.parse(source) : undefined;
40
- }
package/src/readFile.ts DELETED
@@ -1,64 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:27:01
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as fs from 'fs';
16
- import { stat } from './stat';
17
-
18
-
19
- /**
20
- *****************************************
21
- * 编码类型
22
- *****************************************
23
- */
24
- type Encoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex';
25
-
26
-
27
- /**
28
- *****************************************
29
- * 配置
30
- *****************************************
31
- */
32
- interface Options {
33
- encoding?: Encoding;
34
- flag?: string;
35
- }
36
-
37
-
38
- /**
39
- *****************************************
40
- * 读取文件
41
- *****************************************
42
- */
43
- function readFile(path: string): string;
44
- function readFile(path: string, encoding: Encoding): string;
45
- function readFile(path: string, options: Options): string;
46
- function readFile(path: string, encoding?: Encoding | Options): string {
47
- let stats = stat(path);
48
-
49
- // 存在文件
50
- if (stats && !stats.isDirectory()) {
51
- return fs.readFileSync(path, encoding as Encoding || 'utf8');
52
- }
53
-
54
- // 返回空
55
- return '';
56
- }
57
-
58
-
59
- /**
60
- *****************************************
61
- *
62
- *****************************************
63
- */
64
- export { readFile };