@e-mc/document 0.6.0 → 0.6.2

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/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
- Copyright 2023 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ Copyright 2023 Ninja Scroll
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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 CHANGED
@@ -1,5 +1,7 @@
1
- ### @e-mc/document
1
+ # @e-mc/document
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Kagerō
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
package/asset.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { ExternalAsset, InitialValue } from '../types/lib/asset';
2
-
3
- declare namespace asset {
4
- function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
5
- function setInitialValue(file: ExternalAsset, cacheable?: boolean): InitialValue;
6
- }
7
-
1
+ import type { ExternalAsset, InitialValue } from '../types/lib/asset';
2
+
3
+ declare namespace asset {
4
+ function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
5
+ function setInitialValue(file: ExternalAsset, cacheable?: boolean): InitialValue;
6
+ }
7
+
8
8
  export = asset;
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { DocumentConstructor, IFileManager } from '../types/lib';
2
-
3
- declare const Document: DocumentConstructor<IFileManager>;
4
-
1
+ import type { DocumentConstructor, IFileManager } from '../types/lib';
2
+
3
+ declare const Document: DocumentConstructor<IFileManager>;
4
+
5
5
  export = Document;
package/index.js CHANGED
@@ -5,12 +5,12 @@ const fs = require("fs");
5
5
  const pm = require("picomatch");
6
6
  const yaml = require("js-yaml");
7
7
  const chalk = require("chalk");
8
- const types_1 = require("../types");
9
- const core_1 = require("../core");
10
- const db_1 = require("../db");
11
- const util_1 = require("./util");
12
- const transform_1 = require("./transform");
13
- const parse_1 = require("./parse");
8
+ const types_1 = require("@e-mc/types");
9
+ const core_1 = require("@e-mc/core");
10
+ const db_1 = require("@e-mc/db");
11
+ const util_1 = require("@e-mc/document/util");
12
+ const transform_1 = require("@e-mc/document/transform");
13
+ const parse_1 = require("@e-mc/document/parse");
14
14
  const CACHE_PACKAGE = {};
15
15
  const CACHE_REQUIRE = {};
16
16
  const CACHE_ETAG = {};
@@ -34,7 +34,7 @@ function deleteTransform(map, key, timeout) {
34
34
  --CACHE_TOTAL;
35
35
  }
36
36
  function getSourceMappingURL(value, css) {
37
- if (value.indexOf(' ') !== -1) {
37
+ if (value.includes(' ')) {
38
38
  value = encodeURIComponent(value);
39
39
  }
40
40
  return css ? `\n/*# sourceMappingURL=${value} */\n` : `\n//# sourceMappingURL=${value}\n`;
@@ -94,17 +94,16 @@ class Document extends core_1.Client {
94
94
  }
95
95
  try {
96
96
  const args = [instance];
97
- // @ts-ignore
98
- if (ext["__cjs__" /* INTERNAL.CJS */]) {
97
+ if (ext["__cjs__"]) {
99
98
  args.push(__dirname);
100
99
  }
101
- else if (core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */)) {
100
+ else if (core_1.Client.enabled("node.require.inline")) {
102
101
  args.push(require);
103
102
  }
104
103
  await ext.apply(this, args);
105
104
  }
106
105
  catch (err) {
107
- instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, this.moduleName], err);
106
+ instance.writeFail(["Unknown", this.moduleName], err);
108
107
  }
109
108
  }
110
109
  }
@@ -126,7 +125,7 @@ class Document extends core_1.Client {
126
125
  map.sources = [""];
127
126
  }
128
127
  try {
129
- let css = mimeType === 'text/css', flags = 0 /* SOURCEMAP.NONE */;
128
+ let css = mimeType === 'text/css', flags = 0;
130
129
  const output = JSON.stringify(map);
131
130
  const toBase64 = () => 'data:application/json;base64,' + Buffer.from(output).toString('base64');
132
131
  if (!inlineMap) {
@@ -147,24 +146,24 @@ class Document extends core_1.Client {
147
146
  }
148
147
  }
149
148
  let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
150
- flags |= 1 /* SOURCEMAP.FOUND */;
149
+ flags |= 1;
151
150
  if (capture[2] && capture[5]) {
152
151
  css = true;
153
152
  }
154
153
  if (inlineMap || capture[3]) {
155
- flags |= 2 /* SOURCEMAP.INLINE */;
154
+ flags |= 2;
156
155
  return getSourceMappingURL(toBase64(), css);
157
156
  }
158
157
  return capture[1] || css ? getSourceMappingURL(sourceMappingURL, css) : capture[0];
159
158
  });
160
- if (inlineMap || flags & 2 /* SOURCEMAP.INLINE */) {
161
- if (flags === 0 /* SOURCEMAP.NONE */) {
159
+ if (inlineMap || flags & 2) {
160
+ if (flags === 0) {
162
161
  code += getSourceMappingURL(toBase64(), css);
163
162
  }
164
163
  data.code = code;
165
164
  }
166
165
  else {
167
- if (flags === 0 /* SOURCEMAP.NONE */) {
166
+ if (flags === 0) {
168
167
  code += getSourceMappingURL(sourceMappingURL, css);
169
168
  }
170
169
  const result = path.join(path.dirname(uri), sourceMappingURL);
@@ -218,7 +217,7 @@ class Document extends core_1.Client {
218
217
  let match;
219
218
  while (match = pattern.exec(source)) {
220
219
  const preceding = source.substring(lastIndex, match.index);
221
- let opening = 0, closing = namespaces.length - 1;
220
+ let opening = 0, closing = 0;
222
221
  for (let j = 0, q = preceding.length; j < q; ++j) {
223
222
  switch (preceding[j]) {
224
223
  case '{':
@@ -229,8 +228,11 @@ class Document extends core_1.Client {
229
228
  break;
230
229
  }
231
230
  }
232
- if (opening === closing && (!multiple || match[1] && sanitizeValue(match[1]) === sanitizeValue(local[3]))) {
233
- return upgrade ? parse_1.XmlWriter.replaceMatch(match, source, value, pattern) : source;
231
+ if (opening === closing) {
232
+ if (!multiple || match[1] && sanitizeValue(match[1]) === sanitizeValue(local[3])) {
233
+ return upgrade ? parse_1.XmlWriter.replaceMatch(match, source, value, pattern) : source;
234
+ }
235
+ lastIndex = match.index + match[0].length;
234
236
  }
235
237
  }
236
238
  return spliceSource(source, lastIndex, lastIndex, ident.repeat(length) + value + newline);
@@ -275,7 +277,7 @@ class Document extends core_1.Client {
275
277
  for (const { severity, line, column, ruleId, message, fatal } of messages) {
276
278
  let error;
277
279
  if (severity) {
278
- if (error = severity === 2 /* LINT_SEVERITY.ERROR */ || severity === "error" /* LINT_SEVERITY.ERROR_TEXT */) {
280
+ if (error = severity === 2 || severity === "error") {
279
281
  ++errorCount;
280
282
  }
281
283
  else {
@@ -356,20 +358,18 @@ class Document extends core_1.Client {
356
358
  for (const pattern in pages) {
357
359
  const item = pages[pattern];
358
360
  if ((0, types_1.isPlainObject)(item)) {
359
- let isMatch;
360
- if (!(isMatch = CACHE_PICOMATCH.get(pattern)) && (0, types_1.hasGlob)(pattern)) {
361
- isMatch = pm(pattern, { matchBase: true });
362
- CACHE_PICOMATCH.set(pattern, isMatch);
363
- }
364
- else {
365
- continue;
366
- }
367
- if (isMatch(baseUrl)) {
361
+ if (pattern === baseUrl) {
368
362
  items.push(item);
369
363
  }
370
- }
371
- else {
372
- delete pages[pattern];
364
+ else if ((0, types_1.hasGlob)(pattern)) {
365
+ let isMatch = CACHE_PICOMATCH.get(pattern);
366
+ if (!isMatch) {
367
+ CACHE_PICOMATCH.set(pattern, isMatch = pm(pattern, { matchBase: true }));
368
+ }
369
+ if (isMatch(baseUrl)) {
370
+ items.push(item);
371
+ }
372
+ }
373
373
  }
374
374
  }
375
375
  if (items.length > 1) {
@@ -399,19 +399,18 @@ class Document extends core_1.Client {
399
399
  const handler = db.handler;
400
400
  const database = this.dataSource.filter(this.forDb.bind(this));
401
401
  let instance;
402
- if ((0, types_1.isString)(handler) && handler !== "@e-mc/db" /* PACKAGE_NAME.DB */) {
402
+ if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
403
403
  try {
404
404
  const Handler = require(handler);
405
405
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
406
- // @ts-ignore
407
406
  instance = new Handler(db, database);
408
407
  }
409
408
  else {
410
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor" /* ERR_DB.CONSTRUCTOR */, handler);
409
+ throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
411
410
  }
412
411
  }
413
412
  catch (err) {
414
- this.checkPackage(err, handler, ["Unable to load handler" /* ERR_MESSAGE.LOAD_HANDLER */, this.moduleName], 65536 /* LOG_TYPE.DB */);
413
+ this.checkPackage(err, handler, ["Unable to load handler", this.moduleName], 65536);
415
414
  }
416
415
  }
417
416
  else {
@@ -568,7 +567,7 @@ class Document extends core_1.Client {
568
567
  return getObject(result, false);
569
568
  }
570
569
  else {
571
- warning(path.isAbsolute(value) ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ + ` (${value})` : "Unknown" /* ERR_MESSAGE.UNKNOWN */);
570
+ warning(path.isAbsolute(value) ? "Unsupported access" + ` (${value})` : "Unknown");
572
571
  }
573
572
  break;
574
573
  }
@@ -611,7 +610,7 @@ class Document extends core_1.Client {
611
610
  result = CACHE_REQUIRE[pkgName];
612
611
  }
613
612
  if (!result) {
614
- if (!core_1.Client.enabled("node.require.npm" /* KEY_NAME.NODE_REQUIRE_NPM */)) {
613
+ if (!core_1.Client.enabled("node.require.npm")) {
615
614
  return null;
616
615
  }
617
616
  try {
@@ -623,11 +622,11 @@ class Document extends core_1.Client {
623
622
  CACHE_REQUIRE[pkgName] = result;
624
623
  }
625
624
  if (typeof result === 'function') {
626
- return Object.defineProperty(result, "__cjs__" /* INTERNAL.CJS */, { value: true });
625
+ return Object.defineProperty(result, "__cjs__", { value: true });
627
626
  }
628
627
  }
629
628
  catch (err) {
630
- this.checkPackage(err, pkgName, "Unknown" /* ERR_MESSAGE.UNKNOWN */);
629
+ this.checkPackage(err, pkgName, "Unknown");
631
630
  }
632
631
  if (!result) {
633
632
  return null;
@@ -646,13 +645,12 @@ class Document extends core_1.Client {
646
645
  catch {
647
646
  }
648
647
  }
649
- // @ts-ignore
650
- if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__" /* INTERNAL.CJS */] || this.hasEval('function'))) {
648
+ if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
651
649
  return result;
652
650
  }
653
651
  }
654
652
  catch (err) {
655
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(value)], err, 8192 /* LOG_TYPE.PERMISSION */);
653
+ this.writeFail(["Unable to read file", path.basename(value)], err, 8192);
656
654
  }
657
655
  return null;
658
656
  }
@@ -677,7 +675,7 @@ class Document extends core_1.Client {
677
675
  if (imports) {
678
676
  const normalizeDir = (value) => {
679
677
  const sep = value.includes('\\') && !value.includes('/') ? '\\' : '/';
680
- return value + (value[value.length - 1] !== sep ? sep : '');
678
+ return value + (!value.endsWith(sep) ? sep : '');
681
679
  };
682
680
  for (const url in imports) {
683
681
  if (uri === url || normalizeDir(uri) === normalizeDir(url)) {
@@ -730,7 +728,7 @@ class Document extends core_1.Client {
730
728
  }
731
729
  }
732
730
  catch (err) {
733
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, localUri && path.basename(localUri)], 32 /* LOG_TYPE.FILE */);
731
+ this.writeFail(["Unable to read file", localUri && path.basename(localUri)], 32);
734
732
  }
735
733
  }
736
734
  else if (bundleContent) {
@@ -786,7 +784,7 @@ class Document extends core_1.Client {
786
784
  catch (err) {
787
785
  const name = (0, util_1.getModuleName)(err);
788
786
  if (name) {
789
- this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown" /* ERR_MESSAGE.UNKNOWN */);
787
+ this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
790
788
  }
791
789
  throw err;
792
790
  }
@@ -825,7 +823,7 @@ class Document extends core_1.Client {
825
823
  if (!((0, types_1.isPlainObject)(target) && target.name)) {
826
824
  this.abort('view_engine');
827
825
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
828
- this.writeFail(["Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, from], (0, types_1.errorMessage)('view-engine', from, "Unknown" /* ERR_MESSAGE.UNKNOWN */));
826
+ this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
829
827
  return null;
830
828
  }
831
829
  const length = data.length;
@@ -853,10 +851,10 @@ class Document extends core_1.Client {
853
851
  const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
854
852
  let result = '', render, valid;
855
853
  if (!(render = cache[cacheKey])) {
856
- render = await context.compile(template, compile); // eslint-disable-line @typescript-eslint/await-thenable
854
+ render = await context.compile(template, compile);
857
855
  cache[cacheKey] = render;
858
- if (!core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username)) {
859
- setTimeout(() => delete cache[cacheKey], 60000 /* VALUES.TEMPLATE_EXPIRES */);
856
+ if (!core_1.Client.enabled("memory.settings.users", username)) {
857
+ setTimeout(() => delete cache[cacheKey], 60000);
860
858
  }
861
859
  }
862
860
  for (let i = 0, j = 0, row; i < length; ++i) {
@@ -867,11 +865,11 @@ class Document extends core_1.Client {
867
865
  }
868
866
  }
869
867
  else if (!(0, types_1.isObject)(row)) {
870
- this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
868
+ this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
871
869
  continue;
872
870
  }
873
871
  if (!singleRow) {
874
- const content = await render.call(context, row); // eslint-disable-line @typescript-eslint/await-thenable
872
+ const content = await render.call(context, row);
875
873
  if (content !== undefined && content !== null) {
876
874
  result += content;
877
875
  valid = true;
@@ -882,7 +880,7 @@ class Document extends core_1.Client {
882
880
  }
883
881
  catch (err) {
884
882
  this.abort('view_engine');
885
- this.checkPackage(err, name, "Unknown" /* ERR_MESSAGE.UNKNOWN */, 4 /* LOG_TYPE.PROCESS */);
883
+ this.checkPackage(err, name, "Unknown", 4);
886
884
  }
887
885
  return null;
888
886
  }
@@ -896,7 +894,7 @@ class Document extends core_1.Client {
896
894
  const username = this.host?.username || '';
897
895
  const config = this._transformConfig;
898
896
  const cacheData = config && options.cacheData;
899
- const cacheType = username && core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */);
897
+ const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
900
898
  let formatKey, hashKey, excludeKey;
901
899
  if (cacheData && cacheType && !CACHE_EXTERNAL[excludeKey = moduleName + '_' + type + '_' + format] && (!config.exclude[type] || Array.isArray(config.exclude[type]) && !format.some(value => config.exclude[type].includes(value)) || Array.isArray(config.include[type]) && format.every(value => config.include[type].includes(value)))) {
902
900
  const { uri, etag } = cacheData;
@@ -972,7 +970,7 @@ class Document extends core_1.Client {
972
970
  }
973
971
  if (result) {
974
972
  result.storedLog?.forEach(log => this.addLog(log));
975
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
973
+ this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
976
974
  return result;
977
975
  }
978
976
  }
@@ -1050,7 +1048,7 @@ class Document extends core_1.Client {
1050
1048
  if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1051
1049
  failed = true;
1052
1050
  ignoreCache = true;
1053
- this.writeFail(["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ : 'Empty'), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1051
+ this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : 'Empty'), { type: 4, startTime });
1054
1052
  }
1055
1053
  else if (source !== value) {
1056
1054
  series.code = value;
@@ -1082,19 +1080,18 @@ class Document extends core_1.Client {
1082
1080
  }
1083
1081
  this.writeTimeProcess(failed ? 'CHECK' : type, joinString(hint, options.filename) + (series.out.messageAppend || ''), startTime, { failed, bypassLog });
1084
1082
  };
1085
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1083
+ this.formatMessage(4, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1086
1084
  try {
1087
1085
  let context = require(plugin);
1088
1086
  series.packageName = plugin;
1089
1087
  if (typeof baseConfig === 'function') {
1090
1088
  series.baseConfig = outputConfig;
1091
- // @ts-ignore
1092
- if (baseConfig["__cjs__" /* INTERNAL.CJS */]) {
1089
+ if (baseConfig["__cjs__"]) {
1093
1090
  next(await baseConfig(context, source, series));
1094
1091
  }
1095
1092
  else {
1096
- const thisArg = core_1.Client.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null;
1097
- const inline = core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */);
1093
+ const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
1094
+ const inline = core_1.Client.enabled("node.require.inline");
1098
1095
  const args = [context, source, series];
1099
1096
  if (baseConfig.toString().startsWith('async')) {
1100
1097
  if (inline) {
@@ -1128,7 +1125,7 @@ class Document extends core_1.Client {
1128
1125
  }
1129
1126
  else {
1130
1127
  transformer = context;
1131
- context = this; // eslint-disable-line @typescript-eslint/no-this-alias
1128
+ context = this;
1132
1129
  pkg = undefined;
1133
1130
  }
1134
1131
  if (transformer && typeof transformer !== 'function') {
@@ -1143,7 +1140,7 @@ class Document extends core_1.Client {
1143
1140
  }
1144
1141
  catch (err) {
1145
1142
  abort();
1146
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, username ? plugin + ':' + username : hint], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1143
+ this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
1147
1144
  continue;
1148
1145
  }
1149
1146
  }
@@ -1153,7 +1150,7 @@ class Document extends core_1.Client {
1153
1150
  }
1154
1151
  catch (err) {
1155
1152
  abort();
1156
- this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, hint], { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1153
+ this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
1157
1154
  if (i < length - 1) {
1158
1155
  series.reset();
1159
1156
  }
@@ -1162,10 +1159,10 @@ class Document extends core_1.Client {
1162
1159
  else {
1163
1160
  abort();
1164
1161
  if (plugin) {
1165
- this.writeFail("Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4 /* LOG_TYPE.PROCESS */);
1162
+ this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
1166
1163
  }
1167
1164
  else {
1168
- this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown" /* ERR_MESSAGE.UNKNOWN */), 4 /* LOG_TYPE.PROCESS */);
1165
+ this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"), 4);
1169
1166
  }
1170
1167
  }
1171
1168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,12 +17,12 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.6.0",
24
- "@e-mc/db": "0.6.0",
25
- "@e-mc/types": "0.6.0",
23
+ "@e-mc/core": "0.6.2",
24
+ "@e-mc/db": "0.6.2",
25
+ "@e-mc/types": "0.6.2",
26
26
  "chalk": "4.1.2",
27
27
  "htmlparser2": "^9.0.0",
28
28
  "js-yaml": "^4.1.0",
package/parse/dom.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { IGNORE_FLAG, DomWriterConstructor, HtmlElementConstructor } from './types';
2
-
3
- declare namespace dom {
4
- const IGNORE_FLAG: IGNORE_FLAG;
5
- const DomWriter: DomWriterConstructor;
6
- const HtmlElement: HtmlElementConstructor;
7
- }
8
-
1
+ import type { IGNORE_FLAG, DomWriterConstructor, HtmlElementConstructor } from './types';
2
+
3
+ declare namespace dom {
4
+ const IGNORE_FLAG: IGNORE_FLAG;
5
+ const DomWriter: DomWriterConstructor;
6
+ const HtmlElement: HtmlElementConstructor;
7
+ }
8
+
9
9
  export = dom;
package/parse/dom.js CHANGED
@@ -4,9 +4,9 @@ exports.IGNORE_FLAG = exports.HtmlElement = exports.DomWriter = void 0;
4
4
  const htmlparser2 = require("htmlparser2");
5
5
  const domhandler = require("domhandler");
6
6
  const domutils = require("domutils");
7
- const types_1 = require("../../types");
8
- const util_1 = require("../util");
9
- const index_1 = require("./index");
7
+ const types_1 = require("@e-mc/types");
8
+ const util_1 = require("@e-mc/document/util");
9
+ const index_1 = require("@e-mc/document/parse");
10
10
  Object.defineProperty(exports, "IGNORE_FLAG", { enumerable: true, get: function () { return index_1.IGNORE_FLAG; } });
11
11
  const Parser = htmlparser2.Parser;
12
12
  const DomHandler = domhandler.DomHandler;
@@ -30,7 +30,7 @@ class DomWriter extends index_1.XmlWriter {
30
30
  if (ignoreTagGroup) {
31
31
  for (let i = 0, length = ignoreTagGroup.length; i < length; i += 2) {
32
32
  const start = ignoreTagGroup[i];
33
- if (start[0] === '<') {
33
+ if (start.startsWith('<')) {
34
34
  tagGroup.push(new RegExp('^' + (0, types_1.escapePattern)(start)));
35
35
  }
36
36
  const end = ignoreTagGroup[i + 1];
@@ -89,7 +89,7 @@ class DomWriter extends index_1.XmlWriter {
89
89
  const result = { element: null, error: null };
90
90
  new Parser(new DomHandler((err, dom) => {
91
91
  if (!err) {
92
- result.element = domutils.findOne(elem => elem.tagName === "html" /* VALUES.ROOT */, dom);
92
+ result.element = domutils.findOne(elem => elem.tagName === "html", dom);
93
93
  }
94
94
  else {
95
95
  result.error = err;
@@ -111,8 +111,8 @@ class DomWriter extends index_1.XmlWriter {
111
111
  parser || (parser = { ...PARSER_OPTIONS });
112
112
  super(documentName, source, elements, { parser });
113
113
  this.documentElement = null;
114
- this.ignoreTagName = "title|style|script" /* VALUES.IGNORE_TAGNAME */;
115
- this.rootName = "html" /* VALUES.ROOT */;
114
+ this.ignoreTagName = "title|style|script";
115
+ this.rootName = "html";
116
116
  this.ignoreCaseTagName = true;
117
117
  const items = [];
118
118
  let outerXml = '', documentElement, offsetMap, startIndex = -1;
@@ -121,7 +121,7 @@ class DomWriter extends index_1.XmlWriter {
121
121
  item.tagName = item.tagName.toLowerCase();
122
122
  item.ignoreCase = true;
123
123
  }
124
- if (item.tagName === "html" /* VALUES.ROOT */) {
124
+ if (item.tagName === "html") {
125
125
  items.push(item);
126
126
  if (!documentElement && item.innerXml) {
127
127
  documentElement = item;
@@ -198,7 +198,7 @@ class DomWriter extends index_1.XmlWriter {
198
198
  if (this.modified && this.documentElement) {
199
199
  let innerXml;
200
200
  for (const item of this.elements) {
201
- if (item.tagName === "html" /* VALUES.ROOT */) {
201
+ if (item.tagName === "html") {
202
202
  if (!innerXml && index_1.XmlWriter.isIndex(item.endIndex)) {
203
203
  innerXml = this.source.substring(item.endIndex + 1, this.source.length - 7).trim();
204
204
  }
@@ -223,7 +223,7 @@ class HtmlElement extends index_1.XmlElement {
223
223
  constructor(documentName, node, attributes, options = {}) {
224
224
  options.parser || (options.parser = { ...PARSER_OPTIONS });
225
225
  super(documentName, node, attributes, { ...options, tagVoid: TAG_VOID.includes(node.tagName) });
226
- this._documentType = "HTML" /* VALUES.DOCUMENT_TYPE */;
226
+ this._documentType = "HTML";
227
227
  }
228
228
  getTagOffset(source) {
229
229
  switch (this.node.append?.tagName || this.tagName) {
@@ -233,7 +233,7 @@ class HtmlElement extends index_1.XmlElement {
233
233
  case 'script':
234
234
  return;
235
235
  default:
236
- return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script" /* VALUES.IGNORE_TAGNAME */, parser: this.parser });
236
+ return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script", parser: this.parser });
237
237
  }
238
238
  }
239
239
  findIndexOf(source) {
@@ -244,8 +244,8 @@ class HtmlElement extends index_1.XmlElement {
244
244
  }
245
245
  get outerXml() {
246
246
  const [tagName, items, innerXml] = this.getOuterContent();
247
- return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" /* VALUES.ROOT */ ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
247
+ return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
248
248
  }
249
249
  }
250
250
  exports.HtmlElement = HtmlElement;
251
- index_1.XmlWriter.namesOfTagVoid("HTML" /* VALUES.DOCUMENT_TYPE */, TAG_VOID);
251
+ index_1.XmlWriter.namesOfTagVoid("HTML", TAG_VOID);
package/parse/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { IGNORE_FLAG, XmlWriterConstructor, XmlElementConstructor } from './types';
2
-
3
- declare namespace parse {
4
- const IGNORE_FLAG: IGNORE_FLAG;
5
- const XmlWriter: XmlWriterConstructor;
6
- const XmlElement: XmlElementConstructor;
7
- }
8
-
1
+ import type { IGNORE_FLAG, XmlWriterConstructor, XmlElementConstructor } from './types';
2
+
3
+ declare namespace parse {
4
+ const IGNORE_FLAG: IGNORE_FLAG;
5
+ const XmlWriter: XmlWriterConstructor;
6
+ const XmlElement: XmlElementConstructor;
7
+ }
8
+
9
9
  export = parse;
package/parse/index.js CHANGED
@@ -4,8 +4,8 @@ exports.XmlElement = exports.XmlWriter = exports.IGNORE_FLAG = void 0;
4
4
  const htmlparser2 = require("htmlparser2");
5
5
  const domhandler = require("domhandler");
6
6
  const domutils = require("domutils");
7
- const types_1 = require("../../types");
8
- const module_1 = require("../../module");
7
+ const types_1 = require("@e-mc/types");
8
+ const module_1 = require("@e-mc/module");
9
9
  var IGNORE_FLAG;
10
10
  (function (IGNORE_FLAG) {
11
11
  IGNORE_FLAG[IGNORE_FLAG["NONE"] = 0] = "NONE";
@@ -174,7 +174,7 @@ class XmlWriter {
174
174
  }
175
175
  static getNewlineString(leading, trailing, newline) {
176
176
  const value = leading + trailing;
177
- return getNewlineCount(value) > 1 ? newline || (value.indexOf('\r') !== -1 ? '\r\n' : '\n') : '';
177
+ return getNewlineCount(value) > 1 ? newline || (value.includes('\r') ? '\r\n' : '\n') : '';
178
178
  }
179
179
  static findCloseTag(source, startIndex = 0) {
180
180
  const length = source.length;
@@ -910,11 +910,11 @@ class XmlWriter {
910
910
  }
911
911
  let tagName = this.ignoreTagName || '';
912
912
  if (tagName) {
913
- if (value[0] !== '|' && tagName[tagName.length - 1] !== '|') {
913
+ if (!value.startsWith('|') && !tagName.endsWith('|')) {
914
914
  tagName += '|';
915
915
  }
916
916
  }
917
- else if (value[0] === '|') {
917
+ else if (value.startsWith('|')) {
918
918
  value = value.substring(1);
919
919
  }
920
920
  this.ignoreTagName = tagName + value;
@@ -1260,7 +1260,7 @@ class XmlElement {
1260
1260
  const { tagName, tagIndex = -1, tagCount = Infinity, ignoreCase } = node;
1261
1261
  const id = this.id;
1262
1262
  const flags = ignoreCase ? 'gi' : 'g';
1263
- const hasId = (startIndex, endIndex) => source.substring(startIndex, endIndex).indexOf(id) !== -1;
1263
+ const hasId = (startIndex, endIndex) => source.substring(startIndex, endIndex).includes(id);
1264
1264
  const errorResult = () => ['', '', (0, types_1.errorValue)('Element was not found', tagName.toUpperCase() + (isIndex(tagIndex) ? ' @ ' + tagIndex : ''))];
1265
1265
  let position;
1266
1266
  if (XmlWriter.isTagVoid(this.documentType, tagName)) {
@@ -1,8 +1,8 @@
1
- import type { SourceMapConstructor, TransformSeriesConstructor } from '../../types/lib/document';
2
-
3
- declare namespace transform {
4
- const TransformSeries: TransformSeriesConstructor;
5
- const SourceMap: SourceMapConstructor;
6
- }
7
-
1
+ import type { SourceMapConstructor, TransformSeriesConstructor } from '../../types/lib/document';
2
+
3
+ declare namespace transform {
4
+ const TransformSeries: TransformSeriesConstructor;
5
+ const SourceMap: SourceMapConstructor;
6
+ }
7
+
8
8
  export = transform;
@@ -3,8 +3,8 @@ var _a, _b, _c, _d;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.SourceMap = exports.TransformSeries = void 0;
5
5
  const path = require("path");
6
- const types_1 = require("../../types");
7
- const core_1 = require("../../core");
6
+ const types_1 = require("@e-mc/types");
7
+ const core_1 = require("@e-mc/core");
8
8
  const kCode = Symbol('code');
9
9
  const kMap = Symbol('map');
10
10
  const kOut = Symbol('out');
@@ -16,7 +16,7 @@ const kUsername = Symbol('username');
16
16
  const kProductionRelease = Symbol('productionRelease');
17
17
  function parseMap(data, value) {
18
18
  let [mimeType, encoding] = data.split(';');
19
- if (!encoding && mimeType.indexOf('/') === -1) {
19
+ if (!encoding && !mimeType.includes('/')) {
20
20
  encoding = mimeType;
21
21
  }
22
22
  return encoding.includes('base64') ? Buffer.from(value, 'base64').toString() : value;
@@ -185,20 +185,16 @@ class TransformSeries extends core_1.Module {
185
185
  return this.options.external;
186
186
  }
187
187
  set version(value) {
188
- // @ts-ignore
189
188
  this.metadata.__version__ = value;
190
189
  }
191
190
  get version() {
192
- // @ts-ignore
193
191
  return this.metadata.__version__ || '';
194
192
  }
195
193
  set packageName(value) {
196
- // @ts-ignore
197
194
  this.metadata.__packagename__ = value;
198
195
  this.version = 'latest';
199
196
  }
200
197
  get packageName() {
201
- // @ts-ignore
202
198
  return this.metadata.__packagename__ || '';
203
199
  }
204
200
  get packageVersion() {
package/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = exports.IMPORTS = void 0;
4
4
  const path = require("path");
5
- const types_1 = require("../types");
5
+ const types_1 = require("@e-mc/types");
6
6
  Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
7
7
  exports.IMPORTS = {
8
8
  "@babel/core": "@pi-r/babel",