reslop 0.1.1 → 0.1.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/lib/select.js CHANGED
@@ -20,12 +20,12 @@ const isRange = (sel) => {
20
20
  };
21
21
 
22
22
  const ordered = (sel) => {
23
- const a = sel.start;
24
- const b = sel.end;
25
- if (a.y < b.y) return [a, b];
26
- if (a.y > b.y) return [b, a];
27
- if (a.x <= b.x) return [a, b];
28
- return [b, a];
23
+ const start = sel.start;
24
+ const end = sel.end;
25
+ if (start.y < end.y) return { first: start, last: end };
26
+ if (start.y > end.y) return { first: end, last: start };
27
+ if (start.x <= end.x) return { first: start, last: end };
28
+ return { first: end, last: start };
29
29
  };
30
30
 
31
31
  const slicePlain = (plain, fromCol, toCol) => {
@@ -43,25 +43,25 @@ const slicePlain = (plain, fromCol, toCol) => {
43
43
  };
44
44
 
45
45
  const lineRange = (rowIndex, sel) => {
46
- const [a, b] = ordered(sel);
46
+ const { first, last } = ordered(sel);
47
47
  const y = rowIndex + 1;
48
- if (y < a.y || y > b.y) return null;
48
+ if (y < first.y || y > last.y) return null;
49
49
  let from = 0;
50
- let to = 1e9;
51
- if (y === a.y) from = a.x - 1;
52
- if (y === b.y) to = b.x;
50
+ let to = Infinity;
51
+ if (y === first.y) from = first.x - 1;
52
+ if (y === last.y) to = last.x;
53
53
  if (to <= from) return null;
54
54
  return { from, to };
55
55
  };
56
56
 
57
57
  const extractText = (rows, sel) => {
58
58
  if (!isRange(sel) || !rows || !rows.length) return '';
59
- const [a, b] = ordered(sel);
59
+ const { first, last } = ordered(sel);
60
60
  const lines = [];
61
- for (let r = a.y - 1; r <= b.y - 1; r++) {
62
- const range = lineRange(r, sel);
61
+ for (let row = first.y - 1; row <= last.y - 1; row++) {
62
+ const range = lineRange(row, sel);
63
63
  if (!range) continue;
64
- const plain = stripAnsi(rows[r] ?? '');
64
+ const plain = stripAnsi(rows[row] ?? '');
65
65
  const chunk = slicePlain(plain, range.from, range.to);
66
66
  lines.push(chunk.replace(/\s+$/g, ''));
67
67
  }
@@ -202,9 +202,7 @@ const overlayRows = (rows, sel) => {
202
202
 
203
203
  module.exports = {
204
204
  isRange,
205
- ordered,
206
205
  extractText,
207
- overlayRows,
208
206
  overlayRange,
209
- slicePlain,
207
+ overlayRows,
210
208
  };