@e-mc/document 0.5.3 → 0.5.5

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 Anya Forger
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,5 @@
1
- ### @e-mc/document
1
+ # @e-mc/document
2
2
 
3
- ### LICENSE
3
+ ## LICENSE
4
4
 
5
- BSD 3-Clause
5
+ MIT
package/asset.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { ExternalAsset } from '../types/lib/asset';
2
-
3
- declare namespace asset {
4
- function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
5
- function setInitialValue(file: ExternalAsset, cacheable?: boolean): void;
6
- }
7
-
1
+ import type { ExternalAsset } from '../types/lib/asset';
2
+
3
+ declare namespace asset {
4
+ function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
5
+ function setInitialValue(file: ExternalAsset, cacheable?: boolean): void;
6
+ }
7
+
8
8
  export = asset;
package/asset.js CHANGED
@@ -6,6 +6,6 @@ function isEqual(item, other) {
6
6
  }
7
7
  exports.isEqual = isEqual;
8
8
  function setInitialValue(file, cacheable = true) {
9
- file.initialValue || (file.initialValue = { pathname: file.pathname, filename: file.filename, mimeType: file.mimeType, localUri: file.localUri, inlineFilename: file.inlineFilename, cacheable });
9
+ return file.initialValue || (file.initialValue = { pathname: file.pathname, filename: file.filename, mimeType: file.mimeType, localUri: file.localUri, inlineFilename: file.inlineFilename, cacheable });
10
10
  }
11
11
  exports.setInitialValue = setInitialValue;
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 PIR_PLUGINS = Object.freeze({
15
15
  "@babel/core": "@pi-r/babel",
16
16
  "clean-css": "@pi-r/clean-css",
@@ -52,7 +52,7 @@ function deleteTransform(map, key, timeout) {
52
52
  --CACHE_TOTAL;
53
53
  }
54
54
  function getSourceMappingURL(value, css) {
55
- if (value.indexOf(' ') !== -1) {
55
+ if (value.includes(' ')) {
56
56
  value = encodeURIComponent(value);
57
57
  }
58
58
  return css ? `\n/*# sourceMappingURL=${value} */\n` : `\n//# sourceMappingURL=${value}\n`;
@@ -112,17 +112,16 @@ class Document extends core_1.Client {
112
112
  }
113
113
  try {
114
114
  const args = [instance];
115
- // @ts-ignore
116
- if (ext["__cjs__" /* INTERNAL.CJS */]) {
115
+ if (ext["__cjs__"]) {
117
116
  args.push(__dirname);
118
117
  }
119
- else if (core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */)) {
118
+ else if (core_1.Client.enabled("node.require.inline")) {
120
119
  args.push(require);
121
120
  }
122
121
  await ext.apply(this, args);
123
122
  }
124
123
  catch (err) {
125
- instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, this.moduleName], err);
124
+ instance.writeFail(["Unknown", this.moduleName], err);
126
125
  }
127
126
  }
128
127
  }
@@ -144,7 +143,7 @@ class Document extends core_1.Client {
144
143
  map.sources = [""];
145
144
  }
146
145
  try {
147
- let css = mimeType === 'text/css', flags = 0 /* SOURCEMAP.NONE */;
146
+ let css = mimeType === 'text/css', flags = 0;
148
147
  const output = JSON.stringify(map);
149
148
  const toBase64 = () => 'data:application/json;base64,' + Buffer.from(output).toString('base64');
150
149
  if (!inlineMap) {
@@ -165,24 +164,24 @@ class Document extends core_1.Client {
165
164
  }
166
165
  }
167
166
  let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
168
- flags |= 1 /* SOURCEMAP.FOUND */;
167
+ flags |= 1;
169
168
  if (capture[2] && capture[5]) {
170
169
  css = true;
171
170
  }
172
171
  if (inlineMap || capture[3]) {
173
- flags |= 2 /* SOURCEMAP.INLINE */;
172
+ flags |= 2;
174
173
  return getSourceMappingURL(toBase64(), css);
175
174
  }
176
175
  return capture[1] || css ? getSourceMappingURL(sourceMappingURL, css) : capture[0];
177
176
  });
178
- if (inlineMap || flags & 2 /* SOURCEMAP.INLINE */) {
179
- if (flags === 0 /* SOURCEMAP.NONE */) {
177
+ if (inlineMap || flags & 2) {
178
+ if (flags === 0) {
180
179
  code += getSourceMappingURL(toBase64(), css);
181
180
  }
182
181
  data.code = code;
183
182
  }
184
183
  else {
185
- if (flags === 0 /* SOURCEMAP.NONE */) {
184
+ if (flags === 0) {
186
185
  code += getSourceMappingURL(sourceMappingURL, css);
187
186
  }
188
187
  const result = path.join(path.dirname(uri), sourceMappingURL);
@@ -236,7 +235,7 @@ class Document extends core_1.Client {
236
235
  let match;
237
236
  while (match = pattern.exec(source)) {
238
237
  const preceding = source.substring(lastIndex, match.index);
239
- let opening = 0, closing = namespaces.length - 1;
238
+ let opening = 0, closing = 0;
240
239
  for (let j = 0, q = preceding.length; j < q; ++j) {
241
240
  switch (preceding[j]) {
242
241
  case '{':
@@ -247,8 +246,11 @@ class Document extends core_1.Client {
247
246
  break;
248
247
  }
249
248
  }
250
- if (opening === closing && (!multiple || match[1] && sanitizeValue(match[1]) === sanitizeValue(local[3]))) {
251
- return upgrade ? parse_1.XmlWriter.replaceMatch(match, source, value, pattern) : source;
249
+ if (opening === closing) {
250
+ if (!multiple || match[1] && sanitizeValue(match[1]) === sanitizeValue(local[3])) {
251
+ return upgrade ? parse_1.XmlWriter.replaceMatch(match, source, value, pattern) : source;
252
+ }
253
+ lastIndex = match.index + match[0].length;
252
254
  }
253
255
  }
254
256
  return spliceSource(source, lastIndex, lastIndex, ident.repeat(length) + value + newline);
@@ -293,7 +295,7 @@ class Document extends core_1.Client {
293
295
  for (const { severity, line, column, ruleId, message, fatal } of messages) {
294
296
  let error;
295
297
  if (severity) {
296
- if (error = severity === 2 /* LINT_SEVERITY.ERROR */ || severity === "error" /* LINT_SEVERITY.ERROR_TEXT */) {
298
+ if (error = severity === 2 || severity === "error") {
297
299
  ++errorCount;
298
300
  }
299
301
  else {
@@ -370,20 +372,18 @@ class Document extends core_1.Client {
370
372
  for (const pattern in pages) {
371
373
  const item = pages[pattern];
372
374
  if ((0, types_1.isPlainObject)(item)) {
373
- let isMatch;
374
- if (!(isMatch = CACHE_PICOMATCH.get(pattern)) && (0, types_1.hasGlob)(pattern)) {
375
- isMatch = pm(pattern, { matchBase: true });
376
- CACHE_PICOMATCH.set(pattern, isMatch);
377
- }
378
- else {
379
- continue;
380
- }
381
- if (isMatch(baseUrl)) {
375
+ if (pattern === baseUrl) {
382
376
  items.push(item);
383
377
  }
384
- }
385
- else {
386
- delete pages[pattern];
378
+ else if ((0, types_1.hasGlob)(pattern)) {
379
+ let isMatch = CACHE_PICOMATCH.get(pattern);
380
+ if (!isMatch) {
381
+ CACHE_PICOMATCH.set(pattern, isMatch = pm(pattern, { matchBase: true }));
382
+ }
383
+ if (isMatch(baseUrl)) {
384
+ items.push(item);
385
+ }
386
+ }
387
387
  }
388
388
  }
389
389
  if (items.length > 1) {
@@ -413,18 +413,18 @@ class Document extends core_1.Client {
413
413
  const handler = db.handler;
414
414
  const database = this.dataSource.filter(this.forDb.bind(this));
415
415
  let instance;
416
- if ((0, types_1.isString)(handler) && handler !== "@e-mc/db" /* PACKAGE_NAME.DB */) {
416
+ if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
417
417
  try {
418
418
  const Handler = require(handler);
419
419
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
420
420
  instance = new Handler(db, database);
421
421
  }
422
422
  else {
423
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor" /* ERR_DB.CONSTRUCTOR */, handler);
423
+ throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
424
424
  }
425
425
  }
426
426
  catch (err) {
427
- this.checkPackage(err, handler, ["Unable to load handler" /* ERR_MESSAGE.LOAD_HANDLER */, this.moduleName], 65536 /* LOG_TYPE.DB */);
427
+ this.checkPackage(err, handler, ["Unable to load handler", this.moduleName], 65536);
428
428
  }
429
429
  }
430
430
  else {
@@ -581,7 +581,7 @@ class Document extends core_1.Client {
581
581
  return getObject(result, false);
582
582
  }
583
583
  else {
584
- warning(path.isAbsolute(value) ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ + ` (${value})` : "Unknown" /* ERR_MESSAGE.UNKNOWN */);
584
+ warning(path.isAbsolute(value) ? "Unsupported access" + ` (${value})` : "Unknown");
585
585
  }
586
586
  break;
587
587
  }
@@ -624,7 +624,7 @@ class Document extends core_1.Client {
624
624
  result = CACHE_REQUIRE[pkgName];
625
625
  }
626
626
  if (!result) {
627
- if (!core_1.Client.enabled("node.require.npm" /* KEY_NAME.NODE_REQUIRE_NPM */)) {
627
+ if (!core_1.Client.enabled("node.require.npm")) {
628
628
  return null;
629
629
  }
630
630
  try {
@@ -636,11 +636,11 @@ class Document extends core_1.Client {
636
636
  CACHE_REQUIRE[pkgName] = result;
637
637
  }
638
638
  if (typeof result === 'function') {
639
- return Object.defineProperty(result, "__cjs__" /* INTERNAL.CJS */, { value: true });
639
+ return Object.defineProperty(result, "__cjs__", { value: true });
640
640
  }
641
641
  }
642
642
  catch (err) {
643
- this.checkPackage(err, pkgName, "Unknown" /* ERR_MESSAGE.UNKNOWN */);
643
+ this.checkPackage(err, pkgName, "Unknown");
644
644
  }
645
645
  if (!result) {
646
646
  return null;
@@ -659,13 +659,12 @@ class Document extends core_1.Client {
659
659
  catch {
660
660
  }
661
661
  }
662
- // @ts-ignore
663
- if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__" /* INTERNAL.CJS */] || this.hasEval('function'))) {
662
+ if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
664
663
  return result;
665
664
  }
666
665
  }
667
666
  catch (err) {
668
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(value)], err, 8192 /* LOG_TYPE.PERMISSION */);
667
+ this.writeFail(["Unable to read file", path.basename(value)], err, 8192);
669
668
  }
670
669
  return null;
671
670
  }
@@ -690,7 +689,7 @@ class Document extends core_1.Client {
690
689
  if (imports) {
691
690
  const normalizeDir = (value) => {
692
691
  const sep = value.includes('\\') && !value.includes('/') ? '\\' : '/';
693
- return value + (value[value.length - 1] !== sep ? sep : '');
692
+ return value + (!value.endsWith(sep) ? sep : '');
694
693
  };
695
694
  for (const url in imports) {
696
695
  if (uri === url || normalizeDir(uri) === normalizeDir(url)) {
@@ -743,7 +742,7 @@ class Document extends core_1.Client {
743
742
  }
744
743
  }
745
744
  catch (err) {
746
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, localUri && path.basename(localUri)], 32 /* LOG_TYPE.FILE */);
745
+ this.writeFail(["Unable to read file", localUri && path.basename(localUri)], 32);
747
746
  }
748
747
  }
749
748
  else if (bundleContent) {
@@ -799,7 +798,7 @@ class Document extends core_1.Client {
799
798
  catch (err) {
800
799
  const name = (0, util_1.getModuleName)(err);
801
800
  if (name) {
802
- this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown" /* ERR_MESSAGE.UNKNOWN */);
801
+ this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
803
802
  }
804
803
  throw err;
805
804
  }
@@ -838,7 +837,7 @@ class Document extends core_1.Client {
838
837
  if (!((0, types_1.isPlainObject)(target) && target.name)) {
839
838
  this.abort('view_engine');
840
839
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
841
- this.writeFail(["Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, from], (0, types_1.errorMessage)('view-engine', from, "Unknown" /* ERR_MESSAGE.UNKNOWN */));
840
+ this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
842
841
  return null;
843
842
  }
844
843
  const length = data.length;
@@ -866,25 +865,25 @@ class Document extends core_1.Client {
866
865
  const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
867
866
  let result = '', render, valid;
868
867
  if (!(render = cache[cacheKey])) {
869
- render = await context.compile(template, compile); // eslint-disable-line @typescript-eslint/await-thenable
868
+ render = await context.compile(template, compile);
870
869
  cache[cacheKey] = render;
871
- if (!core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username)) {
872
- setTimeout(() => delete cache[cacheKey], 60000 /* VALUES.TEMPLATE_EXPIRES */);
870
+ if (!core_1.Client.enabled("memory.settings.users", username)) {
871
+ setTimeout(() => delete cache[cacheKey], 60000);
873
872
  }
874
873
  }
875
874
  for (let i = 0, j = 0, row; i < length; ++i) {
876
875
  if ((0, types_1.isPlainObject)(row = data[i])) {
877
- row['__index__'] ?? (row['__index__'] = ++j);
876
+ row.__index__ ?? (row.__index__ = ++j);
878
877
  if (output) {
879
878
  row = { ...output, ...row };
880
879
  }
881
880
  }
882
881
  else if (!(0, types_1.isObject)(row)) {
883
- this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
882
+ this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
884
883
  continue;
885
884
  }
886
885
  if (!singleRow) {
887
- const content = await render.call(context, row); // eslint-disable-line @typescript-eslint/await-thenable
886
+ const content = await render.call(context, row);
888
887
  if (content !== undefined && content !== null) {
889
888
  result += content;
890
889
  valid = true;
@@ -895,7 +894,7 @@ class Document extends core_1.Client {
895
894
  }
896
895
  catch (err) {
897
896
  this.abort('view_engine');
898
- this.checkPackage(err, name, "Unknown" /* ERR_MESSAGE.UNKNOWN */, 4 /* LOG_TYPE.PROCESS */);
897
+ this.checkPackage(err, name, "Unknown", 4);
899
898
  }
900
899
  return null;
901
900
  }
@@ -911,7 +910,7 @@ class Document extends core_1.Client {
911
910
  const username = this.host?.username || '';
912
911
  const config = this._transformConfig;
913
912
  const cacheData = config && options.cacheData;
914
- 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 */);
913
+ const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
915
914
  let formatKey, hashKey, excludeKey;
916
915
  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)))) {
917
916
  const { uri, etag } = cacheData;
@@ -987,7 +986,7 @@ class Document extends core_1.Client {
987
986
  }
988
987
  if (result) {
989
988
  result.storedLog?.forEach(log => this.addLog(log));
990
- 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 });
989
+ this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
991
990
  return result;
992
991
  }
993
992
  }
@@ -1065,7 +1064,7 @@ class Document extends core_1.Client {
1065
1064
  if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1066
1065
  failed = true;
1067
1066
  ignoreCache = true;
1068
- 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 });
1067
+ this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : 'Empty'), { type: 4, startTime });
1069
1068
  }
1070
1069
  else if (source !== value) {
1071
1070
  series.code = value;
@@ -1097,19 +1096,18 @@ class Document extends core_1.Client {
1097
1096
  }
1098
1097
  this.writeTimeProcess(failed ? 'CHECK' : type, joinString(hint, options.filename) + (series.out.messageAppend || ''), startTime, { failed, bypassLog });
1099
1098
  };
1100
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1099
+ this.formatMessage(4, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1101
1100
  try {
1102
1101
  let context = require(plugin);
1103
1102
  series.packageName = plugin;
1104
1103
  if (typeof baseConfig === 'function') {
1105
1104
  series.baseConfig = outputConfig;
1106
- // @ts-ignore
1107
- if (baseConfig["__cjs__" /* INTERNAL.CJS */]) {
1105
+ if (baseConfig["__cjs__"]) {
1108
1106
  next(await baseConfig(context, source, series));
1109
1107
  }
1110
1108
  else {
1111
- const thisArg = core_1.Client.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null;
1112
- const inline = core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */);
1109
+ const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
1110
+ const inline = core_1.Client.enabled("node.require.inline");
1113
1111
  const args = [context, source, series];
1114
1112
  if (baseConfig.toString().startsWith('async')) {
1115
1113
  if (inline) {
@@ -1133,7 +1131,7 @@ class Document extends core_1.Client {
1133
1131
  if (!transformer) {
1134
1132
  try {
1135
1133
  let pkg = this.resolveDir('package', plugin + '.js') || userImports?.[plugin] || imports[plugin] || PIR_PLUGINS[plugin];
1136
- if ((0, types_1.isString)(pkg)) {
1134
+ if (pkg) {
1137
1135
  const match = /^(@?\S+)@(\d+(?:\.\d+(?:\.\S+)?)?|[a-z]+)$/.exec(pkg);
1138
1136
  if (match) {
1139
1137
  pkg = match[1];
@@ -1144,10 +1142,12 @@ class Document extends core_1.Client {
1144
1142
  else {
1145
1143
  transformer = context;
1146
1144
  context = this;
1147
- pkg = undefined;
1148
1145
  }
1149
- if (typeof transformer !== 'function' && typeof (transformer = transformer?.['default']) !== 'function') {
1150
- throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1146
+ if (typeof transformer !== 'function') {
1147
+ transformer && (transformer = transformer.default);
1148
+ if (typeof transformer !== 'function') {
1149
+ throw (0, types_1.errorMessage)(plugin, pkg || name, 'Invalid function');
1150
+ }
1151
1151
  }
1152
1152
  if (pkg) {
1153
1153
  CACHE_PACKAGE[plugin + username] = transformer;
@@ -1155,7 +1155,7 @@ class Document extends core_1.Client {
1155
1155
  }
1156
1156
  catch (err) {
1157
1157
  abort();
1158
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, username ? plugin + ':' + username : hint], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1158
+ this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
1159
1159
  continue;
1160
1160
  }
1161
1161
  }
@@ -1165,7 +1165,7 @@ class Document extends core_1.Client {
1165
1165
  }
1166
1166
  catch (err) {
1167
1167
  abort();
1168
- this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, hint], { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1168
+ this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
1169
1169
  if (i < length - 1) {
1170
1170
  series.reset();
1171
1171
  }
@@ -1174,10 +1174,10 @@ class Document extends core_1.Client {
1174
1174
  else {
1175
1175
  abort();
1176
1176
  if (plugin) {
1177
- this.writeFail("Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4 /* LOG_TYPE.PROCESS */);
1177
+ this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
1178
1178
  }
1179
1179
  else {
1180
- this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown" /* ERR_MESSAGE.UNKNOWN */), 4 /* LOG_TYPE.PROCESS */);
1180
+ this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"), 4);
1181
1181
  }
1182
1182
  }
1183
1183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/e-mc.git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
13
  "directory": "src/document"
14
14
  },
15
15
  "keywords": [
@@ -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.5.3",
24
- "@e-mc/db": "0.5.3",
25
- "@e-mc/types": "0.5.3",
23
+ "@e-mc/core": "0.5.5",
24
+ "@e-mc/db": "0.5.5",
25
+ "@e-mc/types": "0.5.5",
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,21 +185,17 @@ class TransformSeries extends core_1.Module {
185
185
  return this.options.external;
186
186
  }
187
187
  set version(value) {
188
- // @ts-ignore
189
- this.metadata['__version__'] = value;
188
+ this.metadata.__version__ = value;
190
189
  }
191
190
  get version() {
192
- // @ts-ignore
193
- return this.metadata['__version__'] || '';
191
+ return this.metadata.__version__ || '';
194
192
  }
195
193
  set packageName(value) {
196
- // @ts-ignore
197
- this.metadata['__packagename__'] = value;
194
+ this.metadata.__packagename__ = value;
198
195
  this.version = 'latest';
199
196
  }
200
197
  get packageName() {
201
- // @ts-ignore
202
- return this.metadata['__packagename__'] || '';
198
+ return this.metadata.__packagename__ || '';
203
199
  }
204
200
  get packageVersion() {
205
201
  const packageName = this.packageName;
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 = 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
  function loadPlugins(name, plugins = []) {
8
8
  if (Array.isArray(name)) {