wikiparser-node 0.5.0 → 0.6.1

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 (63) hide show
  1. package/config/default.json +129 -66
  2. package/config/zhwiki.json +4 -4
  3. package/index.js +74 -65
  4. package/lib/element.js +125 -152
  5. package/lib/node.js +251 -223
  6. package/lib/ranges.js +2 -2
  7. package/lib/text.js +64 -64
  8. package/lib/title.js +8 -7
  9. package/mixin/hidden.js +2 -0
  10. package/mixin/sol.js +1 -2
  11. package/package.json +4 -3
  12. package/parser/brackets.js +8 -2
  13. package/parser/externalLinks.js +1 -1
  14. package/parser/hrAndDoubleUnderscore.js +4 -4
  15. package/parser/links.js +7 -7
  16. package/parser/table.js +12 -10
  17. package/src/arg.js +53 -48
  18. package/src/atom/index.js +7 -5
  19. package/src/attribute.js +91 -80
  20. package/src/charinsert.js +91 -0
  21. package/src/converter.js +22 -11
  22. package/src/converterFlags.js +72 -62
  23. package/src/converterRule.js +49 -49
  24. package/src/extLink.js +30 -28
  25. package/src/gallery.js +56 -32
  26. package/src/hasNowiki/index.js +42 -0
  27. package/src/hasNowiki/pre.js +40 -0
  28. package/src/heading.js +15 -11
  29. package/src/html.js +38 -38
  30. package/src/imageParameter.js +64 -48
  31. package/src/imagemap.js +205 -0
  32. package/src/imagemapLink.js +43 -0
  33. package/src/index.js +222 -124
  34. package/src/link/category.js +4 -8
  35. package/src/link/file.js +95 -59
  36. package/src/link/galleryImage.js +74 -10
  37. package/src/link/index.js +61 -39
  38. package/src/magicLink.js +21 -22
  39. package/src/nested/choose.js +24 -0
  40. package/src/nested/combobox.js +23 -0
  41. package/src/nested/index.js +88 -0
  42. package/src/nested/references.js +23 -0
  43. package/src/nowiki/comment.js +17 -17
  44. package/src/nowiki/dd.js +2 -2
  45. package/src/nowiki/doubleUnderscore.js +14 -14
  46. package/src/nowiki/index.js +12 -0
  47. package/src/onlyinclude.js +10 -8
  48. package/src/paramTag/index.js +83 -0
  49. package/src/paramTag/inputbox.js +42 -0
  50. package/src/parameter.js +32 -18
  51. package/src/syntax.js +9 -1
  52. package/src/table/index.js +33 -32
  53. package/src/table/td.js +51 -57
  54. package/src/table/tr.js +6 -6
  55. package/src/tagPair/ext.js +58 -40
  56. package/src/tagPair/include.js +1 -1
  57. package/src/tagPair/index.js +21 -20
  58. package/src/transclude.js +158 -143
  59. package/tool/index.js +720 -439
  60. package/util/base.js +17 -0
  61. package/util/debug.js +1 -1
  62. package/util/diff.js +1 -1
  63. package/util/string.js +20 -20
package/util/base.js ADDED
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 是否是普通对象
5
+ * @param {*} obj 对象
6
+ */
7
+ const isPlainObject = obj => Boolean(obj) && Object.getPrototypeOf(obj).constructor === Object;
8
+
9
+ /**
10
+ * 延时
11
+ * @param {number} t 秒数
12
+ */
13
+ const sleep = t => new Promise(resolve => {
14
+ setTimeout(resolve, t * 1000);
15
+ });
16
+
17
+ module.exports = {isPlainObject, sleep};
package/util/debug.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * 定制TypeError消息
5
5
  * @param {Function} constructor 类
6
- * @param {string} method 方法名称
6
+ * @param {string} method
7
7
  * @param {...string} args 可接受的参数类型
8
8
  * @throws `TypeError`
9
9
  */
package/util/diff.js CHANGED
@@ -18,7 +18,7 @@ const cmd = (command, args) => new Promise(resolve => {
18
18
 
19
19
  /**
20
20
  * 清除进程并返回
21
- * @param {any} val 返回值
21
+ * @param {*} val 返回值
22
22
  */
23
23
  const r = val => {
24
24
  clearTimeout(timer);
package/util/string.js CHANGED
@@ -1,11 +1,7 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * optionally convert to lower cases
5
- * @param {string} val 属性值
6
- * @param {string|undefined} i 是否对大小写不敏感
7
- */
8
- const toCase = (val, i) => i ? val.toLowerCase() : val;
3
+ const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])'
4
+ + '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
9
5
 
10
6
  /**
11
7
  * remove half-parsed comment-like tokens
@@ -36,16 +32,6 @@ const print = (childNodes, opt = {}) => {
36
32
  */
37
33
  const escapeRegExp = str => str.replaceAll(/[\\{}()|.?*+^$[\]]/gu, '\\$&');
38
34
 
39
- /**
40
- * extract effective wikitext
41
- * @param {(string|AstNode)[]} childNodes a Token's contents
42
- * @param {string} separator delimiter between nodes
43
- */
44
- const text = (childNodes, separator = '') => {
45
- const AstNode = require('../lib/node');
46
- return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
47
- };
48
-
49
35
  /**
50
36
  * a more sophisticated string-explode function
51
37
  * @param {string} start start syntax of a nested AST node
@@ -76,6 +62,23 @@ const explode = (start, end, separator, str) => {
76
62
  return exploded;
77
63
  };
78
64
 
65
+ /**
66
+ * optionally convert to lower cases
67
+ * @param {string} val 属性值
68
+ * @param {string|undefined} i 是否对大小写不敏感
69
+ */
70
+ const toCase = (val, i) => i ? val.toLowerCase() : val;
71
+
72
+ /**
73
+ * extract effective wikitext
74
+ * @param {(string|AstNode)[]} childNodes a Token's contents
75
+ * @param {string} separator delimiter between nodes
76
+ */
77
+ const text = (childNodes, separator = '') => {
78
+ const AstNode = require('../lib/node');
79
+ return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
80
+ };
81
+
79
82
  /**
80
83
  * escape newlines
81
84
  * @param {string} str 原字符串
@@ -99,7 +102,4 @@ const normalizeSpace = token => {
99
102
  }
100
103
  };
101
104
 
102
- const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])'
103
- + '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
104
-
105
- module.exports = {toCase, removeComment, print, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};
105
+ module.exports = {extUrlChar, removeComment, print, escapeRegExp, explode, toCase, text, noWrap, normalizeSpace};