@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
@@ -0,0 +1,234 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2021-06-19 00:16:40
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+
9
+
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ import { createFileResolver, FileResolver, Handler, Options as FileOptions } from './helpers/FileResolver';
16
+ import { split } from './helpers/split';
17
+ import { each } from './helpers/each';
18
+ import { compose } from './helpers/compose';
19
+ import { cwd } from './cwd';
20
+
21
+
22
+ /**
23
+ *****************************************
24
+ * 格式化别名
25
+ *****************************************
26
+ */
27
+ function normalizePaths(value: string | string[]): void | string[] {
28
+
29
+ // 校验值
30
+ if (!value) {
31
+ return;
32
+ }
33
+
34
+ // 处理字符串配置
35
+ if (typeof value === 'string') {
36
+ return [value];
37
+ }
38
+
39
+ // 校验数组配置参数
40
+ if (!Array.isArray(value) || !value.length) {
41
+ return;
42
+ }
43
+
44
+ // 校验参数
45
+ if (value.find(path => !path || typeof path !== 'string')) {
46
+ throw new Error('expect paths value to be valid string[]!');
47
+ }
48
+
49
+ // 返回结果
50
+ return value;
51
+ }
52
+
53
+
54
+ /**
55
+ *****************************************
56
+ * 创建路径解析器
57
+ *****************************************
58
+ */
59
+ function createPathsResolver(resolver: FileResolver, options: Options): Handler {
60
+ const rules: Handler[] = [];
61
+ const baseURL = cwd(options.context || process.cwd(), options.baseUrl || './');
62
+ const resolvePath = resolver.resolvePath;
63
+
64
+ // 解析路径
65
+ function resolvePaths(paths: string[]): Handler {
66
+ return compose(paths.map(value => {
67
+ const [start, end] = split(value, '*');
68
+
69
+ // 处理绝对匹配
70
+ if (end === undefined) {
71
+ return (_, context) => resolvePath(cwd(baseURL, start), context);
72
+ } else {
73
+ return (id, context) => resolvePath(cwd(baseURL, start + id + end), context);
74
+ }
75
+ }));
76
+ }
77
+
78
+ // 校验存在路径映射配置
79
+ each(options.paths, (value, key) => {
80
+ const paths = normalizePaths(value);
81
+
82
+ // 校验配置
83
+ if (!paths) {
84
+ return;
85
+ }
86
+
87
+ // 生成解析函数
88
+ const resolve = resolvePaths(paths);
89
+
90
+ // 解析匹配项
91
+ const [start, end] = split(key, '*');
92
+
93
+ // 完成匹配
94
+ if (end === undefined) {
95
+ return rules.push((id, context) => {
96
+ return id === start ? resolve('', context) : undefined;
97
+ });
98
+ }
99
+
100
+ // 获取前/后缀长度
101
+ const startLength = start.length;
102
+ const endLength = end.length;
103
+ const idx = (startLength ? 1 : 0) + (endLength ? 2 : 0);
104
+
105
+ // 匹配前缀
106
+ if (idx === 1) {
107
+ return rules.push((id, context) => {
108
+ if (id.startsWith(start)) {
109
+ return resolve(id.slice(startLength), context);
110
+ }
111
+ });
112
+ }
113
+
114
+ // 匹配后缀
115
+ if (idx === 2) {
116
+ return rules.push((id, context) => {
117
+ if (id.endsWith(end)) {
118
+ return resolve(id.slice(0, - endLength), context);
119
+ }
120
+ });
121
+ }
122
+
123
+ // 匹配前缀和后缀
124
+ if (idx === 3) {
125
+ return rules.push((id, context) => {
126
+ if (id.startsWith(start) && id.endsWith(end)) {
127
+ return resolve(id.slice(startLength, - endLength), context);
128
+ }
129
+ });
130
+ }
131
+
132
+ // 默认完全匹配
133
+ return rules.push((id, context) => resolve(id, context));
134
+ });
135
+
136
+ // 组件规则解析方法
137
+ if (rules.length) {
138
+ return resolver.wrapHandler(compose([...rules, resolver.resolveModule]));
139
+ } else {
140
+ return resolvePath;
141
+ }
142
+ }
143
+
144
+
145
+ /**
146
+ *****************************************
147
+ * 创建别名解析器
148
+ *****************************************
149
+ */
150
+ function createAliasResolver(resolver: FileResolver, options: Options): Handler {
151
+ const resolvePaths = createPathsResolver(resolver, options);
152
+ const rules: Handler[] = [];
153
+
154
+ // 解析别名
155
+ each(options.alias, (value, key) => {
156
+ const paths = normalizePaths(value);
157
+
158
+ // 校验参数
159
+ if (!paths) {
160
+ return;
161
+ }
162
+
163
+ // 生成解析函数
164
+ const resolve: Handler = compose(
165
+ paths.map(start => (id, context) => resolvePaths(start + id, context))
166
+ );
167
+
168
+ // 绝对匹配
169
+ if (key.endsWith('$')) {
170
+
171
+ // 去除匹配符
172
+ key = key.slice(0, -1);
173
+
174
+ // 添加匹配规则
175
+ return rules.push(
176
+ (id, context) => (id === key ? resolve('', context) : undefined)
177
+ );
178
+ }
179
+
180
+ // 生成配置前缀
181
+ const prefix = key + '/';
182
+ const prefixLength = key.length;
183
+
184
+ // 添加匹配规则
185
+ return rules.push(
186
+ (id, context) => (id === key ? resolve('', context) : undefined),
187
+ (id, context) => (id.startsWith(prefix) ? resolve(id.slice(prefixLength), context) : undefined)
188
+ );
189
+ });
190
+
191
+ // 返回解析函数
192
+ if (rules.length) {
193
+ return resolver.wrapHandler(compose([...rules, resolvePaths]));
194
+ } else {
195
+ return resolvePaths;
196
+ }
197
+ }
198
+
199
+
200
+ /**
201
+ *****************************************
202
+ * 选项
203
+ *****************************************
204
+ */
205
+ export interface Options extends FileOptions {
206
+ baseUrl?: string;
207
+ paths?: {
208
+ [key: string]: string[];
209
+ };
210
+ alias?: {
211
+ [key: string]: string | string[];
212
+ };
213
+ }
214
+
215
+
216
+ /**
217
+ *****************************************
218
+ * 解析文件
219
+ *****************************************
220
+ */
221
+ export function resolvePath(options: Options = {}): Handler {
222
+ const modules = options.modules || ['node_modules'];
223
+
224
+ // 添加基准模块解析
225
+ if (options.baseUrl || options.paths) {
226
+ modules.unshift(options.baseUrl || '.');
227
+ }
228
+
229
+ // 创建文件解析器
230
+ const resolver = createFileResolver({ ...options, modules });
231
+
232
+ // 返回解析函数
233
+ return createAliasResolver(resolver, options);
234
+ }
package/src/stat.ts CHANGED
@@ -21,7 +21,7 @@ import * as path from 'path';
21
21
  * 状态
22
22
  *****************************************
23
23
  */
24
- interface State extends fs.Stats {
24
+ export interface State extends fs.Stats {
25
25
  path: string;
26
26
  }
27
27
 
package/src/supdir.ts CHANGED
@@ -16,6 +16,37 @@ import * as path from 'path';
16
16
  import { dirname } from './dirname';
17
17
 
18
18
 
19
+ /**
20
+ *****************************************
21
+ * 遍历目录
22
+ *****************************************
23
+ */
24
+ export function mapdir(dir: string, handler: (dir: string) => void): void {
25
+ const resolveFrom = path.resolve(dir);
26
+ const sep = path.sep;
27
+ const end = resolveFrom.indexOf(sep);
28
+
29
+ // 不存在结束符
30
+ if (end < 0) {
31
+ return handler(resolveFrom);
32
+ }
33
+
34
+ // 遍历目录
35
+ for (let idx = resolveFrom.length; idx >= end; ) {
36
+
37
+ // 执行回调
38
+ if (idx === 0) {
39
+ return handler('/');
40
+ } else {
41
+ handler(resolveFrom.slice(0, idx));
42
+ }
43
+
44
+ // 更新索引
45
+ idx = resolveFrom.lastIndexOf(sep, idx - 1);
46
+ }
47
+ }
48
+
49
+
19
50
  /**
20
51
  *****************************************
21
52
  * 查找上一级目录回调
package/src/writeFile.ts CHANGED
@@ -25,7 +25,7 @@ import { dirname } from './dirname';
25
25
  interface Options {
26
26
  encoding?: string;
27
27
  append?: boolean;
28
- mode?: string;
28
+ mode?: fs.Mode;
29
29
  flag?: string;
30
30
  }
31
31
 
@@ -35,24 +35,27 @@ interface Options {
35
35
  * 写入文件
36
36
  *****************************************
37
37
  */
38
- function writeFile(path: string, content: string | Buffer): void;
38
+ function writeFile(path: string, content?: string | Buffer): void;
39
39
  function writeFile(path: string, content: string | Buffer, encoding: string): void;
40
40
  function writeFile(path: string, content: string | Buffer, append: boolean): void;
41
41
  function writeFile(path: string, content: string | Buffer, { append, encoding, mode, flag }: Options): void;
42
- function writeFile(path: string, content: string | Buffer, options?: string | boolean | Options): void {
42
+ function writeFile(path: string, content?: string | Buffer, options?: string | boolean | Options): void {
43
43
 
44
44
  // 默认配置
45
45
  if (!options) {
46
46
  options = { encoding: 'utf8' };
47
47
  }
48
48
 
49
- // 校验配置
50
- if (typeof options === 'object') {
49
+ // 默认值
50
+ if (typeof content === 'undefined') {
51
+ content = '';
52
+ }
51
53
 
52
- // 创建目录
53
- mkdir(dirname(path));
54
+ // 创建目录
55
+ mkdir(dirname(path));
54
56
 
55
- // 写入文件
57
+ // 校验配置
58
+ if (typeof options === 'object') {
56
59
  if (options.append) {
57
60
  return fs.appendFileSync(path, content, options as fs.WriteFileOptions);
58
61
  } else {
@@ -1,21 +0,0 @@
1
- /**
2
- *****************************************
3
- * 别名配置
4
- *****************************************
5
- */
6
- export interface Options {
7
- baseUrl?: string;
8
- paths?: {
9
- [key: string]: string[];
10
- };
11
- alias?: {
12
- [key: string]: string;
13
- };
14
- }
15
- /**
16
- *****************************************
17
- * 解析路径别名
18
- *****************************************
19
- */
20
- export declare function resolveAlias(options: Options): (source: string) => string;
21
- //# sourceMappingURL=resolveAlias.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveAlias.d.ts","sourceRoot":"","sources":["../src/resolveAlias.ts"],"names":[],"mappings":"AAsGA;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IACpC,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACrC;AAGD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAiCzE"}
@@ -1,108 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.resolveAlias = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const path_1 = require("path");
16
- const isRelativePath_1 = require("./isRelativePath");
17
- /**
18
- *****************************************
19
- * 末尾星号匹配项
20
- *****************************************
21
- */
22
- const endsStar = /\*+$/;
23
- /**
24
- *****************************************
25
- * 解析路径规则
26
- *****************************************
27
- */
28
- function resolvePaths(key, value, baseUrl, rules) {
29
- // 校验值
30
- if (!key || key === '*' || !value) {
31
- return;
32
- }
33
- // 清除末尾星号
34
- if (value.endsWith('*')) {
35
- value = value.replace(endsStar, '');
36
- }
37
- // 解析匹配规则
38
- if (key.endsWith('/*') || key.endsWith('/')) {
39
- const prefix = key.replace(endsStar, '');
40
- // 存在名称
41
- if (prefix) {
42
- const size = prefix.length;
43
- // 添加规则
44
- rules.push(isRelativePath_1.isRelativePath(value) ?
45
- source => source.startsWith(prefix) && path_1.resolve(baseUrl, value, './' + source.slice(size)) :
46
- source => source.startsWith(prefix) && value + source.slice(size));
47
- }
48
- }
49
- else if (key.endsWith('$')) {
50
- const name = key.slice(0, -1);
51
- // 格式化路径
52
- if (isRelativePath_1.isRelativePath(value)) {
53
- value = path_1.resolve(baseUrl, value);
54
- }
55
- // 存在名称
56
- if (name) {
57
- rules.push(source => name === source && value);
58
- }
59
- }
60
- else {
61
- const prefix = key + '/';
62
- const size = key.length;
63
- // 格式化路径
64
- if (isRelativePath_1.isRelativePath(value)) {
65
- value = path_1.resolve(baseUrl, value);
66
- // 添加匹配规则
67
- rules.push(source => key === source && value, source => source.startsWith(prefix) && path_1.resolve(value, './' + source.slice(size)));
68
- }
69
- else {
70
- rules.push(source => key === source && value, source => source.startsWith(prefix) && value + source.slice(size));
71
- }
72
- }
73
- }
74
- /**
75
- *****************************************
76
- * 解析路径别名
77
- *****************************************
78
- */
79
- function resolveAlias(options) {
80
- const rules = [];
81
- const { alias, paths, baseUrl = '.' } = options;
82
- // 存在别名配置
83
- if (alias) {
84
- Object.keys(alias).forEach(key => resolvePaths(key, alias[key], baseUrl, rules));
85
- }
86
- // 存在路径配置
87
- if (paths) {
88
- Object.keys(paths).forEach(key => resolvePaths(key, paths[key][0], baseUrl, rules));
89
- }
90
- // 无解析规则
91
- if (!rules.length) {
92
- return (source) => source;
93
- }
94
- // 生成解析函数
95
- return (source) => {
96
- for (let idx = 0, len = rules.length; idx < len; idx++) {
97
- const result = rules[idx](source);
98
- // 解析成功
99
- if (result) {
100
- return result;
101
- }
102
- }
103
- // 解析失败
104
- return source;
105
- };
106
- }
107
- exports.resolveAlias = resolveAlias;
108
- //# sourceMappingURL=resolveAlias.js.map
@@ -1 +0,0 @@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AG,GAAG,EAAE,GAAG,OAAO,CAAC;IAEhD,SAAS;IACT,IAAI,KAAK,EAAE;QACP,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;KACpF;IAED,SAAS;IACT,IAAI,KAAK,EAAE;QACP,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;KACvF;IAED,QAAQ;IACR,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACf,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC;KACrC;IAED,SAAS;IACT,OAAO,CAAC,MAAc,EAAE,EAAE;QACtB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAG,EAAE;YACrD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;YAElC,OAAO;YACP,IAAI,MAAM,EAAE;gBACR,OAAO,MAAM,CAAC;aACjB;SACJ;QAED,OAAO;QACP,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAjCD,oCAiCC"}
@@ -1,7 +0,0 @@
1
- /**
2
- *****************************************
3
- * 移除BOM头
4
- *****************************************
5
- */
6
- export declare function stripBOM(content: string): string;
7
- //# sourceMappingURL=stripBOM.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripBOM.d.ts","sourceRoot":"","sources":["../src/stripBOM.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAShD"}
package/dist/stripBOM.js DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-31 22:41:48
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.stripBOM = void 0;
10
- /**
11
- *****************************************
12
- * 移除BOM头
13
- *****************************************
14
- */
15
- function stripBOM(content) {
16
- // 检测第一个字符是否为BOM
17
- if (content.charCodeAt(0) === 0xFEFF) {
18
- return content.slice(1);
19
- }
20
- // 返回源内容
21
- return content;
22
- }
23
- exports.stripBOM = stripBOM;
24
- //# sourceMappingURL=stripBOM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripBOM.js","sourceRoot":"","sources":["../src/stripBOM.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,OAAe;IAEpC,gBAAgB;IAChB,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE;QAClC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC3B;IAED,QAAQ;IACR,OAAO,OAAO,CAAC;AACnB,CAAC;AATD,4BASC"}
@@ -1,7 +0,0 @@
1
- /**
2
- *****************************************
3
- * 过滤注释
4
- *****************************************
5
- */
6
- export declare function stripComments(content: string): string;
7
- //# sourceMappingURL=stripComments.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripComments.d.ts","sourceRoot":"","sources":["../src/stripComments.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAiGrD"}
@@ -1,100 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-31 22:41:48
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.stripComments = void 0;
10
- /**
11
- *****************************************
12
- * 过滤注释
13
- *****************************************
14
- */
15
- function stripComments(content) {
16
- let result = '';
17
- let idx = 0;
18
- let len = content.length;
19
- let start = 0;
20
- // 查找转义符
21
- function isEscaped(index) {
22
- let count = 1;
23
- while (content[index - count] === '\\') {
24
- count++;
25
- }
26
- return count % 2;
27
- }
28
- // 路过字符串
29
- function skipString(ch, start) {
30
- const end = content.indexOf(ch, start);
31
- if (end === -1) {
32
- return len;
33
- }
34
- else {
35
- return isEscaped(end) ? end + 1 : skipString(ch, end + 1);
36
- }
37
- }
38
- // 查找换行
39
- function indexLineCommentEnd(start) {
40
- const end = content.indexOf('\n', start);
41
- if (end === -1) {
42
- return len;
43
- }
44
- else {
45
- return content[end - 1] === '\r' ? end - 1 : end;
46
- }
47
- }
48
- // 查找块注释结束
49
- function indexBlockCommentEnd(start) {
50
- const end = content.indexOf('/', start);
51
- if (end === -1) {
52
- return len;
53
- }
54
- else if (content[end - 1] === '*') {
55
- return end + 1;
56
- }
57
- else {
58
- return indexBlockCommentEnd(end + 1);
59
- }
60
- }
61
- // 遍历字符
62
- while (idx < len) {
63
- const ch = content[idx];
64
- // 跳过字符串
65
- if (ch === '"') {
66
- idx = skipString('"', idx + 1);
67
- continue;
68
- }
69
- // 自增偏移
70
- idx++;
71
- // 非注释
72
- if (ch !== '/') {
73
- continue;
74
- }
75
- // 获取下一字符
76
- const next = content[idx];
77
- // 处理行注释
78
- if (next === '/') {
79
- result += content.slice(start, idx - 1);
80
- start = indexLineCommentEnd(idx + 1);
81
- idx = start + 1;
82
- continue;
83
- }
84
- // 处理多行注释
85
- if (next === '*') {
86
- result += content.slice(start, idx - 1);
87
- start = indexBlockCommentEnd(idx + 2);
88
- idx = start;
89
- continue;
90
- }
91
- }
92
- // 添加结束片段
93
- if (start < len) {
94
- result += content.slice(start);
95
- }
96
- // 返回结果
97
- return result;
98
- }
99
- exports.stripComments = stripComments;
100
- //# sourceMappingURL=stripComments.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripComments.js","sourceRoot":"","sources":["../src/stripComments.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAe;IACzC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IACzB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,QAAQ;IACR,SAAS,SAAS,CAAC,KAAa;QAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,OAAO,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE;YACpC,KAAK,EAAG,CAAC;SACZ;QAED,OAAO,KAAK,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,QAAQ;IACR,SAAS,UAAU,CAAC,EAAU,EAAE,KAAa;QACzC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAEvC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE;YACZ,OAAO,GAAG,CAAC;SACd;aAAM;YACH,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;SAC7D;IACL,CAAC;IAED,OAAO;IACP,SAAS,mBAAmB,CAAC,KAAa;QACtC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAEzC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE;YACZ,OAAO,GAAG,CAAC;SACd;aAAM;YACH,OAAO,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,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