@seafile/seafile-editor 0.3.76
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/README.md +119 -0
- package/TODO.md +55 -0
- package/dist/components/add-formula-dialog.js +135 -0
- package/dist/components/add-image-dialog.js +78 -0
- package/dist/components/add-link-dialog.js +148 -0
- package/dist/components/comment-dialog.js +107 -0
- package/dist/components/comment-panel.js +452 -0
- package/dist/components/context-menu.js +112 -0
- package/dist/components/detail-list-view.js +119 -0
- package/dist/components/generate-share-link.js +412 -0
- package/dist/components/internal-link-dialog.js +96 -0
- package/dist/components/loading.js +32 -0
- package/dist/components/markdown-lint.js +87 -0
- package/dist/components/modal-portal.js +46 -0
- package/dist/components/outline.js +130 -0
- package/dist/components/participants-list.js +126 -0
- package/dist/components/related-files-list.js +75 -0
- package/dist/components/shortcut-dialog.js +167 -0
- package/dist/components/side-panel.js +175 -0
- package/dist/components/toast/alert.js +150 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/toast.js +179 -0
- package/dist/components/toast/toastManager.js +158 -0
- package/dist/components/toast/toaster.js +76 -0
- package/dist/components/toolbar.js +235 -0
- package/dist/components/topbar-component/button-group.js +31 -0
- package/dist/components/topbar-component/editor-toolbar.js +545 -0
- package/dist/components/topbar-component/file-info.js +65 -0
- package/dist/components/topbar-component/header-list.js +128 -0
- package/dist/components/topbar-component/icon-button.js +99 -0
- package/dist/components/topbar-component/insert-file.js +67 -0
- package/dist/components/topbar-component/table-toolbar.js +175 -0
- package/dist/components/topbar-component/upload-img.js +122 -0
- package/dist/components/user-help.js +205 -0
- package/dist/css/diff-viewer.css +105 -0
- package/dist/css/history-viewer.css +104 -0
- package/dist/css/keyboard-shortcuts.css +59 -0
- package/dist/css/layout.css +110 -0
- package/dist/css/markdown-viewer-slate/file-tags-list.css +76 -0
- package/dist/css/markdown-viewer.css +69 -0
- package/dist/css/plaineditor/markdown-editor.css +12 -0
- package/dist/css/react-mentions-default-style.js +72 -0
- package/dist/css/related-files-list.css +56 -0
- package/dist/css/richeditor/comments-list.css +184 -0
- package/dist/css/richeditor/detail-list-view.css +114 -0
- package/dist/css/richeditor/document-info.css +57 -0
- package/dist/css/richeditor/formula.css +19 -0
- package/dist/css/richeditor/image.css +141 -0
- package/dist/css/richeditor/link.css +7 -0
- package/dist/css/richeditor/navbar-imgbutton.css +79 -0
- package/dist/css/richeditor/participants-list.css +22 -0
- package/dist/css/richeditor/rich-editor-main.css +42 -0
- package/dist/css/richeditor/right-panel.css +84 -0
- package/dist/css/richeditor/side-panel.css +190 -0
- package/dist/css/richeditor/table.css +57 -0
- package/dist/css/richeditor/textlink-hovermenu.css +47 -0
- package/dist/css/richeditor/tree-view.css +67 -0
- package/dist/css/topbar.css +400 -0
- package/dist/editor/code-highlight-package.js +27 -0
- package/dist/editor/controller/block-element-controller.js +376 -0
- package/dist/editor/controller/inline-element-controller.js +129 -0
- package/dist/editor/controller/normalize-controller.js +107 -0
- package/dist/editor/controller/shortcut-controller.js +394 -0
- package/dist/editor/controller/void-element-controller.js +12 -0
- package/dist/editor/custom/custom.js +17 -0
- package/dist/editor/custom/get-event-transfer.js +34 -0
- package/dist/editor/custom/getNodesByTypeAtRange.js +69 -0
- package/dist/editor/custom/insertNodes.js +140 -0
- package/dist/editor/custom/is-empty-paragraph.js +13 -0
- package/dist/editor/custom/set-event-transfer.js +31 -0
- package/dist/editor/custom/split-nodes-at-point.js +162 -0
- package/dist/editor/custom/unwrap-node-by-type-at-range.js +81 -0
- package/dist/editor/editor-component/check-list-item.js +64 -0
- package/dist/editor/editor-component/code-block.js +150 -0
- package/dist/editor/editor-component/formula.js +79 -0
- package/dist/editor/editor-component/image.js +215 -0
- package/dist/editor/editor-component/link.js +11 -0
- package/dist/editor/editor-component/table.js +172 -0
- package/dist/editor/editor-component/textlink-hovermenu.js +136 -0
- package/dist/editor/editor-plugin.js +249 -0
- package/dist/editor/editor-utils/block-element-utils/blockquote-utils.js +96 -0
- package/dist/editor/editor-utils/block-element-utils/code-utils.js +162 -0
- package/dist/editor/editor-utils/block-element-utils/formula-utils.js +58 -0
- package/dist/editor/editor-utils/block-element-utils/index.js +38 -0
- package/dist/editor/editor-utils/block-element-utils/list-utils.js +398 -0
- package/dist/editor/editor-utils/block-element-utils/table-utils.js +418 -0
- package/dist/editor/editor-utils/common-editor-utils.js +587 -0
- package/dist/editor/editor-utils/inline-element-utils/index.js +95 -0
- package/dist/editor/editor-utils/mark-utils.js +25 -0
- package/dist/editor/editor-utils/range-utils.js +9 -0
- package/dist/editor/editor-utils/selection-utils.js +33 -0
- package/dist/editor/editor-utils/text-utils.js +130 -0
- package/dist/editor/editor.js +66 -0
- package/dist/editor/element-model/blockquote.js +16 -0
- package/dist/editor/element-model/image.js +19 -0
- package/dist/editor/element-model/link.js +19 -0
- package/dist/editor/element-model/table.js +50 -0
- package/dist/editor/element-model/text.js +13 -0
- package/dist/editor/load-script.js +83 -0
- package/dist/editor/plain-markdown-editor.js +324 -0
- package/dist/editor/rich-markdown-editor.js +580 -0
- package/dist/editor/seafile-editor.js +326 -0
- package/dist/editor/simple-editor.js +245 -0
- package/dist/editor-api.js +261 -0
- package/dist/index.css +97 -0
- package/dist/lib/slate-hyperscript/creators.js +263 -0
- package/dist/lib/slate-hyperscript/hyperscript.js +92 -0
- package/dist/lib/slate-hyperscript/index.js +3 -0
- package/dist/lib/slate-hyperscript/tokens.js +102 -0
- package/dist/lib/unified/index.js +470 -0
- package/dist/lib/vfile/core.js +172 -0
- package/dist/lib/vfile/index.js +48 -0
- package/dist/seafile-editor-chooser.js +45 -0
- package/dist/seafile-markdown-editor.js +301 -0
- package/dist/seafile-markdown-viewer.js +79 -0
- package/dist/seafile-simple-editor.js +56 -0
- package/dist/utils/copy-to-clipboard.js +47 -0
- package/dist/utils/deserialize-html.js +282 -0
- package/dist/utils/diff/compare-strings.js +46 -0
- package/dist/utils/diff/diff.js +855 -0
- package/dist/utils/diff/index.js +2 -0
- package/dist/utils/render-slate.js +219 -0
- package/dist/utils/seafile-markdown2html.js +62 -0
- package/dist/utils/slate2markdown/deserialize.js +689 -0
- package/dist/utils/slate2markdown/index.js +3 -0
- package/dist/utils/slate2markdown/serialize.js +407 -0
- package/dist/utils/utils.js +28 -0
- package/dist/viewer/diff-viewer.js +98 -0
- package/dist/viewer/markdown-viewer.js +139 -0
- package/dist/viewer/slate-viewer.js +73 -0
- package/dist/viewer/viewer-formula.js +67 -0
- package/dist/viewer/viewer-image.js +93 -0
- package/dist/viewer/viewer-outline.js +118 -0
- package/package.json +215 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +45 -0
- package/public/locales/cs/seafile-editor.json +169 -0
- package/public/locales/de/seafile-editor.json +169 -0
- package/public/locales/en/seafile-editor.json +222 -0
- package/public/locales/es/seafile-editor.json +169 -0
- package/public/locales/es-AR/seafile-editor.json +169 -0
- package/public/locales/es-MX/seafile-editor.json +169 -0
- package/public/locales/fr/seafile-editor.json +169 -0
- package/public/locales/it/seafile-editor.json +169 -0
- package/public/locales/ru/seafile-editor.json +169 -0
- package/public/locales/zh-CN/seafile-editor.json +219 -0
- package/public/manifest.json +15 -0
- package/public/media/scripts/mathjax/tex-svg.js +1 -0
- package/public/media/seafile-editor-font/iconfont.eot +0 -0
- package/public/media/seafile-editor-font/iconfont.svg +164 -0
- package/public/media/seafile-editor-font/iconfont.ttf +0 -0
- package/public/media/seafile-editor-font/iconfont.woff +0 -0
- package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
- package/public/media/seafile-editor-font.css +201 -0
- package/public/media/seafile-logo.png +0 -0
- package/public/media/seafile-ui.css +11169 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import deselectCurrent from 'toggle-selection';
|
|
2
|
+
|
|
3
|
+
function copy(text) {
|
|
4
|
+
var reselectPrevious,
|
|
5
|
+
range,
|
|
6
|
+
selection,
|
|
7
|
+
mark,
|
|
8
|
+
success = false;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
reselectPrevious = deselectCurrent();
|
|
12
|
+
range = document.createRange();
|
|
13
|
+
selection = document.getSelection();
|
|
14
|
+
mark = document.createElement('span');
|
|
15
|
+
mark.textContent = text;
|
|
16
|
+
document.body.appendChild(mark);
|
|
17
|
+
range.selectNode(mark);
|
|
18
|
+
selection.addRange(range);
|
|
19
|
+
var successful = document.execCommand('copy');
|
|
20
|
+
|
|
21
|
+
if (!successful) {
|
|
22
|
+
console.log('copy command was unsuccessful');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
success = true;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error('unable to copy using execCommand');
|
|
28
|
+
} finally {
|
|
29
|
+
if (selection) {
|
|
30
|
+
if (typeof selection.removeRange == 'function') {
|
|
31
|
+
selection.removeRange(range);
|
|
32
|
+
} else {
|
|
33
|
+
selection.removeAllRanges();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (mark) {
|
|
38
|
+
document.body.removeChild(mark);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
reselectPrevious();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return success;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default copy;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { jsx } from '../lib/slate-hyperscript/';
|
|
2
|
+
import { generateTableRow, generateTableCell } from '../editor/element-model/table';
|
|
3
|
+
var ELEMENT_TAGS = {
|
|
4
|
+
A: function A(el) {
|
|
5
|
+
return {
|
|
6
|
+
type: 'link',
|
|
7
|
+
data: {
|
|
8
|
+
href: el.getAttribute('href')
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
BLOCKQUOTE: function BLOCKQUOTE() {
|
|
13
|
+
return {
|
|
14
|
+
type: 'blockquote'
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
H1: function H1() {
|
|
18
|
+
return {
|
|
19
|
+
type: 'header_one'
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
H2: function H2() {
|
|
23
|
+
return {
|
|
24
|
+
type: 'header_two'
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
H3: function H3() {
|
|
28
|
+
return {
|
|
29
|
+
type: 'header_three'
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
H4: function H4() {
|
|
33
|
+
return {
|
|
34
|
+
type: 'header_four'
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
H5: function H5() {
|
|
38
|
+
return {
|
|
39
|
+
type: 'header_five'
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
H6: function H6() {
|
|
43
|
+
return {
|
|
44
|
+
type: 'header_six'
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
IMG: function IMG(el) {
|
|
48
|
+
return {
|
|
49
|
+
type: 'image',
|
|
50
|
+
children: [{
|
|
51
|
+
text: ''
|
|
52
|
+
}],
|
|
53
|
+
data: {
|
|
54
|
+
src: el.getAttribute('src')
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
LI: function LI() {
|
|
59
|
+
return {
|
|
60
|
+
type: 'list_item',
|
|
61
|
+
data: {}
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
OL: function OL() {
|
|
65
|
+
return {
|
|
66
|
+
type: 'ordered_list'
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
P: function P() {
|
|
70
|
+
return {
|
|
71
|
+
type: 'paragraph'
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
UL: function UL() {
|
|
75
|
+
return {
|
|
76
|
+
type: 'unordered_list'
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
TABLE: function TABLE() {
|
|
80
|
+
return {
|
|
81
|
+
type: 'table'
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
BR: function BR() {
|
|
85
|
+
return {
|
|
86
|
+
text: ''
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var HEADER_LIST = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
|
|
91
|
+
var TEXT_TAGS = {
|
|
92
|
+
CODE: function CODE() {
|
|
93
|
+
return {
|
|
94
|
+
CODE: true
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
DEL: function DEL() {
|
|
98
|
+
return {
|
|
99
|
+
DELETE: true
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
EM: function EM() {
|
|
103
|
+
return {
|
|
104
|
+
ITALIC: true
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
I: function I() {
|
|
108
|
+
return {
|
|
109
|
+
ITALIC: true
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
STRONG: function STRONG() {
|
|
113
|
+
return {
|
|
114
|
+
BOLD: true
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
INS: function INS() {
|
|
118
|
+
return {
|
|
119
|
+
INS: true
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var parseTable = function parseTable(el) {
|
|
125
|
+
if (el.parentNode.nodeName !== 'BODY') {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var tableWidth = 0;
|
|
130
|
+
Array.from(el.rows[0].childNodes).forEach(function (cell, index) {
|
|
131
|
+
if (cell.nodeName === 'TD' || cell.nodeName === 'TH') {
|
|
132
|
+
tableWidth += Number(cell.getAttribute('colspan')) || 1;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
var rowList = [];
|
|
136
|
+
|
|
137
|
+
for (var rowIndex = 0; rowIndex < el.rows.length; rowIndex++) {
|
|
138
|
+
var cells = el.rows[rowIndex].cells;
|
|
139
|
+
var cellsList = [];
|
|
140
|
+
|
|
141
|
+
for (var columnIndex = 0; columnIndex < cells.length; columnIndex++) {
|
|
142
|
+
var cell = cells[columnIndex];
|
|
143
|
+
cellsList.push(generateTableCell({
|
|
144
|
+
children: [{
|
|
145
|
+
type: 'paragraph',
|
|
146
|
+
children: [{
|
|
147
|
+
text: cell.textContent
|
|
148
|
+
}]
|
|
149
|
+
}]
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (cellsList.length < tableWidth) {
|
|
154
|
+
var count = tableWidth - cellsList.length;
|
|
155
|
+
|
|
156
|
+
for (var i = 0; i < count; i++) {
|
|
157
|
+
cellsList.push(generateTableCell({
|
|
158
|
+
children: [{
|
|
159
|
+
type: 'paragraph',
|
|
160
|
+
children: [{
|
|
161
|
+
text: ''
|
|
162
|
+
}]
|
|
163
|
+
}]
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
rowList.push(generateTableRow({
|
|
169
|
+
children: cellsList
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return rowList;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
var deserializeHtml = function deserializeHtml(el) {
|
|
177
|
+
if (el.nodeType === 3) {
|
|
178
|
+
// remove \n character
|
|
179
|
+
if (el.textContent === '\n' || el.textContent === '\r') {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (el.parentElement.nodeName === 'BODY') {
|
|
184
|
+
var text = el.textContent.replace(/(\n|\r\n)/g, '');
|
|
185
|
+
if (text.length === 0) return null;
|
|
186
|
+
return {
|
|
187
|
+
type: 'paragraph',
|
|
188
|
+
children: [{
|
|
189
|
+
text: text
|
|
190
|
+
}]
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return el.textContent;
|
|
195
|
+
} else if (el.nodeType !== 1) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var nodeName = el.nodeName;
|
|
200
|
+
var parent = el;
|
|
201
|
+
var children = Array.from(parent.childNodes).map(deserializeHtml).flat(); // deserialize task list
|
|
202
|
+
|
|
203
|
+
if (nodeName === 'LI') {
|
|
204
|
+
if (el.className && el.className.indexOf('task-list-item') >= 0) {
|
|
205
|
+
return jsx('element', {
|
|
206
|
+
data: {
|
|
207
|
+
checked: false
|
|
208
|
+
},
|
|
209
|
+
type: 'list_item'
|
|
210
|
+
}, children);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (nodeName === 'PRE' && el.childNodes[0] && el.childNodes[0].nodeName === 'CODE') {
|
|
215
|
+
// deserialize code block
|
|
216
|
+
var code = el.childNodes[0];
|
|
217
|
+
var codeChildren = [];
|
|
218
|
+
code.childNodes.forEach(function (codeLine, index) {
|
|
219
|
+
if (codeLine.innerText) {
|
|
220
|
+
codeChildren.push({
|
|
221
|
+
type: 'code_line',
|
|
222
|
+
children: [{
|
|
223
|
+
text: codeLine.innerText
|
|
224
|
+
}]
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
data: {
|
|
230
|
+
syntax: null
|
|
231
|
+
},
|
|
232
|
+
children: codeChildren,
|
|
233
|
+
type: 'code_block'
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (el.nodeName === 'BODY') {
|
|
238
|
+
return jsx('fragment', {}, children);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (ELEMENT_TAGS[nodeName]) {
|
|
242
|
+
var attrs = ELEMENT_TAGS[nodeName](el);
|
|
243
|
+
|
|
244
|
+
if (nodeName === 'IMG') {
|
|
245
|
+
return jsx('element', attrs, [{
|
|
246
|
+
text: ''
|
|
247
|
+
}]);
|
|
248
|
+
} // modify BR into an empty text node
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
if (nodeName === 'BR') {
|
|
252
|
+
return '';
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (nodeName === 'TABLE') {
|
|
256
|
+
return jsx('element', attrs, parseTable(el));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (nodeName === 'A' || HEADER_LIST.includes(nodeName)) {
|
|
260
|
+
return jsx('element', attrs, [{
|
|
261
|
+
text: el.textContent
|
|
262
|
+
}]);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return jsx('element', attrs, children);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (TEXT_TAGS[nodeName]) {
|
|
269
|
+
var _attrs = TEXT_TAGS[nodeName](el);
|
|
270
|
+
|
|
271
|
+
return children.map(function (child) {
|
|
272
|
+
return jsx('text', _attrs, child);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return children;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
export var htmlDeserializer = function htmlDeserializer(html) {
|
|
280
|
+
var parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
281
|
+
return deserializeHtml(parsed.body);
|
|
282
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function compareTwoStrings(str1, str2) {
|
|
2
|
+
if (!str1.length && !str2.length) return 1; // if both are empty strings
|
|
3
|
+
|
|
4
|
+
if (!str1.length || !str2.length) return 0; // if only one is empty string
|
|
5
|
+
|
|
6
|
+
if (str1.toUpperCase() === str2.toUpperCase()) return 1; // identical
|
|
7
|
+
|
|
8
|
+
if (str1.length === 1 && str2.length === 1) return 0; // both are 1-letter strings
|
|
9
|
+
|
|
10
|
+
var pairs1 = wordLetterPairs(str1);
|
|
11
|
+
var pairs2 = wordLetterPairs(str2);
|
|
12
|
+
var union = pairs1.length + pairs2.length;
|
|
13
|
+
var intersection = 0;
|
|
14
|
+
pairs1.forEach(function (pair1) {
|
|
15
|
+
for (var i = 0, pair2; pair2 = pairs2[i]; i++) {
|
|
16
|
+
if (pair1 !== pair2) continue;
|
|
17
|
+
intersection++;
|
|
18
|
+
pairs2.splice(i, 1);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return intersection * 2 / union;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function flattenDeep(arr) {
|
|
26
|
+
return Array.isArray(arr) ? arr.reduce(function (a, b) {
|
|
27
|
+
return a.concat(flattenDeep(b));
|
|
28
|
+
}, []) : [arr];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function letterPairs(str) {
|
|
32
|
+
var pairs = [];
|
|
33
|
+
|
|
34
|
+
for (var i = 0, max = str.length - 1; i < max; i++) {
|
|
35
|
+
pairs[i] = str.substring(i, i + 2);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return pairs;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function wordLetterPairs(str) {
|
|
42
|
+
var pairs = str.toUpperCase().split(' ').map(letterPairs);
|
|
43
|
+
return flattenDeep(pairs);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { compareTwoStrings };
|