dobo 2.0.1 → 2.2.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 (194) hide show
  1. package/.github/FUNDING.yml +0 -0
  2. package/.github/workflows/repo-lockdown.yml +0 -0
  3. package/.jsdoc.conf.json +0 -0
  4. package/LICENSE +0 -0
  5. package/README.md +2 -2
  6. package/docs/Dobo.html +0 -0
  7. package/docs/data/search.json +0 -0
  8. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  9. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  10. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  11. package/docs/global.html +0 -0
  12. package/docs/index.html +0 -0
  13. package/docs/index.js.html +0 -0
  14. package/docs/lib_collect-connections.js.html +0 -0
  15. package/docs/lib_collect-drivers.js.html +0 -0
  16. package/docs/lib_collect-features.js.html +0 -0
  17. package/docs/lib_collect-schemas.js.html +0 -0
  18. package/docs/lib_index.js.html +0 -0
  19. package/docs/method_model_create.js.html +0 -0
  20. package/docs/method_model_drop.js.html +0 -0
  21. package/docs/method_model_exists.js.html +0 -0
  22. package/docs/method_record_count.js.html +0 -0
  23. package/docs/method_record_create.js.html +0 -0
  24. package/docs/method_record_find-all.js.html +0 -0
  25. package/docs/method_record_find-one.js.html +0 -0
  26. package/docs/method_record_find.js.html +0 -0
  27. package/docs/method_record_get.js.html +0 -0
  28. package/docs/method_record_remove.js.html +0 -0
  29. package/docs/method_record_update.js.html +0 -0
  30. package/docs/method_record_upsert.js.html +0 -0
  31. package/docs/method_sanitize_body.js.html +0 -0
  32. package/docs/method_sanitize_date.js.html +0 -0
  33. package/docs/method_sanitize_id.js.html +0 -0
  34. package/docs/method_validate.js.html +0 -0
  35. package/docs/module-Lib.html +0 -0
  36. package/docs/scripts/core.js +476 -477
  37. package/docs/scripts/core.min.js +0 -0
  38. package/docs/scripts/resize.js +36 -36
  39. package/docs/scripts/search.js +105 -105
  40. package/docs/scripts/search.min.js +0 -0
  41. package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
  42. package/docs/scripts/third-party/fuse.js +1 -1
  43. package/docs/scripts/third-party/hljs-line-num-original.js +282 -285
  44. package/docs/scripts/third-party/hljs-line-num.js +1 -1
  45. package/docs/scripts/third-party/hljs-original.js +1195 -1202
  46. package/docs/scripts/third-party/hljs.js +1 -1
  47. package/docs/scripts/third-party/popper.js +1 -1
  48. package/docs/scripts/third-party/tippy.js +1 -1
  49. package/docs/scripts/third-party/tocbot.js +508 -509
  50. package/docs/scripts/third-party/tocbot.min.js +0 -0
  51. package/docs/static/bitcoin.jpeg +0 -0
  52. package/docs/static/home.md +0 -0
  53. package/docs/static/logo-ecosystem.png +0 -0
  54. package/docs/static/logo.png +0 -0
  55. package/docs/styles/clean-jsdoc-theme-base.css +0 -0
  56. package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
  57. package/docs/styles/clean-jsdoc-theme-light.css +0 -0
  58. package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  59. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  60. package/docs/styles/clean-jsdoc-theme.min.css +0 -0
  61. package/extend/bajo/intl/en-US.json +66 -28
  62. package/extend/bajo/intl/id.json +55 -27
  63. package/extend/bajoCli/applet/clear-record.js +22 -0
  64. package/extend/bajoCli/applet/connection.js +0 -0
  65. package/extend/bajoCli/applet/count-record.js +27 -0
  66. package/extend/bajoCli/applet/create-aggregate.js +33 -0
  67. package/extend/bajoCli/applet/create-histogram.js +33 -0
  68. package/extend/bajoCli/applet/create-record.js +39 -0
  69. package/extend/bajoCli/applet/find-record.js +27 -0
  70. package/extend/bajoCli/applet/get-record.js +27 -0
  71. package/extend/bajoCli/applet/lib/post-process.js +10 -17
  72. package/extend/bajoCli/applet/model.js +22 -0
  73. package/extend/bajoCli/applet/rebuild-model.js +91 -0
  74. package/extend/bajoCli/applet/remove-record.js +27 -0
  75. package/extend/bajoCli/applet/update-record.js +44 -0
  76. package/extend/bajoCli/applet.js +0 -0
  77. package/extend/dobo/driver/memory.js +170 -0
  78. package/extend/dobo/feature/created-at.js +9 -7
  79. package/extend/dobo/feature/dt.js +0 -0
  80. package/extend/dobo/feature/immutable.js +30 -0
  81. package/extend/dobo/feature/int-id.js +0 -0
  82. package/extend/dobo/feature/removed-at.js +32 -54
  83. package/extend/dobo/feature/updated-at.js +14 -12
  84. package/extend/waibuMpa/route/attachment/@model/@id/@field/@file.js +2 -6
  85. package/extend/waibuStatic/virtual.json +0 -0
  86. package/index.js +284 -371
  87. package/lib/collect-connections.js +49 -21
  88. package/lib/collect-drivers.js +19 -33
  89. package/lib/collect-features.js +24 -17
  90. package/lib/collect-models.js +321 -0
  91. package/lib/factory/action.js +161 -0
  92. package/lib/factory/connection.js +62 -0
  93. package/lib/factory/driver.js +372 -0
  94. package/lib/factory/feature.js +33 -0
  95. package/lib/factory/model/_util.js +402 -0
  96. package/lib/factory/model/build.js +15 -0
  97. package/lib/factory/model/clear-record.js +17 -0
  98. package/lib/factory/model/count-record.js +17 -0
  99. package/lib/factory/model/create-aggregate.js +17 -0
  100. package/lib/factory/model/create-attachment.js +29 -0
  101. package/lib/factory/model/create-histogram.js +17 -0
  102. package/lib/factory/model/create-record.js +35 -0
  103. package/lib/factory/model/drop.js +15 -0
  104. package/lib/factory/model/exists.js +21 -0
  105. package/lib/factory/model/find-all-record.js +71 -0
  106. package/lib/factory/model/find-attachment.js +29 -0
  107. package/lib/factory/model/find-one-record.js +19 -0
  108. package/{method/record/find.js → lib/factory/model/find-record.js} +103 -115
  109. package/lib/factory/model/get-attachment.js +15 -0
  110. package/lib/factory/model/get-record.js +79 -0
  111. package/lib/factory/model/list-attachment.js +37 -0
  112. package/lib/{add-fixtures.js → factory/model/load-fixtures.js} +69 -67
  113. package/lib/factory/model/remove-attachment.js +15 -0
  114. package/lib/factory/model/remove-record.js +59 -0
  115. package/lib/factory/model/sanitize-body.js +56 -0
  116. package/lib/factory/model/sanitize-id.js +7 -0
  117. package/lib/factory/model/sanitize-record.js +26 -0
  118. package/lib/factory/model/update-attachment.js +9 -0
  119. package/lib/factory/model/update-record.js +81 -0
  120. package/lib/factory/model/upsert-record.js +95 -0
  121. package/{method → lib/factory/model}/validate.js +38 -52
  122. package/lib/factory/model.js +150 -0
  123. package/lib/index.js +0 -0
  124. package/package.json +8 -4
  125. package/wiki/APPLETS.md +0 -0
  126. package/wiki/CHANGES.md +50 -0
  127. package/wiki/CONFIG.md +0 -0
  128. package/wiki/CONTRIBUTING.md +0 -0
  129. package/wiki/DEV-GUIDE.md +0 -0
  130. package/wiki/ECOSYSTEM.md +0 -0
  131. package/wiki/GETTING-STARTED.md +10 -10
  132. package/wiki/QUERY-LANGUAGE.md +0 -0
  133. package/wiki/USER-GUIDE.md +0 -0
  134. package/extend/bajoCli/applet/model-clear.js +0 -11
  135. package/extend/bajoCli/applet/model-rebuild.js +0 -101
  136. package/extend/bajoCli/applet/record-create.js +0 -43
  137. package/extend/bajoCli/applet/record-find.js +0 -28
  138. package/extend/bajoCli/applet/record-get.js +0 -24
  139. package/extend/bajoCli/applet/record-remove.js +0 -24
  140. package/extend/bajoCli/applet/record-update.js +0 -47
  141. package/extend/bajoCli/applet/schema.js +0 -22
  142. package/extend/bajoCli/applet/stat-count.js +0 -24
  143. package/lib/build-bulk-action.js +0 -12
  144. package/lib/check-unique.js +0 -39
  145. package/lib/collect-schemas.js +0 -91
  146. package/lib/exec-feature-hook.js +0 -13
  147. package/lib/exec-validation.js +0 -21
  148. package/lib/generic-prop-sanitizer.js +0 -32
  149. package/lib/handle-attachment-upload.js +0 -16
  150. package/lib/mem-db/conn-sanitizer.js +0 -8
  151. package/lib/mem-db/instantiate.js +0 -41
  152. package/lib/mem-db/method/model/clear.js +0 -6
  153. package/lib/mem-db/method/model/create.js +0 -5
  154. package/lib/mem-db/method/model/drop.js +0 -5
  155. package/lib/mem-db/method/model/exists.js +0 -5
  156. package/lib/mem-db/method/record/create.js +0 -12
  157. package/lib/mem-db/method/record/find.js +0 -20
  158. package/lib/mem-db/method/record/get.js +0 -9
  159. package/lib/mem-db/method/record/remove.js +0 -13
  160. package/lib/mem-db/method/record/update.js +0 -15
  161. package/lib/mem-db/method/stat/count.js +0 -11
  162. package/lib/mem-db/start.js +0 -25
  163. package/lib/merge-attachment-info.js +0 -16
  164. package/lib/multi-rel-rows.js +0 -42
  165. package/lib/resolve-method.js +0 -16
  166. package/lib/sanitize-schema.js +0 -198
  167. package/lib/single-rel-rows.js +0 -38
  168. package/method/attachment/copy-uploaded.js +0 -34
  169. package/method/attachment/create.js +0 -29
  170. package/method/attachment/find.js +0 -27
  171. package/method/attachment/get-path.js +0 -12
  172. package/method/attachment/get.js +0 -12
  173. package/method/attachment/pre-check.js +0 -9
  174. package/method/attachment/remove.js +0 -11
  175. package/method/attachment/update.js +0 -7
  176. package/method/bulk/create.js +0 -46
  177. package/method/model/clear.js +0 -22
  178. package/method/model/create.js +0 -32
  179. package/method/model/drop.js +0 -31
  180. package/method/model/exists.js +0 -37
  181. package/method/record/clear.js +0 -24
  182. package/method/record/count.js +0 -66
  183. package/method/record/create.js +0 -111
  184. package/method/record/find-all.js +0 -41
  185. package/method/record/find-one.js +0 -70
  186. package/method/record/get.js +0 -89
  187. package/method/record/remove.js +0 -72
  188. package/method/record/update.js +0 -104
  189. package/method/record/upsert.js +0 -51
  190. package/method/sanitize/body.js +0 -85
  191. package/method/sanitize/date.js +0 -27
  192. package/method/sanitize/id.js +0 -17
  193. package/method/stat/aggregate.js +0 -23
  194. package/method/stat/histogram.js +0 -26
@@ -1,369 +1,366 @@
1
1
  // jshint multistr:true
2
2
 
3
3
  (function (w, d) {
4
- 'use strict';
5
-
6
- var TABLE_NAME = 'hljs-ln',
7
- LINE_NAME = 'hljs-ln-line',
8
- CODE_BLOCK_NAME = 'hljs-ln-code',
9
- NUMBERS_BLOCK_NAME = 'hljs-ln-numbers',
10
- NUMBER_LINE_NAME = 'hljs-ln-n',
11
- DATA_ATTR_NAME = 'data-line-number',
12
- BREAK_LINE_REGEXP = /\r\n|\r|\n/g;
13
-
14
- if (w.hljs) {
15
- w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad;
16
- w.hljs.lineNumbersBlock = lineNumbersBlock;
17
- w.hljs.lineNumbersValue = lineNumbersValue;
18
-
19
- addStyles();
20
- } else {
21
- w.console.error('highlight.js not detected!');
4
+ 'use strict'
5
+
6
+ const TABLE_NAME = 'hljs-ln'
7
+ const LINE_NAME = 'hljs-ln-line'
8
+ const CODE_BLOCK_NAME = 'hljs-ln-code'
9
+ const NUMBERS_BLOCK_NAME = 'hljs-ln-numbers'
10
+ const NUMBER_LINE_NAME = 'hljs-ln-n'
11
+ const DATA_ATTR_NAME = 'data-line-number'
12
+ const BREAK_LINE_REGEXP = /\r\n|\r|\n/g
13
+
14
+ if (w.hljs) {
15
+ w.hljs.initLineNumbersOnLoad = initLineNumbersOnLoad
16
+ w.hljs.lineNumbersBlock = lineNumbersBlock
17
+ w.hljs.lineNumbersValue = lineNumbersValue
18
+
19
+ addStyles()
20
+ } else {
21
+ w.console.error('highlight.js not detected!')
22
+ }
23
+
24
+ function isHljsLnCodeDescendant (domElt) {
25
+ let curElt = domElt
26
+ while (curElt) {
27
+ if (curElt.className && curElt.className.indexOf('hljs-ln-code') !== -1) {
28
+ return true
29
+ }
30
+ curElt = curElt.parentNode
22
31
  }
32
+ return false
33
+ }
23
34
 
24
- function isHljsLnCodeDescendant(domElt) {
25
- var curElt = domElt;
26
- while (curElt) {
27
- if (curElt.className && curElt.className.indexOf('hljs-ln-code') !== -1) {
28
- return true;
29
- }
30
- curElt = curElt.parentNode;
31
- }
32
- return false;
35
+ function getHljsLnTable (hljsLnDomElt) {
36
+ let curElt = hljsLnDomElt
37
+ while (curElt.nodeName !== 'TABLE') {
38
+ curElt = curElt.parentNode
33
39
  }
34
-
35
- function getHljsLnTable(hljsLnDomElt) {
36
- var curElt = hljsLnDomElt;
37
- while (curElt.nodeName !== 'TABLE') {
38
- curElt = curElt.parentNode;
39
- }
40
- return curElt;
40
+ return curElt
41
+ }
42
+
43
+ // Function to workaround a copy issue with Microsoft Edge.
44
+ // Due to hljs-ln wrapping the lines of code inside a <table> element,
45
+ // itself wrapped inside a <pre> element, window.getSelection().toString()
46
+ // does not contain any line breaks. So we need to get them back using the
47
+ // rendered code in the DOM as reference.
48
+ function edgeGetSelectedCodeLines (selection) {
49
+ // current selected text without line breaks
50
+ const selectionText = selection.toString()
51
+
52
+ // get the <td> element wrapping the first line of selected code
53
+ let tdAnchor = selection.anchorNode
54
+ while (tdAnchor.nodeName !== 'TD') {
55
+ tdAnchor = tdAnchor.parentNode
41
56
  }
42
57
 
43
- // Function to workaround a copy issue with Microsoft Edge.
44
- // Due to hljs-ln wrapping the lines of code inside a <table> element,
45
- // itself wrapped inside a <pre> element, window.getSelection().toString()
46
- // does not contain any line breaks. So we need to get them back using the
47
- // rendered code in the DOM as reference.
48
- function edgeGetSelectedCodeLines(selection) {
49
- // current selected text without line breaks
50
- var selectionText = selection.toString();
51
-
52
- // get the <td> element wrapping the first line of selected code
53
- var tdAnchor = selection.anchorNode;
54
- while (tdAnchor.nodeName !== 'TD') {
55
- tdAnchor = tdAnchor.parentNode;
56
- }
57
-
58
- // get the <td> element wrapping the last line of selected code
59
- var tdFocus = selection.focusNode;
60
- while (tdFocus.nodeName !== 'TD') {
61
- tdFocus = tdFocus.parentNode;
62
- }
63
-
64
- // extract line numbers
65
- var firstLineNumber = parseInt(tdAnchor.dataset.lineNumber);
66
- var lastLineNumber = parseInt(tdFocus.dataset.lineNumber);
67
-
68
- // multi-lines copied case
69
- if (firstLineNumber != lastLineNumber) {
70
-
71
- var firstLineText = tdAnchor.textContent;
72
- var lastLineText = tdFocus.textContent;
73
-
74
- // if the selection was made backward, swap values
75
- if (firstLineNumber > lastLineNumber) {
76
- var tmp = firstLineNumber;
77
- firstLineNumber = lastLineNumber;
78
- lastLineNumber = tmp;
79
- tmp = firstLineText;
80
- firstLineText = lastLineText;
81
- lastLineText = tmp;
82
- }
83
-
84
- // discard not copied characters in first line
85
- while (selectionText.indexOf(firstLineText) !== 0) {
86
- firstLineText = firstLineText.slice(1);
87
- }
88
-
89
- // discard not copied characters in last line
90
- while (selectionText.lastIndexOf(lastLineText) === -1) {
91
- lastLineText = lastLineText.slice(0, -1);
92
- }
93
-
94
- // reconstruct and return the real copied text
95
- var selectedText = firstLineText;
96
- var hljsLnTable = getHljsLnTable(tdAnchor);
97
- for (var i = firstLineNumber + 1 ; i < lastLineNumber ; ++i) {
98
- var codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i]);
99
- var codeLineElt = hljsLnTable.querySelector(codeLineSel);
100
- selectedText += '\n' + codeLineElt.textContent;
101
- }
102
- selectedText += '\n' + lastLineText;
103
- return selectedText;
104
- // single copied line case
105
- } else {
106
- return selectionText;
107
- }
58
+ // get the <td> element wrapping the last line of selected code
59
+ let tdFocus = selection.focusNode
60
+ while (tdFocus.nodeName !== 'TD') {
61
+ tdFocus = tdFocus.parentNode
108
62
  }
109
63
 
110
- // ensure consistent code copy/paste behavior across all browsers
111
- // (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
112
- document.addEventListener('copy', function(e) {
113
- // get current selection
114
- var selection = window.getSelection();
115
- // override behavior when one wants to copy line of codes
116
- if (isHljsLnCodeDescendant(selection.anchorNode)) {
117
- var selectionText;
118
- // workaround an issue with Microsoft Edge as copied line breaks
119
- // are removed otherwise from the selection string
120
- if (window.navigator.userAgent.indexOf('Edge') !== -1) {
121
- selectionText = edgeGetSelectedCodeLines(selection);
122
- } else {
123
- // other browsers can directly use the selection string
124
- selectionText = selection.toString();
125
- }
126
- e.clipboardData.setData(
127
- 'text/plain',
128
- selectionText
129
- .replace(/(^\t)/gm, '')
130
- );
131
- e.preventDefault();
132
- }
133
- });
64
+ // extract line numbers
65
+ let firstLineNumber = parseInt(tdAnchor.dataset.lineNumber)
66
+ let lastLineNumber = parseInt(tdFocus.dataset.lineNumber)
67
+
68
+ // multi-lines copied case
69
+ if (firstLineNumber != lastLineNumber) {
70
+ let firstLineText = tdAnchor.textContent
71
+ let lastLineText = tdFocus.textContent
72
+
73
+ // if the selection was made backward, swap values
74
+ if (firstLineNumber > lastLineNumber) {
75
+ let tmp = firstLineNumber
76
+ firstLineNumber = lastLineNumber
77
+ lastLineNumber = tmp
78
+ tmp = firstLineText
79
+ firstLineText = lastLineText
80
+ lastLineText = tmp
81
+ }
82
+
83
+ // discard not copied characters in first line
84
+ while (selectionText.indexOf(firstLineText) !== 0) {
85
+ firstLineText = firstLineText.slice(1)
86
+ }
87
+
88
+ // discard not copied characters in last line
89
+ while (selectionText.lastIndexOf(lastLineText) === -1) {
90
+ lastLineText = lastLineText.slice(0, -1)
91
+ }
92
+
93
+ // reconstruct and return the real copied text
94
+ let selectedText = firstLineText
95
+ const hljsLnTable = getHljsLnTable(tdAnchor)
96
+ for (let i = firstLineNumber + 1; i < lastLineNumber; ++i) {
97
+ const codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i])
98
+ const codeLineElt = hljsLnTable.querySelector(codeLineSel)
99
+ selectedText += '\n' + codeLineElt.textContent
100
+ }
101
+ selectedText += '\n' + lastLineText
102
+ return selectedText
103
+ // single copied line case
104
+ } else {
105
+ return selectionText
106
+ }
107
+ }
108
+
109
+ // ensure consistent code copy/paste behavior across all browsers
110
+ // (see https://github.com/wcoder/highlightjs-line-numbers.js/issues/51)
111
+ document.addEventListener('copy', function (e) {
112
+ // get current selection
113
+ const selection = window.getSelection()
114
+ // override behavior when one wants to copy line of codes
115
+ if (isHljsLnCodeDescendant(selection.anchorNode)) {
116
+ let selectionText
117
+ // workaround an issue with Microsoft Edge as copied line breaks
118
+ // are removed otherwise from the selection string
119
+ if (window.navigator.userAgent.indexOf('Edge') !== -1) {
120
+ selectionText = edgeGetSelectedCodeLines(selection)
121
+ } else {
122
+ // other browsers can directly use the selection string
123
+ selectionText = selection.toString()
124
+ }
125
+ e.clipboardData.setData(
126
+ 'text/plain',
127
+ selectionText
128
+ .replace(/(^\t)/gm, '')
129
+ )
130
+ e.preventDefault()
131
+ }
132
+ })
134
133
 
135
- function addStyles () {
136
- var css = d.createElement('style');
137
- css.type = 'text/css';
138
- css.innerHTML = format(
139
- '.{0}{border-collapse:collapse}' +
134
+ function addStyles () {
135
+ const css = d.createElement('style')
136
+ css.type = 'text/css'
137
+ css.innerHTML = format(
138
+ '.{0}{border-collapse:collapse}' +
140
139
  '.{0} td{padding:0}' +
141
140
  '.{1}:before{content:attr({2})}',
142
- [
143
- TABLE_NAME,
144
- NUMBER_LINE_NAME,
145
- DATA_ATTR_NAME
146
- ]);
147
- d.getElementsByTagName('head')[0].appendChild(css);
141
+ [
142
+ TABLE_NAME,
143
+ NUMBER_LINE_NAME,
144
+ DATA_ATTR_NAME
145
+ ])
146
+ d.getElementsByTagName('head')[0].appendChild(css)
147
+ }
148
+
149
+ function initLineNumbersOnLoad (options) {
150
+ if (d.readyState === 'interactive' || d.readyState === 'complete') {
151
+ documentReady(options)
152
+ } else {
153
+ w.addEventListener('DOMContentLoaded', function () {
154
+ documentReady(options)
155
+ })
148
156
  }
157
+ }
149
158
 
150
- function initLineNumbersOnLoad (options) {
151
- if (d.readyState === 'interactive' || d.readyState === 'complete') {
152
- documentReady(options);
153
- } else {
154
- w.addEventListener('DOMContentLoaded', function () {
155
- documentReady(options);
156
- });
157
- }
158
- }
159
+ function documentReady (options) {
160
+ try {
161
+ const blocks = d.querySelectorAll('code.hljs,code.nohighlight')
159
162
 
160
- function documentReady (options) {
161
- try {
162
- var blocks = d.querySelectorAll('code.hljs,code.nohighlight');
163
-
164
- for (var i in blocks) {
165
- if (blocks.hasOwnProperty(i)) {
166
- if (!isPluginDisabledForBlock(blocks[i])) {
167
- lineNumbersBlock(blocks[i], options);
168
- }
169
- }
170
- }
171
- } catch (e) {
172
- w.console.error('LineNumbers error: ', e);
163
+ for (const i in blocks) {
164
+ if (blocks.hasOwnProperty(i)) {
165
+ if (!isPluginDisabledForBlock(blocks[i])) {
166
+ lineNumbersBlock(blocks[i], options)
167
+ }
173
168
  }
169
+ }
170
+ } catch (e) {
171
+ w.console.error('LineNumbers error: ', e)
174
172
  }
173
+ }
175
174
 
176
- function isPluginDisabledForBlock(element) {
177
- return element.classList.contains('nohljsln');
178
- }
175
+ function isPluginDisabledForBlock (element) {
176
+ return element.classList.contains('nohljsln')
177
+ }
179
178
 
180
- function lineNumbersBlock (element, options) {
181
- if (typeof element !== 'object') return;
179
+ function lineNumbersBlock (element, options) {
180
+ if (typeof element !== 'object') return
182
181
 
183
- async(function () {
184
- element.innerHTML = lineNumbersInternal(element, options);
185
- });
186
- }
182
+ async(function () {
183
+ element.innerHTML = lineNumbersInternal(element, options)
184
+ })
185
+ }
187
186
 
188
- function lineNumbersValue (value, options) {
189
- if (typeof value !== 'string') return;
187
+ function lineNumbersValue (value, options) {
188
+ if (typeof value !== 'string') return
190
189
 
191
- var element = document.createElement('code')
192
- element.innerHTML = value
190
+ const element = document.createElement('code')
191
+ element.innerHTML = value
193
192
 
194
- return lineNumbersInternal(element, options);
195
- }
193
+ return lineNumbersInternal(element, options)
194
+ }
196
195
 
197
- function lineNumbersInternal (element, options) {
196
+ function lineNumbersInternal (element, options) {
197
+ const internalOptions = mapOptions(element, options)
198
198
 
199
- var internalOptions = mapOptions(element, options);
199
+ duplicateMultilineNodes(element)
200
200
 
201
- duplicateMultilineNodes(element);
202
-
203
- return addLineNumbersBlockFor(element.innerHTML, internalOptions);
204
- }
201
+ return addLineNumbersBlockFor(element.innerHTML, internalOptions)
202
+ }
205
203
 
206
- function addLineNumbersBlockFor (inputHtml, options) {
207
- var lines = getLines(inputHtml);
204
+ function addLineNumbersBlockFor (inputHtml, options) {
205
+ const lines = getLines(inputHtml)
208
206
 
209
- // if last line contains only carriage return remove it
210
- if (lines[lines.length-1].trim() === '') {
211
- lines.pop();
212
- }
207
+ // if last line contains only carriage return remove it
208
+ if (lines[lines.length - 1].trim() === '') {
209
+ lines.pop()
210
+ }
213
211
 
214
- if (lines.length > 1 || options.singleLine) {
215
- var html = '';
212
+ if (lines.length > 1 || options.singleLine) {
213
+ let html = ''
216
214
 
217
- for (var i = 0, l = lines.length; i < l; i++) {
218
- html += format(
219
- '<tr>' +
215
+ for (let i = 0, l = lines.length; i < l; i++) {
216
+ html += format(
217
+ '<tr>' +
220
218
  '<td class="{0} {1}" {3}="{5}">' +
221
219
  '</td>' +
222
220
  '<td class="{0} {4}" {3}="{5}">' +
223
221
  '{6}' +
224
222
  '</td>' +
225
223
  '</tr>',
226
- [
227
- LINE_NAME,
228
- NUMBERS_BLOCK_NAME,
229
- NUMBER_LINE_NAME,
230
- DATA_ATTR_NAME,
231
- CODE_BLOCK_NAME,
232
- i + options.startFrom,
233
- lines[i].length > 0 ? lines[i] : ' '
234
- ]);
235
- }
236
-
237
- return format('<table class="{0}">{1}</table>', [ TABLE_NAME, html ]);
238
- }
239
-
240
- return inputHtml;
224
+ [
225
+ LINE_NAME,
226
+ NUMBERS_BLOCK_NAME,
227
+ NUMBER_LINE_NAME,
228
+ DATA_ATTR_NAME,
229
+ CODE_BLOCK_NAME,
230
+ i + options.startFrom,
231
+ lines[i].length > 0 ? lines[i] : ' '
232
+ ])
233
+ }
234
+
235
+ return format('<table class="{0}">{1}</table>', [TABLE_NAME, html])
241
236
  }
242
237
 
243
- /**
238
+ return inputHtml
239
+ }
240
+
241
+ /**
244
242
  * @param {HTMLElement} element Code block.
245
243
  * @param {Object} options External API options.
246
244
  * @returns {Object} Internal API options.
247
245
  */
248
- function mapOptions (element, options) {
249
- options = options || {};
250
- return {
251
- singleLine: getSingleLineOption(options),
252
- startFrom: getStartFromOption(element, options)
253
- };
246
+ function mapOptions (element, options) {
247
+ options = options || {}
248
+ return {
249
+ singleLine: getSingleLineOption(options),
250
+ startFrom: getStartFromOption(element, options)
254
251
  }
252
+ }
255
253
 
256
- function getSingleLineOption (options) {
257
- var defaultValue = false;
258
- if (!!options.singleLine) {
259
- return options.singleLine;
260
- }
261
- return defaultValue;
254
+ function getSingleLineOption (options) {
255
+ const defaultValue = false
256
+ if (options.singleLine) {
257
+ return options.singleLine
262
258
  }
259
+ return defaultValue
260
+ }
263
261
 
264
- function getStartFromOption (element, options) {
265
- var defaultValue = 1;
266
- var startFrom = defaultValue;
267
-
268
- if (isFinite(options.startFrom)) {
269
- startFrom = options.startFrom;
270
- }
262
+ function getStartFromOption (element, options) {
263
+ const defaultValue = 1
264
+ let startFrom = defaultValue
271
265
 
272
- // can be overridden because local option is priority
273
- var value = getAttribute(element, 'data-ln-start-from');
274
- if (value !== null) {
275
- startFrom = toNumber(value, defaultValue);
276
- }
266
+ if (isFinite(options.startFrom)) {
267
+ startFrom = options.startFrom
268
+ }
277
269
 
278
- return startFrom;
270
+ // can be overridden because local option is priority
271
+ const value = getAttribute(element, 'data-ln-start-from')
272
+ if (value !== null) {
273
+ startFrom = toNumber(value, defaultValue)
279
274
  }
280
275
 
281
- /**
276
+ return startFrom
277
+ }
278
+
279
+ /**
282
280
  * Recursive method for fix multi-line elements implementation in highlight.js
283
281
  * Doing deep passage on child nodes.
284
282
  * @param {HTMLElement} element
285
283
  */
286
- function duplicateMultilineNodes (element) {
287
- var nodes = element.childNodes;
288
- for (var node in nodes) {
289
- if (nodes.hasOwnProperty(node)) {
290
- var child = nodes[node];
291
- if (getLinesCount(child.textContent) > 0) {
292
- if (child.childNodes.length > 0) {
293
- duplicateMultilineNodes(child);
294
- } else {
295
- duplicateMultilineNode(child.parentNode);
296
- }
297
- }
298
- }
284
+ function duplicateMultilineNodes (element) {
285
+ const nodes = element.childNodes
286
+ for (const node in nodes) {
287
+ if (nodes.hasOwnProperty(node)) {
288
+ const child = nodes[node]
289
+ if (getLinesCount(child.textContent) > 0) {
290
+ if (child.childNodes.length > 0) {
291
+ duplicateMultilineNodes(child)
292
+ } else {
293
+ duplicateMultilineNode(child.parentNode)
294
+ }
299
295
  }
296
+ }
300
297
  }
298
+ }
301
299
 
302
- /**
300
+ /**
303
301
  * Method for fix multi-line elements implementation in highlight.js
304
302
  * @param {HTMLElement} element
305
303
  */
306
- function duplicateMultilineNode (element) {
307
- var className = element.className;
308
-
309
- if ( ! /hljs-/.test(className)) return;
304
+ function duplicateMultilineNode (element) {
305
+ const className = element.className
310
306
 
311
- var lines = getLines(element.innerHTML);
307
+ if (!/hljs-/.test(className)) return
312
308
 
313
- for (var i = 0, result = ''; i < lines.length; i++) {
314
- var lineText = lines[i].length > 0 ? lines[i] : ' ';
315
- result += format('<span class="{0}">{1}</span>\n', [ className, lineText ]);
316
- }
309
+ const lines = getLines(element.innerHTML)
317
310
 
318
- element.innerHTML = result.trim();
311
+ for (var i = 0, result = ''; i < lines.length; i++) {
312
+ const lineText = lines[i].length > 0 ? lines[i] : ' '
313
+ result += format('<span class="{0}">{1}</span>\n', [className, lineText])
319
314
  }
320
315
 
321
- function getLines (text) {
322
- if (text.length === 0) return [];
323
- return text.split(BREAK_LINE_REGEXP);
324
- }
316
+ element.innerHTML = result.trim()
317
+ }
325
318
 
326
- function getLinesCount (text) {
327
- return (text.trim().match(BREAK_LINE_REGEXP) || []).length;
328
- }
319
+ function getLines (text) {
320
+ if (text.length === 0) return []
321
+ return text.split(BREAK_LINE_REGEXP)
322
+ }
329
323
 
330
- ///
331
- /// HELPERS
332
- ///
324
+ function getLinesCount (text) {
325
+ return (text.trim().match(BREAK_LINE_REGEXP) || []).length
326
+ }
333
327
 
334
- function async (func) {
335
- w.setTimeout(func, 0);
336
- }
328
+ ///
329
+ /// HELPERS
330
+ ///
337
331
 
338
- /**
332
+ function async (func) {
333
+ w.setTimeout(func, 0)
334
+ }
335
+
336
+ /**
339
337
  * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript}
340
338
  * @param {string} format
341
339
  * @param {array} args
342
340
  */
343
- function format (format, args) {
344
- return format.replace(/\{(\d+)\}/g, function(m, n){
345
- return args[n] !== undefined ? args[n] : m;
346
- });
347
- }
341
+ function format (format, args) {
342
+ return format.replace(/\{(\d+)\}/g, function (m, n) {
343
+ return args[n] !== undefined ? args[n] : m
344
+ })
345
+ }
348
346
 
349
- /**
347
+ /**
350
348
  * @param {HTMLElement} element Code block.
351
349
  * @param {String} attrName Attribute name.
352
350
  * @returns {String} Attribute value or empty.
353
351
  */
354
- function getAttribute (element, attrName) {
355
- return element.hasAttribute(attrName) ? element.getAttribute(attrName) : null;
356
- }
352
+ function getAttribute (element, attrName) {
353
+ return element.hasAttribute(attrName) ? element.getAttribute(attrName) : null
354
+ }
357
355
 
358
- /**
356
+ /**
359
357
  * @param {String} str Source string.
360
358
  * @param {Number} fallback Fallback value.
361
359
  * @returns Parsed number or fallback value.
362
360
  */
363
- function toNumber (str, fallback) {
364
- if (!str) return fallback;
365
- var number = Number(str);
366
- return isFinite(number) ? number : fallback;
367
- }
368
-
369
- }(window, document));
361
+ function toNumber (str, fallback) {
362
+ if (!str) return fallback
363
+ const number = Number(str)
364
+ return isFinite(number) ? number : fallback
365
+ }
366
+ }(window, document))