xshell 0.0.10 → 0.0.14

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/prototype.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.is_codepoint_fullwidth = exports.to_json_safely = exports.to_json = exports.BRACKETS = exports.QUOTES = exports.CJK = exports.to_getter_property_descriptors = exports.to_method_property_descriptors = exports.colors = exports.EMOJI_REGEX = void 0;
3
+ exports.is_codepoint_fullwidth = exports.to_json_safely = exports.to_json = exports.brackets = exports.quotes = exports.cjk = exports.to_getter_property_descriptors = exports.to_method_property_descriptors = exports.chalk = exports.emoji_regex = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
6
  const upath_1 = (0, tslib_1.__importDefault)(require("upath"));
@@ -8,11 +8,12 @@ const upath_1 = (0, tslib_1.__importDefault)(require("upath"));
8
8
  const byte_size_1 = (0, tslib_1.__importDefault)(require("byte-size"));
9
9
  const emoji_regex_1 = (0, tslib_1.__importDefault)(require("emoji-regex"));
10
10
  const strip_ansi_1 = (0, tslib_1.__importDefault)(require("strip-ansi"));
11
- const safe_1 = (0, tslib_1.__importDefault)(require("colors/safe"));
12
- exports.colors = safe_1.default;
13
- exports.EMOJI_REGEX = (0, emoji_regex_1.default)();
11
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
12
+ exports.chalk = chalk_1.default;
13
+ exports.emoji_regex = (0, emoji_regex_1.default)();
14
14
  function to_method_property_descriptors(methods) {
15
- return Object.fromEntries(Object.entries(methods).map(([name, value]) => ([name, {
15
+ return Object.fromEntries(Object.entries(methods)
16
+ .map(([name, value]) => ([name, {
16
17
  configurable: true,
17
18
  writable: true,
18
19
  enumerable: false,
@@ -21,42 +22,44 @@ function to_method_property_descriptors(methods) {
21
22
  }
22
23
  exports.to_method_property_descriptors = to_method_property_descriptors;
23
24
  function to_getter_property_descriptors(getters) {
24
- return Object.fromEntries(Object.entries(getters).map(([name, get]) => ([name, {
25
+ return Object.fromEntries(Object.entries(getters)
26
+ .map(([name, get]) => ([name, {
25
27
  configurable: true,
26
28
  enumerable: false,
27
29
  get,
28
30
  }])));
29
31
  }
30
32
  exports.to_getter_property_descriptors = to_getter_property_descriptors;
31
- exports.CJK = '([\u2e80-\u9fff\uf900-\ufaff])';
32
- exports.QUOTES = {
33
- SINGLE: "'",
34
- DOUBLE: '"',
35
- BACKTICK: '`',
33
+ exports.cjk = '([\u2e80-\u9fff\uf900-\ufaff])';
34
+ exports.quotes = {
35
+ single: "'",
36
+ double: '"',
37
+ backtick: '`',
36
38
  };
37
- exports.BRACKETS = {
38
- ROUND: ['(', ')'],
39
- SQUARE: ['[', ']'],
40
- CURLY: ['{', '}'],
41
- POINTY: ['<', '>'],
42
- CORNER: ['「', '」'],
43
- FAT: ['【', '】'],
44
- TORTOISE_SHELL: ['〔', '〕'],
39
+ exports.brackets = {
40
+ round: ['(', ')'],
41
+ square: ['[', ']'],
42
+ curly: ['{', '}'],
43
+ pointy: ['<', '>'],
44
+ corner: ['「', '」'],
45
+ fat: ['【', '】'],
46
+ tortoise_shell: ['〔', '〕'],
45
47
  };
48
+ const color_map = Object.fromEntries(['red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_'].map(color => [color, `${color.slice(0, -1)}Bright`]));
46
49
  // ------------------------------------ String.prototype
47
50
  Object.defineProperties(String.prototype, {
48
51
  ...to_getter_property_descriptors({
49
52
  width() {
50
- const s = (0, strip_ansi_1.default)(this.replace(exports.EMOJI_REGEX, ' '));
53
+ const s = (0, strip_ansi_1.default)(this.replace(exports.emoji_regex, ' '));
51
54
  let width = 0;
52
55
  for (let i = 0; i < s.length; i++) {
53
56
  const code = s.codePointAt(i);
54
- if ((code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters
55
- code >= 0x300 && code <= 0x36F // Ignore combining characters
57
+ if ((code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters
58
+ code >= 0x300 && code <= 0x36f // ignore combining characters
56
59
  )
57
60
  continue;
58
- // Surrogates
59
- if (code > 0xFFFF)
61
+ // surrogates
62
+ if (code > 0xffff)
60
63
  i++;
61
64
  width += is_codepoint_fullwidth(code) ? 2 : 1;
62
65
  }
@@ -80,7 +83,7 @@ Object.defineProperties(String.prototype, {
80
83
  code >= 0x300 && code <= 0x36F // Ignore combining characters
81
84
  )
82
85
  continue;
83
- // Surrogates (codepoint need two UTF-16 encoding units, thus here skip the first in order to prevent repeated counting)
86
+ // surrogates (codepoint need two utf-16 encoding units, thus here skip the first in order to prevent repeated counting)
84
87
  if (code > 0xFFFF)
85
88
  i++;
86
89
  const w = is_codepoint_fullwidth(code) ? 2 : 1;
@@ -111,8 +114,7 @@ Object.defineProperties(String.prototype, {
111
114
  to_regx(preservations, flags = '') {
112
115
  const preserved_chars = new Set(preservations);
113
116
  const replace_chars = Array.prototype.filter.call('|\\{}()[]^$+*?.-', (c) => !preserved_chars.has(c))
114
- .map((c) => c === ']' ? '\\]' : c)
115
- .join('');
117
+ .map((c) => c === ']' ? '\\]' : c).join('');
116
118
  return new RegExp(this.replace(new RegExp(`[${replace_chars}]`, 'g'), '\\$&'), flags);
117
119
  },
118
120
  to_bool() {
@@ -139,7 +141,10 @@ Object.defineProperties(String.prototype, {
139
141
  placeholder_name = placeholder_name.slice(0, -1);
140
142
  optional = true;
141
143
  }
142
- $placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ? placeholder_pattern.bracket() + (optional ? '?' : '') : '(.*?)');
144
+ $placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ?
145
+ `${placeholder_pattern.bracket()}${optional ? '?' : ''}`
146
+ :
147
+ '(.*?)');
143
148
  return '';
144
149
  });
145
150
  add_part(last_end);
@@ -152,11 +157,13 @@ Object.defineProperties(String.prototype, {
152
157
  const matches = pattern_regx.exec(this);
153
158
  if (!matches)
154
159
  return this;
155
- const placeholders = Object.fromEntries(Object.entries($placeholders).map(([name, $i]) => ([
160
+ const placeholders = Object.fromEntries(Object.entries($placeholders)
161
+ .map(([name, $i]) => [
156
162
  [name, matches[$i]],
157
- [name + '.before', matches[$i - 1] || ''],
158
- [name + '.after', matches[$i + 1] || ''],
159
- ])).flat());
163
+ [`${name}.before`, matches[$i - 1] || ''],
164
+ [`${name}.after`, matches[$i + 1] || ''],
165
+ ])
166
+ .flat());
160
167
  // --- convert pattern_ to replacement_str, if transformer exists then apply on placeholder
161
168
  last_end = 0;
162
169
  let replacement_parts = [];
@@ -191,28 +198,32 @@ Object.defineProperties(String.prototype, {
191
198
  placeholder_name = placeholder_name.slice(0, -1);
192
199
  optional = true;
193
200
  }
194
- $placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ? placeholder_pattern.bracket() + (optional ? '?' : '') : '(.*?)');
201
+ $placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ?
202
+ `${placeholder_pattern.bracket()}${optional ? '?' : ''}`
203
+ :
204
+ '(.*?)');
195
205
  return '';
196
206
  });
197
207
  add_part(last_end);
198
208
  // convert last (.*?) to greedy, to make .{suffix} work
199
209
  regx_parts = regx_parts.filter(part => part);
200
- if (regx_parts.last === '(.*?)')
210
+ if (regx_parts[regx_parts.length - 1] === '(.*?)')
201
211
  regx_parts[regx_parts.length - 1] = '(.*)';
202
212
  const pattern_regx = new RegExp(regx_parts.join(''), flags);
203
213
  // --- match original string based on pattern_regx, and get result to build placeholders dict
204
214
  const matches = pattern_regx.exec(this);
205
215
  if (!matches)
206
216
  return {};
207
- return Object.fromEntries(Object.entries($placeholders).map(([name, $i]) => ([name, matches[$i] || ''])));
217
+ return Object.fromEntries(Object.entries($placeholders)
218
+ .map(([name, $i]) => [name, matches[$i] || '']));
208
219
  },
209
- quote(type = 'SINGLE') {
210
- if (type === 'PSH')
211
- return '& ' + this.quote();
212
- return this.surround(exports.QUOTES[type]);
220
+ quote(type = 'single') {
221
+ if (type === 'psh')
222
+ return `& ${this.quote()}`;
223
+ return this.surround(exports.quotes[type]);
213
224
  },
214
- bracket(shape = 'ROUND') {
215
- return this.surround(...exports.BRACKETS[shape]);
225
+ bracket(shape = 'round') {
226
+ return this.surround(...exports.brackets[shape]);
216
227
  },
217
228
  surround(left, right) {
218
229
  return left + this + (right || left);
@@ -258,8 +269,11 @@ Object.defineProperties(String.prototype, {
258
269
  to_base64() {
259
270
  return Buffer.from(this).toString('base64');
260
271
  },
261
- decode_base64() {
262
- return Buffer.from(this, 'base64').toString();
272
+ decode_base64(buffer = false) {
273
+ const buf = Buffer.from(this, 'base64');
274
+ if (buffer)
275
+ return buf;
276
+ return buf.toString();
263
277
  },
264
278
  strip_ansi() {
265
279
  return (0, strip_ansi_1.default)(this);
@@ -269,30 +283,34 @@ Object.defineProperties(String.prototype, {
269
283
  return this;
270
284
  let text_;
271
285
  text_ = this
272
- .replace(new RegExp(exports.CJK + `(['"])`, 'g'), '$1 $2')
273
- .replace(new RegExp(`(['"])` + exports.CJK, 'g'), '$1 $2')
286
+ .replace(new RegExp(exports.cjk + `(['"])`, 'g'), '$1 $2')
287
+ .replace(new RegExp(`(['"])` + exports.cjk, 'g'), '$1 $2')
274
288
  .replace(/(["']+)\s*(.+?)\s*(["']+)/g, '$1$2$3')
275
- .replace(new RegExp(exports.CJK + '([\\+\\-\\*\\/=&\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')
276
- .replace(new RegExp('([A-Za-z0-9])([\\+\\-\\*\\/=&\\\\\\|<>])' + exports.CJK, 'g'), '$1 $2 $3');
289
+ .replace(new RegExp(exports.cjk + '([\\+\\-\\*\\/=&\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')
290
+ .replace(new RegExp('([A-Za-z0-9])([\\+\\-\\*\\/=&\\\\\\|<>])' + exports.cjk, 'g'), '$1 $2 $3');
277
291
  const textBak = text_;
278
- text_ = text_.replace(new RegExp(exports.CJK + '([\\(\\[\\{<\u201c]+(.*?)[\\)\\]\\}>\u201d]+)' + exports.CJK, 'g'), '$1 $2 $4');
292
+ text_ = text_.replace(new RegExp(exports.cjk + '([\\(\\[\\{<\u201c]+(.*?)[\\)\\]\\}>\u201d]+)' + exports.cjk, 'g'), '$1 $2 $4');
279
293
  if (text_ === textBak)
280
294
  text_ = text_
281
- .replace(new RegExp(exports.CJK + '([\\(\\[\\{<\u201c>])', 'g'), '$1 $2')
282
- .replace(new RegExp('([\\)\\]\\}>\u201d<])' + exports.CJK, 'g'), '$1 $2');
295
+ .replace(new RegExp(exports.cjk + '([\\(\\[\\{<\u201c>])', 'g'), '$1 $2')
296
+ .replace(new RegExp('([\\)\\]\\}>\u201d<])' + exports.cjk, 'g'), '$1 $2');
283
297
  return text_
284
298
  // eslint-disable-next-line no-useless-escape
285
299
  .replace(/([\(\[\{<\u201c]+)(\s*)(.+?)(\s*)([\)\]\}>\u201d]+)/g, '$1$3$5')
286
- .replace(new RegExp(exports.CJK + '([~!;:,\\.\\?\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')
287
- .replace(new RegExp(exports.CJK + '([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])', 'g'), '$1 $2')
288
- .replace(new RegExp('([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])' + exports.CJK, 'g'), '$1 $2');
300
+ .replace(new RegExp(exports.cjk + '([~!;:,\\.\\?\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')
301
+ .replace(new RegExp(exports.cjk + '([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])', 'g'), '$1 $2')
302
+ .replace(new RegExp('([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])' + exports.cjk, 'g'), '$1 $2');
289
303
  }
290
304
  }),
291
- // ------------ colors
292
- ...Object.fromEntries(['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'grey', 'underline'].map(color => ([color, {
305
+ // ------------ chalk colors
306
+ ...Object.fromEntries([
307
+ 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'grey',
308
+ 'red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_',
309
+ 'underline',
310
+ ].map(color => ([color, {
293
311
  configurable: true,
294
312
  get() {
295
- return safe_1.default[color](this);
313
+ return chalk_1.default[color_map[color] || color](this);
296
314
  }
297
315
  }]))),
298
316
  // ------------ file path ops
@@ -371,13 +389,13 @@ Object.defineProperties(Date.prototype, to_method_property_descriptors({
371
389
  Object.defineProperties(Number.prototype, to_method_property_descriptors({
372
390
  to_fsize_str(units = 'iec') {
373
391
  const { value, unit } = (0, byte_size_1.default)(this, { units });
374
- return `${value} ${unit.rm('i').toUpperCase()}`;
392
+ return `${value} ${unit.rm('i')}`;
375
393
  },
376
394
  to_bin_str() {
377
395
  return `0b${this.toString(2)}`;
378
396
  },
379
397
  to_hex_str(length) {
380
- const s = this.toString(16).toUpperCase();
398
+ const s = this.toString(16);
381
399
  if (!length)
382
400
  length = Math.ceil(s.length / 4) * 4;
383
401
  return `0x${'0'.repeat(length - s.length)}${s}`;
@@ -407,7 +425,6 @@ Object.defineProperties(Array.prototype, {
407
425
  trim_lines({ trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false } = {}) {
408
426
  if (!this.length)
409
427
  return this;
410
- // eslint-disable-next-line @typescript-eslint/no-this-alias
411
428
  let lines = this;
412
429
  if (trim_line)
413
430
  lines = lines.map(line => line.trim());
@@ -438,7 +455,8 @@ Object.defineProperties(Array.prototype, {
438
455
  return this.map(line => character.repeat(width) + line);
439
456
  },
440
457
  indent2to4() {
441
- return this.split_indents().map(line => ' '.repeat(Math.floor(line.indent / 2) * 4) + line.text);
458
+ return this.split_indents()
459
+ .map(line => ' '.repeat(Math.floor(line.indent / 2) * 4) + line.text);
442
460
  },
443
461
  join_lines(append = true) {
444
462
  return `${this.join('\n')}${append ? '\n' : ''}`;
@@ -446,7 +464,7 @@ Object.defineProperties(Array.prototype, {
446
464
  })
447
465
  });
448
466
  function to_json(obj, replacer) {
449
- return JSON.stringify(obj, replacer, 4);
467
+ return JSON.stringify(obj, replacer, 4) + '\n';
450
468
  }
451
469
  exports.to_json = to_json;
452
470
  function to_json_safely(obj, replacer) {
@@ -457,48 +475,49 @@ function to_json_safely(obj, replacer) {
457
475
  }
458
476
  exports.to_json_safely = to_json_safely;
459
477
  function is_codepoint_fullwidth(codepoint) {
460
- // Code points are derived from:
478
+ // code points are derived from:
461
479
  // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
462
480
  return (!Number.isNaN(codepoint) &&
463
481
  codepoint >= 0x1100 &&
464
- (codepoint <= 0x115F || // Hangul Jamo
482
+ (codepoint <= 0x115f || // hangul jamo
483
+ codepoint === 0x201c || codepoint === 0x201d || //
465
484
  codepoint === 0x2026 || // …
466
- codepoint === 0x203B || // ※
467
- // Arrows
485
+ codepoint === 0x203b || // ※
486
+ // arrows
468
487
  (0x2190 <= codepoint && codepoint <= 0x21FF) ||
469
- codepoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
470
- codepoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
488
+ codepoint === 0x2329 || // left-pointing angle bracket
489
+ codepoint === 0x232a || // right-pointing angle bracket
471
490
  // ①
472
- (0x2460 <= codepoint && codepoint <= 0x24FF) ||
473
- // Box Drawing
474
- (0x2500 <= codepoint && codepoint <= 0x257F) ||
475
- // Shapes, Symbols, …
476
- (0x2580 <= codepoint && codepoint <= 0x2BEF) ||
477
- // CJK Radicals Supplement .. Enclosed CJK Letters and Months
478
- (0x2E80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303F) ||
479
- // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
480
- (0x3250 <= codepoint && codepoint <= 0x4DBF) ||
481
- // CJK Unified Ideographs .. Yi Radicals
491
+ (0x2460 <= codepoint && codepoint <= 0x24ff) ||
492
+ // box drawing
493
+ (0x2500 <= codepoint && codepoint <= 0x257f) ||
494
+ // shapes, symbols, …
495
+ (0x2580 <= codepoint && codepoint <= 0x2bef) ||
496
+ // cjk radicals supplement .. enclosed cjk letters and months
497
+ (0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||
498
+ // enclosed cjk letters and months .. cjk unified ideographs extension a
499
+ (0x3250 <= codepoint && codepoint <= 0x4dbf) ||
500
+ // cjk unified ideographs .. yi radicals
482
501
  (0x4E00 <= codepoint && codepoint <= 0xA4C6) ||
483
- // Hangul Jamo Extended-A
484
- (0xA960 <= codepoint && codepoint <= 0xA97C) ||
485
- // Hangul Syllables
486
- (0xAC00 <= codepoint && codepoint <= 0xD7A3) ||
487
- // CJK Compatibility Ideographs
488
- (0xF900 <= codepoint && codepoint <= 0xFAFF) ||
489
- // Vertical Forms
490
- (0xFE10 <= codepoint && codepoint <= 0xFE19) ||
491
- // CJK Compatibility Forms .. Small Form Variants
492
- (0xFE30 <= codepoint && codepoint <= 0xFE6B) ||
493
- // Halfwidth and Fullwidth Forms
494
- (0xFF01 <= codepoint && codepoint <= 0xFF60) ||
495
- (0xFFE0 <= codepoint && codepoint <= 0xFFE6) ||
496
- // Kana Supplement
497
- (0x1B000 <= codepoint && codepoint <= 0x1B001) ||
498
- // Enclosed Ideographic Supplement
499
- (0x1F200 <= codepoint && codepoint <= 0x1F251) ||
500
- // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
501
- (0x20000 <= codepoint && codepoint <= 0x3FFFD)));
502
+ // hangul jamo extended-a
503
+ (0xa960 <= codepoint && codepoint <= 0xa97c) ||
504
+ // hangul syllables
505
+ (0xac00 <= codepoint && codepoint <= 0xd7a3) ||
506
+ // cjk compatibility ideographs
507
+ (0xf900 <= codepoint && codepoint <= 0xfaff) ||
508
+ // vertical forms
509
+ (0xfe10 <= codepoint && codepoint <= 0xfe19) ||
510
+ // cjk compatibility forms .. small form variants
511
+ (0xfe30 <= codepoint && codepoint <= 0xfe6b) ||
512
+ // halfwidth and fullwidth forms
513
+ (0xff01 <= codepoint && codepoint <= 0xff60) ||
514
+ (0xffe0 <= codepoint && codepoint <= 0xffe6) ||
515
+ // kana supplement
516
+ (0x1b000 <= codepoint && codepoint <= 0x1b001) ||
517
+ // enclosed ideographic supplement
518
+ (0x1f200 <= codepoint && codepoint <= 0x1f251) ||
519
+ // cjk unified ideographs extension b .. tertiary ideographic plane
520
+ (0x20000 <= codepoint && codepoint <= 0x3fffd)));
502
521
  }
503
522
  exports.is_codepoint_fullwidth = is_codepoint_fullwidth;
504
523
  //# sourceMappingURL=prototype.js.map