1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var util = require('@spare/util');
|
6 | var enumChars = require('@spare/enum-chars');
|
7 |
|
8 | const indexNonTab = tx => {
|
9 | let i = 0;
|
10 |
|
11 | for (let {
|
12 | length
|
13 | } = tx; i < length; i++) if (!util.isTab(tx.charAt(i))) return i;
|
14 |
|
15 | return i;
|
16 | };
|
17 |
|
18 | const afterNonTab = tx => tx.substring(util.deNaTab(tx));
|
19 |
|
20 | function narrow(tx, lb, rb) {
|
21 | const [li, ri] = [tx.indexOf(lb), tx.lastIndexOf(rb)];
|
22 | return li > 0 && ri > 0 ? tx.slice(li, ri + rb.length) : tx;
|
23 | }
|
24 |
|
25 | function narrowExclude(tx, lb, rb) {
|
26 | const [li, ri] = [tx.indexOf(lb), tx.lastIndexOf(rb)];
|
27 | return li && ri ? tx.slice(li + lb.length, ri) : tx;
|
28 | }
|
29 |
|
30 | const trim = Function.prototype.call.bind(String.prototype.trim);
|
31 |
|
32 | const wL = (tx = '') => {
|
33 | console.log(tx);
|
34 | };
|
35 |
|
36 | const tag = (label, item) => {
|
37 | const i = util.deNaTab(label);
|
38 | let [key, text] = [util.endsBracs(label) ? label : `${label.substring(0, i)}[${label.substring(i)}]`, `${item}`];
|
39 |
|
40 | if (text.includes('\n')) {
|
41 | const t = ' '.repeat(i);
|
42 | text = (text.endsWith('}') || text.endsWith(']')) && !text.endsWith(']]') ? util.afterNaTab(text.split(enumChars.RN).map(x => t + x).join(enumChars.RN)) : ['', ...text.split(enumChars.RN).map(x => t + enumChars.TB + x), t].join(enumChars.RN);
|
43 | }
|
44 |
|
45 | return `${key} (${text})`;
|
46 | };
|
47 |
|
48 | exports.afterNonTab = afterNonTab;
|
49 | exports.indexNonTab = indexNonTab;
|
50 | exports.narrow = narrow;
|
51 | exports.narrowExclude = narrowExclude;
|
52 | exports.tag = tag;
|
53 | exports.trim = trim;
|
54 | exports.wL = wL;
|