@e-mc/document 0.10.1 → 0.10.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/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "@e-mc/document",
3
- "version": "0.10.1",
4
- "description": "Document constructor for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/document"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/core": "0.10.1",
24
- "@e-mc/db": "0.10.1",
25
- "@e-mc/types": "0.10.1",
26
- "chalk": "4.1.2",
27
- "htmlparser2": "^9.1.0",
28
- "js-yaml": "^4.1.0",
29
- "picomatch": "^4.0.2"
30
- }
31
- }
1
+ {
2
+ "name": "@e-mc/document",
3
+ "version": "0.10.2",
4
+ "description": "Document constructor for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/document"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "BSD 3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/core": "0.10.2",
24
+ "@e-mc/db": "0.10.2",
25
+ "@e-mc/types": "0.10.2",
26
+ "chalk": "4.1.2",
27
+ "htmlparser2": "^9.1.0",
28
+ "js-yaml": "^4.1.0",
29
+ "picomatch": "^4.0.2"
30
+ }
31
+ }
package/parse/dom.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { DomWriterConstructor, HtmlElementConstructor, IGNORE_FLAG } 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 { DomWriterConstructor, HtmlElementConstructor, IGNORE_FLAG } 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
@@ -9,7 +9,7 @@ const types_1 = require("@e-mc/types");
9
9
  const util_1 = require("@e-mc/document/util");
10
10
  const Parser = htmlparser2.Parser;
11
11
  const DomHandler = domhandler.DomHandler;
12
- const TAG_VOID = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
12
+ const TAG_VOID = ['area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'isindex', 'keygen', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
13
13
  const REGEXP_VOID = TAG_VOID.map(tagName => new RegExp(`(\\s*)</${tagName}\\s*>` + index_1.XmlWriter.PATTERN_TRAILINGSPACE, 'gi'));
14
14
  const REGEXP_TAGNAME = new RegExp(`^${index_1.XmlWriter.PATTERN_TAGNAME}$`);
15
15
  const PARSER_OPTIONS = Object.freeze({ xmlMode: false, decodeEntities: false });
@@ -106,7 +106,7 @@ class DomWriter extends index_1.XmlWriter {
106
106
  else {
107
107
  options = { normalize: options, escapeEntities, parser };
108
108
  }
109
- parser || (parser = { ...PARSER_OPTIONS });
109
+ parser ||= { ...PARSER_OPTIONS };
110
110
  super(documentName, source, elements, { parser });
111
111
  this.documentElement = null;
112
112
  this.ignoreTagName = "title|style|script";
@@ -224,7 +224,7 @@ class DomWriter extends index_1.XmlWriter {
224
224
  exports.DomWriter = DomWriter;
225
225
  class HtmlElement extends index_1.XmlElement {
226
226
  constructor(documentName, node, attributes, options = {}) {
227
- options.parser || (options.parser = { ...PARSER_OPTIONS });
227
+ options.parser ||= { ...PARSER_OPTIONS };
228
228
  super(documentName, node, attributes, { ...options, tagVoid: TAG_VOID.includes(node.tagName) });
229
229
  this._documentType = "HTML";
230
230
  }
package/parse/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { IGNORE_FLAG, XmlElementConstructor, XmlWriterConstructor } 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, XmlElementConstructor, XmlWriterConstructor } 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
@@ -51,9 +51,8 @@ function resetTagPosition(item) {
51
51
  item.tagCount = 0;
52
52
  }
53
53
  function findCloseIndex(source, tagName, lastIndex, ignoreCase) {
54
- var _a;
55
54
  const flags = ignoreCase ? 'gi' : 'g';
56
- const pattern = CACHE_TAGNAME[_a = tagName + flags + '0'] || (CACHE_TAGNAME[_a] = new RegExp(`<(?:${escapeTagName(tagName)}\\s*|/${escapeTagName(tagName)}\\s*>)`, flags));
55
+ const pattern = CACHE_TAGNAME[tagName + flags + '0'] ||= new RegExp(`<(?:${escapeTagName(tagName)}\\s*|/${escapeTagName(tagName)}\\s*>)`, flags);
57
56
  pattern.lastIndex = lastIndex;
58
57
  let openTag = 1, closeTag = 0, match;
59
58
  while (match = pattern.exec(source)) {
@@ -151,7 +150,7 @@ class XmlWriter {
151
150
  return leading + content + trailing;
152
151
  }
153
152
  static escapeXmlString(value, ampersand) {
154
- return value.replace(ampersand ? /[<>"'&]/g : /[<>"']|&(?![a-z][a-z\d]+|#(?:\d+|x[a-f\d]+))/g, capture => {
153
+ return value.replace(ampersand ? /[<>"'&]/g : /[<>"']|&(?![a-z][a-z\d]+|#(?:\d+|x[a-f\d]+))/gi, capture => {
155
154
  switch (capture) {
156
155
  case '<':
157
156
  return '&lt;';
@@ -311,7 +310,6 @@ class XmlWriter {
311
310
  return { element, parser, outDom, error: null };
312
311
  }
313
312
  static getTagOffset(source, replacement, options) {
314
- var _a, _b;
315
313
  if ((0, types_1.isObject)(replacement)) {
316
314
  options = replacement;
317
315
  replacement = undefined;
@@ -321,14 +319,14 @@ class XmlWriter {
321
319
  const { ignoreCase, ignoreTagName, ignoreTagGroup } = options;
322
320
  if (ignoreTagName) {
323
321
  const flags = ignoreCase ? 'gi' : 'g';
324
- source = source.replace(CACHE_TAGOFFSET[_a = ignoreTagName + flags] || (CACHE_TAGOFFSET[_a] = new RegExp(`<(?:${ignoreTagName.split('|').map(value => escapeTagName(value)).join('|')})${this.PATTERN_TAGOPEN}*>[\\S\\s]*?<\\/\\1\\s*>`, flags)), '');
322
+ source = source.replace(CACHE_TAGOFFSET[ignoreTagName + flags] ||= new RegExp(`<(?:${ignoreTagName.split('|').map(value => escapeTagName(value)).join('|')})${this.PATTERN_TAGOPEN}*>[\\S\\s]*?<\\/\\1\\s*>`, flags), '');
325
323
  }
326
324
  if (ignoreTagGroup) {
327
325
  for (let i = 0, length = ignoreTagGroup.length; i < length; i += 2) {
328
326
  const start = ignoreTagGroup[i];
329
327
  const end = ignoreTagGroup[i + 1];
330
328
  if (end) {
331
- source = source.replace(CACHE_TAGOFFSET[_b = start + end] || (CACHE_TAGOFFSET[_b] = new RegExp(escapeTagName(start) + '.*?' + escapeTagName(end), 'gs')), '');
329
+ source = source.replace(CACHE_TAGOFFSET[start + end] ||= new RegExp(escapeTagName(start) + '.*?' + escapeTagName(end), 'gs'), '');
332
330
  }
333
331
  }
334
332
  }
@@ -368,10 +366,9 @@ class XmlWriter {
368
366
  return `data-${document}-id`;
369
367
  }
370
368
  static getPatternId(name) {
371
- return CACHE_PATTERNID[name] || (CACHE_PATTERNID[name] = new RegExp(`\\s${(0, types_1.escapePattern)(name)}="([^"]+)"`));
369
+ return CACHE_PATTERNID[name] ||= new RegExp(`\\s${(0, types_1.escapePattern)(name)}="([^"]+)"`);
372
370
  }
373
371
  static getCommentsAndCDATA(source, tagPattern = '', ignoreCase, stripXml) {
374
- var _a, _b;
375
372
  let tagGroup;
376
373
  if (stripXml) {
377
374
  if (typeof tagPattern !== 'string') {
@@ -389,7 +386,7 @@ class XmlWriter {
389
386
  }
390
387
  const result = [];
391
388
  const flags = ignoreCase ? 'gi' : 'g';
392
- let pattern = CACHE_TAGNAME[_a = tagPattern + flags] || (CACHE_TAGNAME[_a] = new RegExp(`<(?:(!--[\\S\\s]*?--)|(!\\[CDATA\\[[\\S\\s]*?\\]\\])` + (tagPattern ? '|' + `(${tagPattern})${this.PATTERN_TAGOPEN}*` : '') + ')>', flags)), match;
389
+ let pattern = CACHE_TAGNAME[tagPattern + flags] ||= new RegExp(`<(?:(!--[\\S\\s]*?--)|(!\\[CDATA\\[[\\S\\s]*?\\]\\])` + (tagPattern ? '|' + `(${tagPattern})${this.PATTERN_TAGOPEN}*` : '') + ')>', flags), match;
393
390
  pattern.lastIndex = 0;
394
391
  while (match = pattern.exec(source)) {
395
392
  if (stripXml) {
@@ -414,7 +411,7 @@ class XmlWriter {
414
411
  const start = tagGroup[i];
415
412
  const end = tagGroup[i + 1];
416
413
  if (end) {
417
- pattern = CACHE_TAGNAME[_b = start + end] || (CACHE_TAGNAME[_b] = new RegExp(escapeTagName(start) + '.*?' + escapeTagName(end), 'gs'));
414
+ pattern = CACHE_TAGNAME[start + end] ||= new RegExp(escapeTagName(start) + '.*?' + escapeTagName(end), 'gs');
418
415
  for (const tag of source.matchAll(pattern)) {
419
416
  const startIndex = tag.index;
420
417
  result.push({ type: 'block', outerXml: tag[0], startIndex, endIndex: startIndex + tag[0].length - 1 });
@@ -539,7 +536,7 @@ class XmlWriter {
539
536
  if (!(tagName in this._tagCount) && isCount(append.tagCount)) {
540
537
  this._tagCount[tagName] = append.tagCount;
541
538
  }
542
- append.id || (append.id = this.newId);
539
+ append.id ||= this.newId;
543
540
  element.setAppend(append);
544
541
  }
545
542
  return element;
@@ -570,7 +567,7 @@ class XmlWriter {
570
567
  return true;
571
568
  }
572
569
  const { node, append } = element;
573
- element.parser || (element.parser = this.parser);
570
+ element.parser ||= this.parser;
574
571
  element.newline = this.newline;
575
572
  let output, outerXml = '', error;
576
573
  if (element.hasPosition()) {
@@ -598,7 +595,7 @@ class XmlWriter {
598
595
  if (!prepend) {
599
596
  node.index = nextSibling ?? -1;
600
597
  }
601
- (node.id || (node.id = {}))[this.documentName] = id;
598
+ (node.id ||= {})[this.documentName] = id;
602
599
  element.id = id;
603
600
  element.innerXml = textContent;
604
601
  const offset = element.getInnerOffset(tagName);
@@ -958,7 +955,7 @@ class XmlWriter {
958
955
  const source = this.source;
959
956
  const match = new RegExp(`<(${tagName && escapeTagName(tagName) || '[^\\s>]+'})${XmlWriter.PATTERN_TAGOPEN}+?${(0, types_1.escapePattern)(this.nameOfId)}="${(0, types_1.escapePattern)(id)}"`, ignoreCase ? 'i' : '').exec(source);
960
957
  if (match) {
961
- tagName || (tagName = match[1]);
958
+ tagName ||= match[1];
962
959
  const startIndex = match.index;
963
960
  let endIndex = -1, closeTag = 0;
964
961
  if (!tagVoid) {
@@ -973,7 +970,6 @@ class XmlWriter {
973
970
  }
974
971
  }
975
972
  getElementsByTagName(tagName, ignoreCase = false, options) {
976
- var _a;
977
973
  let tagVoid;
978
974
  if (options) {
979
975
  ({ tagVoid } = options);
@@ -983,7 +979,7 @@ class XmlWriter {
983
979
  const result = [];
984
980
  const patternId = XmlWriter.getPatternId(this.nameOfId);
985
981
  const flags = ignoreCase ? 'gi' : 'g';
986
- const pattern = CACHE_TAGNAME[_a = tagName + flags + '3'] || (CACHE_TAGNAME[_a] = new RegExp(`<${escapeTagName(tagName) + XmlWriter.PATTERN_TAGOPEN}*>`, flags));
982
+ const pattern = CACHE_TAGNAME[tagName + flags + '3'] ||= new RegExp(`<${escapeTagName(tagName) + XmlWriter.PATTERN_TAGOPEN}*>`, flags);
987
983
  for (const match of source.matchAll(pattern)) {
988
984
  const startIndex = match.index;
989
985
  let outerXml = match[0], endIndex = startIndex + outerXml.length - 1;
@@ -1038,7 +1034,7 @@ class XmlWriter {
1038
1034
  return XmlWriter.getNameOfId(this.documentName);
1039
1035
  }
1040
1036
  get patternIgnore() {
1041
- return this.ignoreTagName ? this._patternIgnore || (this._patternIgnore = new RegExp(`^(?:${this.ignoreTagName})$`, this.ignoreCaseTagName ? 'i' : '')) : null;
1037
+ return this.ignoreTagName ? this._patternIgnore ||= new RegExp(`^(?:${this.ignoreTagName})$`, this.ignoreCaseTagName ? 'i' : '') : null;
1042
1038
  }
1043
1039
  set source(value) {
1044
1040
  if (value !== this._source) {
@@ -1153,7 +1149,7 @@ class XmlElement {
1153
1149
  }
1154
1150
  getTagOffset(replacement, options = {}) {
1155
1151
  if (!this.tagVoid || this._prevTagName && !XmlWriter.isTagVoid(this.documentType, this._prevTagName)) {
1156
- options.parser || (options.parser = this.parser);
1152
+ options.parser ||= this.parser;
1157
1153
  if (!this.node.append) {
1158
1154
  return XmlWriter.getTagOffset(this.innerXml, replacement, options);
1159
1155
  }
@@ -1265,7 +1261,6 @@ class XmlElement {
1265
1261
  return [source.substring(0, startIndex) + leading + outerXml + trailing + source.substring(endIndex), outerXml];
1266
1262
  }
1267
1263
  write(source, invalid) {
1268
- var _a, _b;
1269
1264
  if (!this._modified) {
1270
1265
  return ['', ''];
1271
1266
  }
@@ -1280,7 +1275,7 @@ class XmlElement {
1280
1275
  let position;
1281
1276
  if (XmlWriter.isTagVoid(this.documentType, tagName)) {
1282
1277
  const openTag = [];
1283
- const pattern = CACHE_TAGNAME[_a = tagName + flags + '1'] || (CACHE_TAGNAME[_a] = new RegExp(`<${escapeTagName(tagName)}[\\s|>]`, flags));
1278
+ const pattern = CACHE_TAGNAME[tagName + flags + '1'] ||= new RegExp(`<${escapeTagName(tagName)}[\\s|>]`, flags);
1284
1279
  let openCount = 0, match;
1285
1280
  pattern.lastIndex = 0;
1286
1281
  while (match = pattern.exec(source)) {
@@ -1303,7 +1298,7 @@ class XmlElement {
1303
1298
  }
1304
1299
  else if (id || isIndex(tagIndex) && isCount(tagCount)) {
1305
1300
  complete: {
1306
- const pattern = CACHE_TAGNAME[_b = tagName + flags + '2'] || (CACHE_TAGNAME[_b] = new RegExp(`<(?:${escapeTagName(tagName)}[\\s|>]|/${escapeTagName(tagName)}\\s*>)`, flags));
1301
+ const pattern = CACHE_TAGNAME[tagName + flags + '2'] ||= new RegExp(`<(?:${escapeTagName(tagName)}[\\s|>]|/${escapeTagName(tagName)}\\s*>)`, flags);
1307
1302
  const openTag = [];
1308
1303
  let openCount = 0, found, match;
1309
1304
  pattern.lastIndex = 0;
@@ -1348,7 +1343,7 @@ class XmlElement {
1348
1343
  }
1349
1344
  }
1350
1345
  }
1351
- if (position || (position = this.findIndexOf(source))) {
1346
+ if (position ||= this.findIndexOf(source)) {
1352
1347
  if (remove) {
1353
1348
  position.remove = true;
1354
1349
  }
@@ -1408,7 +1403,7 @@ class XmlElement {
1408
1403
  }
1409
1404
  const tagName = this.tagName;
1410
1405
  if (value !== tagName) {
1411
- this._prevTagName || (this._prevTagName = tagName);
1406
+ this._prevTagName ||= tagName;
1412
1407
  this._tagName = value;
1413
1408
  if (!CACHE_TAGVOID[this.documentType]) {
1414
1409
  this._tagVoid = null;