@ainc/fs 0.1.10 → 0.1.14

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 (175) hide show
  1. package/README.md +2 -0
  2. package/dist/basename.d.ts +6 -6
  3. package/dist/basename.js +16 -16
  4. package/dist/copy.d.ts +40 -40
  5. package/dist/copy.d.ts.map +1 -1
  6. package/dist/copy.js +89 -86
  7. package/dist/copy.js.map +1 -1
  8. package/dist/cpdir.d.ts +19 -19
  9. package/dist/cpdir.js +28 -28
  10. package/dist/cwd.d.ts +6 -6
  11. package/dist/cwd.js +16 -16
  12. package/dist/dirname.d.ts +6 -6
  13. package/dist/dirname.js +30 -30
  14. package/dist/extname.d.ts +6 -6
  15. package/dist/extname.js +16 -16
  16. package/dist/filename.d.ts +6 -6
  17. package/dist/filename.js +24 -24
  18. package/dist/find.d.ts +26 -26
  19. package/dist/find.d.ts.map +1 -1
  20. package/dist/find.js +72 -68
  21. package/dist/find.js.map +1 -1
  22. package/dist/findFile.d.ts +20 -20
  23. package/dist/findFile.d.ts.map +1 -1
  24. package/dist/findFile.js +39 -39
  25. package/dist/findFile.js.map +1 -1
  26. package/dist/finddir.d.ts +20 -20
  27. package/dist/finddir.d.ts.map +1 -1
  28. package/dist/finddir.js +39 -39
  29. package/dist/finddir.js.map +1 -1
  30. package/dist/helpers/FileResolver.d.ts +54 -0
  31. package/dist/helpers/FileResolver.d.ts.map +1 -0
  32. package/dist/helpers/FileResolver.js +184 -0
  33. package/dist/helpers/FileResolver.js.map +1 -0
  34. package/dist/helpers/compose.d.ts +14 -0
  35. package/dist/helpers/compose.d.ts.map +1 -0
  36. package/dist/helpers/compose.js +38 -0
  37. package/dist/helpers/compose.js.map +1 -0
  38. package/dist/helpers/each.d.ts +7 -0
  39. package/dist/helpers/each.d.ts.map +1 -0
  40. package/dist/helpers/each.js +21 -0
  41. package/dist/helpers/each.js.map +1 -0
  42. package/dist/helpers/match.d.ts +7 -0
  43. package/dist/helpers/match.d.ts.map +1 -0
  44. package/dist/helpers/match.js +30 -0
  45. package/dist/helpers/match.js.map +1 -0
  46. package/dist/helpers/normalizePath.d.ts +23 -0
  47. package/dist/helpers/normalizePath.d.ts.map +1 -0
  48. package/dist/helpers/normalizePath.js +37 -0
  49. package/dist/helpers/normalizePath.js.map +1 -0
  50. package/dist/helpers/safeCall.d.ts +7 -0
  51. package/dist/helpers/safeCall.d.ts.map +1 -0
  52. package/dist/helpers/safeCall.js +24 -0
  53. package/dist/helpers/safeCall.js.map +1 -0
  54. package/dist/helpers/split.d.ts +7 -0
  55. package/dist/helpers/split.d.ts.map +1 -0
  56. package/dist/helpers/split.js +25 -0
  57. package/dist/helpers/split.js.map +1 -0
  58. package/dist/homedir.d.ts +6 -6
  59. package/dist/homedir.js +31 -31
  60. package/dist/includePaths.d.ts +6 -6
  61. package/dist/includePaths.js +53 -53
  62. package/dist/index.d.ts +42 -41
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +88 -86
  65. package/dist/index.js.map +1 -1
  66. package/dist/indir.d.ts +13 -13
  67. package/dist/indir.js +26 -26
  68. package/dist/isAbsolutePath.d.ts +6 -6
  69. package/dist/isAbsolutePath.js +24 -24
  70. package/dist/isDirectory.d.ts +12 -12
  71. package/dist/isDirectory.js +26 -26
  72. package/dist/isRelativePath.d.ts +6 -6
  73. package/dist/isRelativePath.d.ts.map +1 -1
  74. package/dist/isRelativePath.js +44 -18
  75. package/dist/isRelativePath.js.map +1 -1
  76. package/dist/json.d.ts +21 -21
  77. package/dist/json.js +33 -33
  78. package/dist/jsonc.d.ts +21 -21
  79. package/dist/jsonc.d.ts.map +1 -1
  80. package/dist/jsonc.js +40 -41
  81. package/dist/jsonc.js.map +1 -1
  82. package/dist/lstat.d.ts +22 -22
  83. package/dist/lstat.js +30 -30
  84. package/dist/mapdir.d.ts +22 -22
  85. package/dist/mapdir.js +42 -42
  86. package/dist/mkdir.d.ts +6 -6
  87. package/dist/mkdir.js +37 -37
  88. package/dist/normalizeJSON.d.ts +7 -0
  89. package/dist/normalizeJSON.d.ts.map +1 -0
  90. package/dist/normalizeJSON.js +145 -0
  91. package/dist/normalizeJSON.js.map +1 -0
  92. package/dist/readFile.d.ts +29 -29
  93. package/dist/readFile.js +26 -26
  94. package/dist/readStream.d.ts +36 -36
  95. package/dist/readStream.js +19 -19
  96. package/dist/readdir.d.ts +16 -16
  97. package/dist/readdir.js +34 -34
  98. package/dist/readline.d.ts +16 -16
  99. package/dist/readline.js +24 -24
  100. package/dist/realpath.d.ts +13 -0
  101. package/dist/realpath.d.ts.map +1 -0
  102. package/dist/realpath.js +33 -0
  103. package/dist/realpath.js.map +1 -0
  104. package/dist/relative.d.ts +6 -6
  105. package/dist/relative.js +38 -38
  106. package/dist/relative.js.map +1 -1
  107. package/dist/resolve.d.ts +26 -25
  108. package/dist/resolve.d.ts.map +1 -1
  109. package/dist/resolve.js +53 -53
  110. package/dist/resolve.js.map +1 -1
  111. package/dist/resolvePath.d.ts +27 -0
  112. package/dist/resolvePath.d.ts.map +1 -0
  113. package/dist/resolvePath.js +178 -0
  114. package/dist/resolvePath.js.map +1 -0
  115. package/dist/rmdir.d.ts +6 -6
  116. package/dist/rmdir.js +40 -40
  117. package/dist/stat.d.ts +21 -22
  118. package/dist/stat.d.ts.map +1 -1
  119. package/dist/stat.js +30 -30
  120. package/dist/supdir.d.ts +21 -15
  121. package/dist/supdir.d.ts.map +1 -1
  122. package/dist/supdir.js +62 -35
  123. package/dist/supdir.js.map +1 -1
  124. package/dist/symlink.d.ts +22 -22
  125. package/dist/symlink.js +39 -39
  126. package/dist/unlink.d.ts +6 -6
  127. package/dist/unlink.js +28 -28
  128. package/dist/usedir.d.ts +6 -6
  129. package/dist/usedir.js +24 -24
  130. package/dist/writeFile.d.ts +33 -27
  131. package/dist/writeFile.d.ts.map +1 -1
  132. package/dist/writeFile.js +49 -46
  133. package/dist/writeFile.js.map +1 -1
  134. package/dist/writeStream.d.ts +35 -35
  135. package/dist/writeStream.js +19 -19
  136. package/package.json +7 -7
  137. package/src/copy.ts +10 -4
  138. package/src/find.ts +16 -12
  139. package/src/findFile.ts +1 -1
  140. package/src/finddir.ts +1 -1
  141. package/src/helpers/FileResolver.ts +282 -0
  142. package/src/helpers/compose.ts +49 -0
  143. package/src/helpers/each.ts +19 -0
  144. package/src/helpers/match.ts +31 -0
  145. package/src/helpers/normalizePath.ts +51 -0
  146. package/src/helpers/safeCall.ts +21 -0
  147. package/src/helpers/split.ts +25 -0
  148. package/src/{stripBOM.ts → helpers/stripBOM.ts} +3 -10
  149. package/src/helpers/stripComments.ts +167 -0
  150. package/src/index.ts +3 -1
  151. package/src/isRelativePath.ts +36 -1
  152. package/src/json.ts +2 -1
  153. package/src/jsonc.ts +2 -3
  154. package/src/parseJSON.ts +40 -0
  155. package/src/realpath.ts +35 -0
  156. package/src/relative.ts +1 -1
  157. package/src/resolve.ts +2 -1
  158. package/src/resolvePath.ts +234 -0
  159. package/src/stat.ts +1 -1
  160. package/src/supdir.ts +31 -0
  161. package/src/writeFile.ts +11 -8
  162. package/dist/resolveAlias.d.ts +0 -21
  163. package/dist/resolveAlias.d.ts.map +0 -1
  164. package/dist/resolveAlias.js +0 -108
  165. package/dist/resolveAlias.js.map +0 -1
  166. package/dist/stripBOM.d.ts +0 -7
  167. package/dist/stripBOM.d.ts.map +0 -1
  168. package/dist/stripBOM.js +0 -24
  169. package/dist/stripBOM.js.map +0 -1
  170. package/dist/stripComments.d.ts +0 -7
  171. package/dist/stripComments.d.ts.map +0 -1
  172. package/dist/stripComments.js +0 -100
  173. package/dist/stripComments.js.map +0 -1
  174. package/src/resolveAlias.ts +0 -153
  175. package/src/stripComments.ts +0 -112
@@ -1,27 +1,27 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:15:04
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.isDirectory = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const stat_1 = require("./stat");
16
- /**
17
- *****************************************
18
- * 判断是否为文件夹
19
- *****************************************
20
- */
21
- function isDirectory(dir) {
22
- const stats = stat_1.stat(dir);
23
- // 返回状态判断
24
- return stats && stats.isDirectory() ? stats : null;
25
- }
26
- exports.isDirectory = isDirectory;
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2019-11-07 16:15:04
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isDirectory = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const stat_1 = require("./stat");
16
+ /**
17
+ *****************************************
18
+ * 判断是否为文件夹
19
+ *****************************************
20
+ */
21
+ function isDirectory(dir) {
22
+ const stats = stat_1.stat(dir);
23
+ // 返回状态判断
24
+ return stats && stats.isDirectory() ? stats : null;
25
+ }
26
+ exports.isDirectory = isDirectory;
27
27
  //# sourceMappingURL=isDirectory.js.map
@@ -1,7 +1,7 @@
1
- /**
2
- *****************************************
3
- * 判断是否为相对路径
4
- *****************************************
5
- */
6
- export declare function isRelativePath(source: string): boolean;
1
+ /**
2
+ *****************************************
3
+ * 判断是否为相对路径
4
+ *****************************************
5
+ */
6
+ export declare function isRelativePath(source: string): boolean;
7
7
  //# sourceMappingURL=isRelativePath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isRelativePath.d.ts","sourceRoot":"","sources":["../src/isRelativePath.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD"}
1
+ {"version":3,"file":"isRelativePath.d.ts","sourceRoot":"","sources":["../src/isRelativePath.ts"],"names":[],"mappings":"AAkCA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAYtD"}
@@ -1,19 +1,45 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-25 22:23:32
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.isRelativePath = void 0;
10
- /**
11
- *****************************************
12
- * 判断是否为相对路径
13
- *****************************************
14
- */
15
- function isRelativePath(source) {
16
- return source.startsWith('./') || source.startsWith('../');
17
- }
18
- exports.isRelativePath = isRelativePath;
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2021-05-25 22:23:32
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isRelativePath = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const path_1 = require("path");
16
+ /**
17
+ *****************************************
18
+ * 判断是否为路径分隔符
19
+ *****************************************
20
+ */
21
+ function isSep(ch) {
22
+ // 模块相对标识
23
+ if (ch === '/' || ch === '') {
24
+ return true;
25
+ }
26
+ // 路径相对标识
27
+ return ch === path_1.sep;
28
+ }
29
+ /**
30
+ *****************************************
31
+ * 判断是否为相对路径
32
+ *****************************************
33
+ */
34
+ function isRelativePath(source) {
35
+ // 非相对标识
36
+ if (source.charAt(0) !== '.') {
37
+ return false;
38
+ }
39
+ // 位1字符
40
+ const ch1 = source.charAt(1);
41
+ // 非相对路径
42
+ return ch1 === '.' ? isSep(source.charAt(2)) : isSep(ch1);
43
+ }
44
+ exports.isRelativePath = isRelativePath;
19
45
  //# sourceMappingURL=isRelativePath.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isRelativePath.js","sourceRoot":"","sources":["../src/isRelativePath.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,SAAgB,cAAc,CAAC,MAAc;IACzC,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAFD,wCAEC"}
1
+ {"version":3,"file":"isRelativePath.js","sourceRoot":"","sources":["../src/isRelativePath.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,+BAA2B;AAG3B;;;;GAIG;AACH,SAAS,KAAK,CAAC,EAAU;IAErB,SAAS;IACT,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE;QACzB,OAAO,IAAI,CAAC;KACf;IAED,SAAS;IACT,OAAO,EAAE,KAAK,UAAG,CAAC;AACtB,CAAC;AAGD;;;;GAIG;AACH,SAAgB,cAAc,CAAC,MAAc;IAEzC,QAAQ;IACR,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QAC1B,OAAO,KAAK,CAAC;KAChB;IAED,OAAO;IACP,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE7B,QAAQ;IACR,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC9D,CAAC;AAZD,wCAYC"}
package/dist/json.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- /**
2
- *****************************************
3
- * 数据接口
4
- *****************************************
5
- */
6
- interface Data {
7
- [key: string]: unknown;
8
- }
9
- /**
10
- *****************************************
11
- * 读取/写入【json】文件
12
- *****************************************
13
- */
14
- declare function json<T = Data>(path: string): T | null;
15
- declare function json<T = Data>(path: string, data: T): T;
16
- /**
17
- *****************************************
18
- * 抛出接口
19
- *****************************************
20
- */
21
- export { json };
1
+ /**
2
+ *****************************************
3
+ * 数据接口
4
+ *****************************************
5
+ */
6
+ interface Data {
7
+ [key: string]: unknown;
8
+ }
9
+ /**
10
+ *****************************************
11
+ * 读取/写入【json】文件
12
+ *****************************************
13
+ */
14
+ declare function json<T = Data>(path: string): T | null;
15
+ declare function json<T = Data>(path: string, data: T): T;
16
+ /**
17
+ *****************************************
18
+ * 抛出接口
19
+ *****************************************
20
+ */
21
+ export { json };
22
22
  //# sourceMappingURL=json.d.ts.map
package/dist/json.js CHANGED
@@ -1,34 +1,34 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 21:27:52
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.json = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const stat_1 = require("./stat");
16
- const readFile_1 = require("./readFile");
17
- const writeFile_1 = require("./writeFile");
18
- function json(...args) {
19
- const [name, data] = args;
20
- // 读写数据
21
- if (args.length > 1) {
22
- writeFile_1.writeFile(name, JSON.stringify(data));
23
- }
24
- else {
25
- const stats = stat_1.stat(name);
26
- if (stats && stats.isFile()) {
27
- return JSON.parse(readFile_1.readFile(stats.path));
28
- }
29
- }
30
- // 返回数据
31
- return data || null;
32
- }
33
- exports.json = json;
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2019-11-07 21:27:52
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.json = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const stat_1 = require("./stat");
16
+ const readFile_1 = require("./readFile");
17
+ const writeFile_1 = require("./writeFile");
18
+ function json(...args) {
19
+ const [name, data] = args;
20
+ // 读写数据
21
+ if (args.length > 1) {
22
+ writeFile_1.writeFile(name, JSON.stringify(data));
23
+ }
24
+ else {
25
+ const stats = stat_1.stat(name);
26
+ if (stats && stats.isFile()) {
27
+ return JSON.parse(readFile_1.readFile(stats.path));
28
+ }
29
+ }
30
+ // 返回数据
31
+ return data || null;
32
+ }
33
+ exports.json = json;
34
34
  //# sourceMappingURL=json.js.map
package/dist/jsonc.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- /**
2
- *****************************************
3
- * 数据接口
4
- *****************************************
5
- */
6
- interface Data {
7
- [key: string]: unknown;
8
- }
9
- /**
10
- *****************************************
11
- * 读取/写入【jsonc】文件
12
- *****************************************
13
- */
14
- declare function jsonc<T = Data>(path: string): T | null;
15
- declare function jsonc<T = Data>(path: string, data: T): T;
16
- /**
17
- *****************************************
18
- * 抛出接口
19
- *****************************************
20
- */
21
- export { jsonc };
1
+ /**
2
+ *****************************************
3
+ * 数据接口
4
+ *****************************************
5
+ */
6
+ interface Data {
7
+ [key: string]: unknown;
8
+ }
9
+ /**
10
+ *****************************************
11
+ * 读取/写入【jsonc】文件
12
+ *****************************************
13
+ */
14
+ declare function jsonc<T = Data>(path: string): T | null;
15
+ declare function jsonc<T = Data>(path: string, data: T): T;
16
+ /**
17
+ *****************************************
18
+ * 抛出接口
19
+ *****************************************
20
+ */
21
+ export { jsonc };
22
22
  //# sourceMappingURL=jsonc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonc.d.ts","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH,UAAU,IAAI;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAGD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC;AACjD,iBAAS,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;AA4BnD;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"jsonc.d.ts","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,UAAU,IAAI;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAGD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC;AACjD,iBAAS,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;AA4BnD;;;;GAIG;AACH,OAAO,EAAE,KAAK,EAAE,CAAC"}
package/dist/jsonc.js CHANGED
@@ -1,42 +1,41 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 21:27:52
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.jsonc = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const stat_1 = require("./stat");
16
- const readFile_1 = require("./readFile");
17
- const writeFile_1 = require("./writeFile");
18
- const stripBOM_1 = require("./stripBOM");
19
- const stripComments_1 = require("./stripComments");
20
- function jsonc(...args) {
21
- const [name, data] = args;
22
- // 读写数据
23
- if (args.length > 1) {
24
- writeFile_1.writeFile(name, JSON.stringify(data));
25
- }
26
- else {
27
- const stats = stat_1.stat(name);
28
- if (stats && stats.isFile()) {
29
- const content = stripComments_1.stripComments(stripBOM_1.stripBOM(readFile_1.readFile(stats.path)));
30
- // 空白文件
31
- if (!content.trim()) {
32
- return null;
33
- }
34
- // 解析文件
35
- return JSON.parse(content);
36
- }
37
- }
38
- // 返回数据
39
- return data || null;
40
- }
41
- exports.jsonc = jsonc;
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2019-11-07 21:27:52
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.jsonc = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const stat_1 = require("./stat");
16
+ const readFile_1 = require("./readFile");
17
+ const writeFile_1 = require("./writeFile");
18
+ const normalizeJSON_1 = require("./normalizeJSON");
19
+ function jsonc(...args) {
20
+ const [name, data] = args;
21
+ // 读写数据
22
+ if (args.length > 1) {
23
+ writeFile_1.writeFile(name, JSON.stringify(data));
24
+ }
25
+ else {
26
+ const stats = stat_1.stat(name);
27
+ if (stats && stats.isFile()) {
28
+ const content = normalizeJSON_1.normalizeJSON(readFile_1.readFile(stats.path));
29
+ // 空白文件
30
+ if (!content.trim()) {
31
+ return null;
32
+ }
33
+ // 解析文件
34
+ return JSON.parse(content);
35
+ }
36
+ }
37
+ // 返回数据
38
+ return data || null;
39
+ }
40
+ exports.jsonc = jsonc;
42
41
  //# sourceMappingURL=jsonc.js.map
package/dist/jsonc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jsonc.js","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,iCAA8B;AAC9B,yCAAsC;AACtC,2CAAwC;AACxC,yCAAsC;AACtC,mDAAgD;AAoBhD,SAAS,KAAK,CAAW,GAAG,IAA4B;IACpD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAE1B,OAAO;IACP,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACjB,qBAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACzC;SAAM;QACH,MAAM,KAAK,GAAG,WAAI,CAAC,IAAI,CAAC,CAAC;QAEzB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE;YACzB,MAAM,OAAO,GAAG,6BAAa,CAAC,mBAAQ,CAAC,mBAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAE9D,OAAO;YACP,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE;gBACjB,OAAO,IAAI,CAAC;aACf;YAED,OAAO;YACP,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SAC9B;KACJ;IAED,OAAO;IACP,OAAO,IAAI,IAAI,IAAI,CAAC;AACxB,CAAC;AAQQ,sBAAK"}
1
+ {"version":3,"file":"jsonc.js","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,iCAA8B;AAC9B,yCAAsC;AACtC,2CAAwC;AACxC,mDAAgD;AAoBhD,SAAS,KAAK,CAAW,GAAG,IAA4B;IACpD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAE1B,OAAO;IACP,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACjB,qBAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACzC;SAAM;QACH,MAAM,KAAK,GAAG,WAAI,CAAC,IAAI,CAAC,CAAC;QAEzB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE;YACzB,MAAM,OAAO,GAAG,6BAAa,CAAC,mBAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAEpD,OAAO;YACP,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE;gBACjB,OAAO,IAAI,CAAC;aACf;YAED,OAAO;YACP,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SAC9B;KACJ;IAED,OAAO;IACP,OAAO,IAAI,IAAI,IAAI,CAAC;AACxB,CAAC;AAQQ,sBAAK"}
package/dist/lstat.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- /// <reference types="node" />
2
- /**
3
- *****************************************
4
- * 加载依赖
5
- *****************************************
6
- */
7
- import * as fs from 'fs';
8
- /**
9
- *****************************************
10
- * 状态
11
- *****************************************
12
- */
13
- interface State extends fs.Stats {
14
- path: string;
15
- }
16
- /**
17
- *****************************************
18
- * 获取文件状态
19
- *****************************************
20
- */
21
- export declare function lstat(dir: string): State | null;
22
- export {};
1
+ /// <reference types="node" />
2
+ /**
3
+ *****************************************
4
+ * 加载依赖
5
+ *****************************************
6
+ */
7
+ import * as fs from 'fs';
8
+ /**
9
+ *****************************************
10
+ * 状态
11
+ *****************************************
12
+ */
13
+ interface State extends fs.Stats {
14
+ path: string;
15
+ }
16
+ /**
17
+ *****************************************
18
+ * 获取文件状态
19
+ *****************************************
20
+ */
21
+ export declare function lstat(dir: string): State | null;
22
+ export {};
23
23
  //# sourceMappingURL=lstat.d.ts.map
package/dist/lstat.js CHANGED
@@ -1,31 +1,31 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:06:57
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.lstat = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const fs = require("fs");
16
- const path = require("path");
17
- /**
18
- *****************************************
19
- * 获取文件状态
20
- *****************************************
21
- */
22
- function lstat(dir) {
23
- try {
24
- return Object.assign(fs.lstatSync(dir), { path: path.resolve(dir) });
25
- }
26
- catch (err) {
27
- return null;
28
- }
29
- }
30
- exports.lstat = lstat;
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2019-11-07 16:06:57
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.lstat = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const fs = require("fs");
16
+ const path = require("path");
17
+ /**
18
+ *****************************************
19
+ * 获取文件状态
20
+ *****************************************
21
+ */
22
+ function lstat(dir) {
23
+ try {
24
+ return Object.assign(fs.lstatSync(dir), { path: path.resolve(dir) });
25
+ }
26
+ catch (err) {
27
+ return null;
28
+ }
29
+ }
30
+ exports.lstat = lstat;
31
31
  //# sourceMappingURL=lstat.js.map
package/dist/mapdir.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- /// <reference types="node" />
2
- /**
3
- *****************************************
4
- * 加载依赖
5
- *****************************************
6
- */
7
- import * as fs from 'fs';
8
- /**
9
- *****************************************
10
- * 遍历回调
11
- *****************************************
12
- */
13
- interface Handler<T> {
14
- (path: string, stats: fs.Stats): T;
15
- }
16
- /**
17
- *****************************************
18
- * 遍历目录
19
- *****************************************
20
- */
21
- export declare function mapdir<T>(dir: string, handler: Handler<T>): T[];
22
- export {};
1
+ /// <reference types="node" />
2
+ /**
3
+ *****************************************
4
+ * 加载依赖
5
+ *****************************************
6
+ */
7
+ import * as fs from 'fs';
8
+ /**
9
+ *****************************************
10
+ * 遍历回调
11
+ *****************************************
12
+ */
13
+ interface Handler<T> {
14
+ (path: string, stats: fs.Stats): T;
15
+ }
16
+ /**
17
+ *****************************************
18
+ * 遍历目录
19
+ *****************************************
20
+ */
21
+ export declare function mapdir<T>(dir: string, handler: Handler<T>): T[];
22
+ export {};
23
23
  //# sourceMappingURL=mapdir.d.ts.map
package/dist/mapdir.js CHANGED
@@ -1,43 +1,43 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-09 16:35:57
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.mapdir = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const fs = require("fs");
16
- const path = require("path");
17
- const stat_1 = require("./stat");
18
- /**
19
- *****************************************
20
- * 遍历目录
21
- *****************************************
22
- */
23
- function mapdir(dir, handler) {
24
- let stats = stat_1.stat(dir), result = [];
25
- // 存在目录
26
- if (stats) {
27
- let dirname = stats.path, ignore = ['node_modules', '.DS_Store'];
28
- // 遍历子文件
29
- if (stats.isDirectory()) {
30
- fs.readdirSync(stats.path).forEach(name => {
31
- if (!ignore.includes(name)) {
32
- result.push(...mapdir(path.join(dirname, name), handler));
33
- }
34
- });
35
- }
36
- // 执行回调
37
- result.push(handler(dirname, stats));
38
- }
39
- // 返回结果
40
- return result;
41
- }
42
- exports.mapdir = mapdir;
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2019-11-09 16:35:57
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.mapdir = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const fs = require("fs");
16
+ const path = require("path");
17
+ const stat_1 = require("./stat");
18
+ /**
19
+ *****************************************
20
+ * 遍历目录
21
+ *****************************************
22
+ */
23
+ function mapdir(dir, handler) {
24
+ let stats = stat_1.stat(dir), result = [];
25
+ // 存在目录
26
+ if (stats) {
27
+ let dirname = stats.path, ignore = ['node_modules', '.DS_Store'];
28
+ // 遍历子文件
29
+ if (stats.isDirectory()) {
30
+ fs.readdirSync(stats.path).forEach(name => {
31
+ if (!ignore.includes(name)) {
32
+ result.push(...mapdir(path.join(dirname, name), handler));
33
+ }
34
+ });
35
+ }
36
+ // 执行回调
37
+ result.push(handler(dirname, stats));
38
+ }
39
+ // 返回结果
40
+ return result;
41
+ }
42
+ exports.mapdir = mapdir;
43
43
  //# sourceMappingURL=mapdir.js.map
package/dist/mkdir.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /**
2
- *****************************************
3
- * 创建目录
4
- *****************************************
5
- */
6
- export declare function mkdir(dir: string): string;
1
+ /**
2
+ *****************************************
3
+ * 创建目录
4
+ *****************************************
5
+ */
6
+ export declare function mkdir(dir: string): string;
7
7
  //# sourceMappingURL=mkdir.d.ts.map