@opensumi/ide-core-common 2.17.8 → 2.18.0
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/application-error.d.ts.map +1 -1
- package/lib/application-error.js +6 -0
- package/lib/application-error.js.map +1 -1
- package/lib/command.d.ts +1 -2
- package/lib/command.d.ts.map +1 -1
- package/lib/command.js +4 -4
- package/lib/command.js.map +1 -1
- package/lib/{utils/comparers.d.ts → comparers.d.ts} +1 -1
- package/lib/comparers.d.ts.map +1 -0
- package/lib/{utils/comparers.js → comparers.js} +5 -5
- package/lib/comparers.js.map +1 -0
- package/lib/const/application.d.ts +1 -0
- package/lib/const/application.d.ts.map +1 -1
- package/lib/const/application.js +3 -1
- package/lib/const/application.js.map +1 -1
- package/lib/const/index.d.ts +1 -1
- package/lib/const/index.d.ts.map +1 -1
- package/lib/const/index.js +1 -1
- package/lib/const/index.js.map +1 -1
- package/lib/crypto.d.ts +7 -0
- package/lib/{cryptr.d.ts.map → crypto.d.ts.map} +1 -1
- package/lib/crypto.js +6 -0
- package/lib/crypto.js.map +1 -0
- package/lib/electron.d.ts +2 -2
- package/lib/electron.d.ts.map +1 -1
- package/lib/electron.js.map +1 -1
- package/lib/event-bus/event-bus-types.d.ts +3 -4
- package/lib/event-bus/event-bus-types.d.ts.map +1 -1
- package/lib/event-bus/event-bus.d.ts +3 -3
- package/lib/event-bus/event-bus.d.ts.map +1 -1
- package/lib/event-bus/event-bus.js +3 -3
- package/lib/event-bus/event-bus.js.map +1 -1
- package/lib/event-bus/event-decorator.d.ts +1 -1
- package/lib/event-bus/event-decorator.d.ts.map +1 -1
- package/lib/event-bus/event-decorator.js +2 -2
- package/lib/event-bus/event-decorator.js.map +1 -1
- package/lib/hash-calculate/hash-calculate.d.ts.map +1 -1
- package/lib/hash-calculate/hash-calculate.js +2 -2
- package/lib/hash-calculate/hash-calculate.js.map +1 -1
- package/lib/index.d.ts +4 -18
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -18
- package/lib/index.js.map +1 -1
- package/lib/keyboard/keyboard-layout-provider.d.ts +1 -1
- package/lib/keyboard/keyboard-layout-provider.d.ts.map +1 -1
- package/lib/keyboard/keymap.js +4 -4
- package/lib/keyboard/keymap.js.map +1 -1
- package/lib/localize.d.ts.map +1 -1
- package/lib/localize.js +7 -7
- package/lib/localize.js.map +1 -1
- package/lib/log.d.ts +1 -1
- package/lib/log.d.ts.map +1 -1
- package/lib/{utils/markdown.d.ts → markdown.d.ts} +1 -1
- package/lib/markdown.d.ts.map +1 -0
- package/lib/{utils/markdown.js → markdown.js} +0 -0
- package/lib/markdown.js.map +1 -0
- package/lib/menu.d.ts +1 -1
- package/lib/menu.d.ts.map +1 -1
- package/lib/menu.js.map +1 -1
- package/lib/network.d.ts +2 -1
- package/lib/network.d.ts.map +1 -1
- package/lib/network.js +19 -18
- package/lib/network.js.map +1 -1
- package/lib/problem-matcher.d.ts +1 -3
- package/lib/problem-matcher.d.ts.map +1 -1
- package/lib/problem-matcher.js +5 -6
- package/lib/problem-matcher.js.map +1 -1
- package/lib/problem-pattern.d.ts +1 -2
- package/lib/problem-pattern.d.ts.map +1 -1
- package/lib/problem-pattern.js +9 -10
- package/lib/problem-pattern.js.map +1 -1
- package/lib/reference.d.ts +1 -3
- package/lib/reference.d.ts.map +1 -1
- package/lib/reference.js +4 -5
- package/lib/reference.js.map +1 -1
- package/lib/reporter.d.ts +1 -1
- package/lib/reporter.d.ts.map +1 -1
- package/lib/storage.d.ts +1 -4
- package/lib/storage.d.ts.map +1 -1
- package/lib/storage.js +11 -11
- package/lib/storage.js.map +1 -1
- package/lib/task-definition.d.ts +1 -1
- package/lib/task-definition.d.ts.map +1 -1
- package/lib/task-definition.js +6 -6
- package/lib/task-definition.js.map +1 -1
- package/lib/types/application.d.ts +4 -4
- package/lib/types/application.d.ts.map +1 -1
- package/lib/types/authentication.d.ts +1 -2
- package/lib/types/authentication.d.ts.map +1 -1
- package/lib/types/authentication.js.map +1 -1
- package/lib/types/common.d.ts +2 -2
- package/lib/types/common.d.ts.map +1 -1
- package/lib/types/extension.d.ts +1 -1
- package/lib/types/extension.d.ts.map +1 -1
- package/lib/types/extension.js.map +1 -1
- package/lib/types/file-watch.d.ts +1 -1
- package/lib/types/file-watch.d.ts.map +1 -1
- package/lib/types/file-watch.js +2 -2
- package/lib/types/file-watch.js.map +1 -1
- package/lib/types/file.d.ts +1 -1
- package/lib/types/file.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/markdown.d.ts +2 -1
- package/lib/types/markdown.d.ts.map +1 -1
- package/lib/types/markers/markers-manager.d.ts +2 -2
- package/lib/types/markers/markers-manager.d.ts.map +1 -1
- package/lib/types/markers/markers-manager.js +25 -23
- package/lib/types/markers/markers-manager.js.map +1 -1
- package/lib/types/markers/markers.js +2 -2
- package/lib/types/markers/markers.js.map +1 -1
- package/lib/utils/ipc.d.ts.map +1 -1
- package/lib/utils/ipc.js +7 -8
- package/lib/utils/ipc.js.map +1 -1
- package/package.json +4 -7
- package/lib/arrays.d.ts +0 -134
- package/lib/arrays.d.ts.map +0 -1
- package/lib/arrays.js +0 -545
- package/lib/arrays.js.map +0 -1
- package/lib/async.d.ts +0 -185
- package/lib/async.d.ts.map +0 -1
- package/lib/async.js +0 -469
- package/lib/async.js.map +0 -1
- package/lib/cache.d.ts +0 -12
- package/lib/cache.d.ts.map +0 -1
- package/lib/cache.js +0 -37
- package/lib/cache.js.map +0 -1
- package/lib/cancellation.d.ts +0 -23
- package/lib/cancellation.d.ts.map +0 -1
- package/lib/cancellation.js +0 -120
- package/lib/cancellation.js.map +0 -1
- package/lib/charCode.d.ts +0 -406
- package/lib/charCode.d.ts.map +0 -1
- package/lib/charCode.js +0 -8
- package/lib/charCode.js.map +0 -1
- package/lib/character-classifier.d.ts +0 -25
- package/lib/character-classifier.d.ts.map +0 -1
- package/lib/character-classifier.js +0 -59
- package/lib/character-classifier.js.map +0 -1
- package/lib/const/encodings.d.ts +0 -10
- package/lib/const/encodings.d.ts.map +0 -1
- package/lib/const/encodings.js +0 -244
- package/lib/const/encodings.js.map +0 -1
- package/lib/cryptr.d.ts +0 -7
- package/lib/cryptr.js +0 -6
- package/lib/cryptr.js.map +0 -1
- package/lib/date.d.ts +0 -2
- package/lib/date.d.ts.map +0 -1
- package/lib/date.js +0 -22
- package/lib/date.js.map +0 -1
- package/lib/disposable.d.ts +0 -88
- package/lib/disposable.d.ts.map +0 -1
- package/lib/disposable.js +0 -316
- package/lib/disposable.js.map +0 -1
- package/lib/encoding/index.d.ts +0 -34
- package/lib/encoding/index.d.ts.map +0 -1
- package/lib/encoding/index.js +0 -219
- package/lib/encoding/index.js.map +0 -1
- package/lib/errors.d.ts +0 -56
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js +0 -148
- package/lib/errors.js.map +0 -1
- package/lib/event.d.ts +0 -268
- package/lib/event.d.ts.map +0 -1
- package/lib/event.js +0 -816
- package/lib/event.js.map +0 -1
- package/lib/filters.d.ts +0 -47
- package/lib/filters.d.ts.map +0 -1
- package/lib/filters.js +0 -699
- package/lib/filters.js.map +0 -1
- package/lib/functional.d.ts +0 -4
- package/lib/functional.d.ts.map +0 -1
- package/lib/functional.js +0 -45
- package/lib/functional.js.map +0 -1
- package/lib/iterator.d.ts +0 -17
- package/lib/iterator.d.ts.map +0 -1
- package/lib/iterator.js +0 -24
- package/lib/iterator.js.map +0 -1
- package/lib/lifecycle.d.ts +0 -17
- package/lib/lifecycle.d.ts.map +0 -1
- package/lib/lifecycle.js +0 -39
- package/lib/lifecycle.js.map +0 -1
- package/lib/linked-list.d.ts +0 -18
- package/lib/linked-list.d.ts.map +0 -1
- package/lib/linked-list.js +0 -138
- package/lib/linked-list.js.map +0 -1
- package/lib/linkedText.d.ts +0 -13
- package/lib/linkedText.d.ts.map +0 -1
- package/lib/linkedText.js +0 -50
- package/lib/linkedText.js.map +0 -1
- package/lib/map.d.ts +0 -124
- package/lib/map.d.ts.map +0 -1
- package/lib/map.js +0 -819
- package/lib/map.js.map +0 -1
- package/lib/path.d.ts +0 -92
- package/lib/path.d.ts.map +0 -1
- package/lib/path.js +0 -1695
- package/lib/path.js.map +0 -1
- package/lib/platform.d.ts +0 -48
- package/lib/platform.d.ts.map +0 -1
- package/lib/platform.js +0 -153
- package/lib/platform.js.map +0 -1
- package/lib/process.d.ts +0 -5
- package/lib/process.d.ts.map +0 -1
- package/lib/process.js +0 -23
- package/lib/process.js.map +0 -1
- package/lib/progress.d.ts +0 -56
- package/lib/progress.d.ts.map +0 -1
- package/lib/progress.js +0 -27
- package/lib/progress.js.map +0 -1
- package/lib/sequence.d.ts +0 -20
- package/lib/sequence.d.ts.map +0 -1
- package/lib/sequence.js +0 -17
- package/lib/sequence.js.map +0 -1
- package/lib/uint.d.ts +0 -32
- package/lib/uint.d.ts.map +0 -1
- package/lib/uint.js +0 -28
- package/lib/uint.js.map +0 -1
- package/lib/uri.d.ts +0 -94
- package/lib/uri.d.ts.map +0 -1
- package/lib/uri.js +0 -231
- package/lib/uri.js.map +0 -1
- package/lib/utils/ansi.d.ts +0 -5
- package/lib/utils/ansi.d.ts.map +0 -1
- package/lib/utils/ansi.js +0 -14
- package/lib/utils/ansi.js.map +0 -1
- package/lib/utils/arrays.d.ts +0 -66
- package/lib/utils/arrays.d.ts.map +0 -1
- package/lib/utils/arrays.js +0 -260
- package/lib/utils/arrays.js.map +0 -1
- package/lib/utils/buffer.d.ts +0 -35
- package/lib/utils/buffer.d.ts.map +0 -1
- package/lib/utils/buffer.js +0 -174
- package/lib/utils/buffer.js.map +0 -1
- package/lib/utils/comparers.d.ts.map +0 -1
- package/lib/utils/comparers.js.map +0 -1
- package/lib/utils/decorators.d.ts +0 -11
- package/lib/utils/decorators.d.ts.map +0 -1
- package/lib/utils/decorators.js +0 -151
- package/lib/utils/decorators.js.map +0 -1
- package/lib/utils/file-uri.d.ts +0 -15
- package/lib/utils/file-uri.d.ts.map +0 -1
- package/lib/utils/file-uri.js +0 -46
- package/lib/utils/file-uri.js.map +0 -1
- package/lib/utils/glob.d.ts +0 -46
- package/lib/utils/glob.d.ts.map +0 -1
- package/lib/utils/glob.js +0 -556
- package/lib/utils/glob.js.map +0 -1
- package/lib/utils/hash.d.ts +0 -38
- package/lib/utils/hash.d.ts.map +0 -1
- package/lib/utils/hash.js +0 -294
- package/lib/utils/hash.js.map +0 -1
- package/lib/utils/index.d.ts +0 -15
- package/lib/utils/index.d.ts.map +0 -1
- package/lib/utils/index.js +0 -18
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/json.d.ts +0 -76
- package/lib/utils/json.d.ts.map +0 -1
- package/lib/utils/json.js +0 -188
- package/lib/utils/json.js.map +0 -1
- package/lib/utils/markdown.d.ts.map +0 -1
- package/lib/utils/markdown.js.map +0 -1
- package/lib/utils/marshalling.d.ts +0 -7
- package/lib/utils/marshalling.d.ts.map +0 -1
- package/lib/utils/marshalling.js +0 -59
- package/lib/utils/marshalling.js.map +0 -1
- package/lib/utils/objects.d.ts +0 -6
- package/lib/utils/objects.d.ts.map +0 -1
- package/lib/utils/objects.js +0 -103
- package/lib/utils/objects.js.map +0 -1
- package/lib/utils/os.d.ts +0 -49
- package/lib/utils/os.d.ts.map +0 -1
- package/lib/utils/os.js +0 -98
- package/lib/utils/os.js.map +0 -1
- package/lib/utils/paths.d.ts +0 -35
- package/lib/utils/paths.d.ts.map +0 -1
- package/lib/utils/paths.js +0 -313
- package/lib/utils/paths.js.map +0 -1
- package/lib/utils/promise-util.d.ts +0 -10
- package/lib/utils/promise-util.d.ts.map +0 -1
- package/lib/utils/promise-util.js +0 -17
- package/lib/utils/promise-util.js.map +0 -1
- package/lib/utils/strings.d.ts +0 -181
- package/lib/utils/strings.d.ts.map +0 -1
- package/lib/utils/strings.js +0 -858
- package/lib/utils/strings.js.map +0 -1
- package/lib/utils/types.d.ts +0 -69
- package/lib/utils/types.d.ts.map +0 -1
- package/lib/utils/types.js +0 -201
- package/lib/utils/types.js.map +0 -1
- package/lib/uuid.d.ts +0 -2
- package/lib/uuid.d.ts.map +0 -1
- package/lib/uuid.js +0 -10
- package/lib/uuid.js.map +0 -1
package/lib/utils/strings.js
DELETED
|
@@ -1,858 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.containsUppercaseCharacter = exports.fuzzyContains = exports.repeat = exports.safeBtoa = exports.stripUTF8BOM = exports.startsWithUTF8BOM = exports.UTF8_BOM_CHARACTER = exports.removeAccents = exports.removeAnsiEscapeCodes = exports.lcut = exports.isFullWidthCharacter = exports.containsFullWidthCharacter = exports.isBasicASCII = exports.containsEmoji = exports.containsRTL = exports.isLowSurrogate = exports.isHighSurrogate = exports.overlap = exports.commonSuffixLength = exports.commonPrefixLength = exports.startsWithIgnoreCase = exports.equalsIgnoreCase = exports.isUpperAsciiLetter = exports.isLowerAsciiLetter = exports.compareIgnoreCase = exports.compare = exports.lastNonWhitespaceIndex = exports.getLeadingWhitespace = exports.firstNonWhitespaceIndex = exports.regExpFlags = exports.regExpContainsBackreference = exports.regExpLeadsToEndlessLoop = exports.createRegExp = exports.endsWith = exports.startsWith = exports.stripWildcards = exports.convertSimple2RegExpPattern = exports.rtrim = exports.multiRightTrim = exports.ltrim = exports.trim = exports.count = exports.escapeRegExpCharacters = exports.escape = exports.mnemonicButtonLabel = exports.format = exports.pad = exports.isFalsyOrWhitespace = exports.stringUtils = exports.empty = void 0;
|
|
4
|
-
exports.decodeUTF8 = exports.encodeUTF8 = exports.getNextCodePoint = exports.computeCodePoint = exports.getNLines = exports.uppercaseFirstLetter = void 0;
|
|
5
|
-
const os_1 = require("./os");
|
|
6
|
-
/**
|
|
7
|
-
* The empty string.
|
|
8
|
-
*/
|
|
9
|
-
exports.empty = '';
|
|
10
|
-
const hasTextEncoder = typeof TextEncoder !== 'undefined';
|
|
11
|
-
const hasTextDecoder = typeof TextDecoder !== 'undefined';
|
|
12
|
-
/**
|
|
13
|
-
* 浏览器全局可以直接使用 TextEncoder/TextDecoder
|
|
14
|
-
* Node.js 11+ 才可以全局使用,以下需要 require('util')
|
|
15
|
-
*/
|
|
16
|
-
var stringUtils;
|
|
17
|
-
(function (stringUtils) {
|
|
18
|
-
stringUtils.StringTextEncoder = hasTextEncoder ? TextEncoder : require('util').TextEncoder;
|
|
19
|
-
stringUtils.StringTextDecoder = hasTextDecoder ? TextDecoder : require('util').TextDecoder;
|
|
20
|
-
})(stringUtils = exports.stringUtils || (exports.stringUtils = {}));
|
|
21
|
-
function isFalsyOrWhitespace(str) {
|
|
22
|
-
if (!str || typeof str !== 'string') {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return str.trim().length === 0;
|
|
26
|
-
}
|
|
27
|
-
exports.isFalsyOrWhitespace = isFalsyOrWhitespace;
|
|
28
|
-
/**
|
|
29
|
-
* @returns the provided number with the given number of preceding zeros.
|
|
30
|
-
*/
|
|
31
|
-
function pad(n, l, char = '0') {
|
|
32
|
-
const str = '' + n;
|
|
33
|
-
const r = [str];
|
|
34
|
-
for (let i = str.length; i < l; i++) {
|
|
35
|
-
r.push(char);
|
|
36
|
-
}
|
|
37
|
-
return r.reverse().join('');
|
|
38
|
-
}
|
|
39
|
-
exports.pad = pad;
|
|
40
|
-
const _formatRegexp = /{(\d+)}/g;
|
|
41
|
-
/**
|
|
42
|
-
* Helper to produce a string with a variable number of arguments. Insert variable segments
|
|
43
|
-
* into the string using the {n} notation where N is the index of the argument following the string.
|
|
44
|
-
* @param value string to which formatting is applied
|
|
45
|
-
* @param args replacements for {n}-entries
|
|
46
|
-
*/
|
|
47
|
-
function format(value, ...args) {
|
|
48
|
-
if (args.length === 0) {
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
return value.replace(_formatRegexp, function (match, group) {
|
|
52
|
-
const idx = parseInt(group, 10);
|
|
53
|
-
return isNaN(idx) || idx < 0 || idx >= args.length ? match : args[idx];
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
exports.format = format;
|
|
57
|
-
/**
|
|
58
|
-
* Handles mnemonics for buttons. Depending on OS:
|
|
59
|
-
* - Windows: Supported via & character (replace && with & and & with && for escaping)
|
|
60
|
-
* - Linux: Supported via _ character (replace && with _)
|
|
61
|
-
* - macOS: Unsupported (replace && with empty string)
|
|
62
|
-
*/
|
|
63
|
-
function mnemonicButtonLabel(label, forceDisableMnemonics) {
|
|
64
|
-
if (os_1.isOSX || forceDisableMnemonics) {
|
|
65
|
-
return label.replace(/\(&&\w\)|&&/g, '');
|
|
66
|
-
}
|
|
67
|
-
if (os_1.isWindows) {
|
|
68
|
-
return label.replace(/&&|&/g, (m) => (m === '&' ? '&&' : '&'));
|
|
69
|
-
}
|
|
70
|
-
return label.replace(/&&/g, '_');
|
|
71
|
-
}
|
|
72
|
-
exports.mnemonicButtonLabel = mnemonicButtonLabel;
|
|
73
|
-
/**
|
|
74
|
-
* Converts HTML characters inside the string to use entities instead. Makes the string safe from
|
|
75
|
-
* being used e.g. in HTMLElement.innerHTML.
|
|
76
|
-
*/
|
|
77
|
-
function escape(html) {
|
|
78
|
-
return html.replace(/[<>&]/g, function (match) {
|
|
79
|
-
switch (match) {
|
|
80
|
-
case '<':
|
|
81
|
-
return '<';
|
|
82
|
-
case '>':
|
|
83
|
-
return '>';
|
|
84
|
-
case '&':
|
|
85
|
-
return '&';
|
|
86
|
-
default:
|
|
87
|
-
return match;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
exports.escape = escape;
|
|
92
|
-
/**
|
|
93
|
-
* Escapes regular expression characters in a given string
|
|
94
|
-
*/
|
|
95
|
-
function escapeRegExpCharacters(value) {
|
|
96
|
-
return value.replace(/[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g, '\\$&');
|
|
97
|
-
}
|
|
98
|
-
exports.escapeRegExpCharacters = escapeRegExpCharacters;
|
|
99
|
-
/**
|
|
100
|
-
* Counts how often `character` occurs inside `value`.
|
|
101
|
-
*/
|
|
102
|
-
function count(value, character) {
|
|
103
|
-
let result = 0;
|
|
104
|
-
const ch = character.charCodeAt(0);
|
|
105
|
-
for (let i = value.length - 1; i >= 0; i--) {
|
|
106
|
-
if (value.charCodeAt(i) === ch) {
|
|
107
|
-
result++;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
exports.count = count;
|
|
113
|
-
/**
|
|
114
|
-
* Removes all occurrences of needle from the beginning and end of haystack.
|
|
115
|
-
* @param haystack string to trim
|
|
116
|
-
* @param needle the thing to trim (default is a blank)
|
|
117
|
-
*/
|
|
118
|
-
function trim(haystack, needle = ' ') {
|
|
119
|
-
const trimmed = ltrim(haystack, needle);
|
|
120
|
-
return rtrim(trimmed, needle);
|
|
121
|
-
}
|
|
122
|
-
exports.trim = trim;
|
|
123
|
-
/**
|
|
124
|
-
* Removes all occurrences of needle from the beginning of haystack.
|
|
125
|
-
* @param haystack string to trim
|
|
126
|
-
* @param needle the thing to trim
|
|
127
|
-
*/
|
|
128
|
-
function ltrim(haystack, needle) {
|
|
129
|
-
if (!haystack || !needle) {
|
|
130
|
-
return haystack;
|
|
131
|
-
}
|
|
132
|
-
const needleLen = needle.length;
|
|
133
|
-
if (needleLen === 0 || haystack.length === 0) {
|
|
134
|
-
return haystack;
|
|
135
|
-
}
|
|
136
|
-
let offset = 0;
|
|
137
|
-
while (haystack.indexOf(needle, offset) === offset) {
|
|
138
|
-
offset = offset + needleLen;
|
|
139
|
-
}
|
|
140
|
-
return haystack.substring(offset);
|
|
141
|
-
}
|
|
142
|
-
exports.ltrim = ltrim;
|
|
143
|
-
/**
|
|
144
|
-
* Removes all occurrences of needles from the end of haystack.
|
|
145
|
-
* @param source
|
|
146
|
-
* @param needles
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* let source = '/path/to/file.ts,;';
|
|
150
|
-
* const res = multiRightTrim(source, [`,`, ';']);
|
|
151
|
-
* // res === '/path/to/file.ts';
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
function multiRightTrim(source, needles) {
|
|
155
|
-
let result = decodeURIComponent(source);
|
|
156
|
-
for (const needle of needles) {
|
|
157
|
-
result = rtrim(result, needle);
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
exports.multiRightTrim = multiRightTrim;
|
|
162
|
-
/**
|
|
163
|
-
* Removes all occurrences of needle from the end of haystack.
|
|
164
|
-
* @param haystack string to trim
|
|
165
|
-
* @param needle the thing to trim
|
|
166
|
-
*/
|
|
167
|
-
function rtrim(haystack, needle) {
|
|
168
|
-
if (!haystack || !needle) {
|
|
169
|
-
return haystack;
|
|
170
|
-
}
|
|
171
|
-
const needleLen = needle.length;
|
|
172
|
-
const haystackLen = haystack.length;
|
|
173
|
-
if (needleLen === 0 || haystackLen === 0) {
|
|
174
|
-
return haystack;
|
|
175
|
-
}
|
|
176
|
-
let offset = haystackLen;
|
|
177
|
-
let idx = -1;
|
|
178
|
-
while (true) {
|
|
179
|
-
idx = haystack.lastIndexOf(needle, offset - 1);
|
|
180
|
-
if (idx === -1 || idx + needleLen !== offset) {
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
if (idx === 0) {
|
|
184
|
-
return '';
|
|
185
|
-
}
|
|
186
|
-
offset = idx;
|
|
187
|
-
}
|
|
188
|
-
return haystack.substring(0, offset);
|
|
189
|
-
}
|
|
190
|
-
exports.rtrim = rtrim;
|
|
191
|
-
function convertSimple2RegExpPattern(pattern) {
|
|
192
|
-
return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
|
|
193
|
-
}
|
|
194
|
-
exports.convertSimple2RegExpPattern = convertSimple2RegExpPattern;
|
|
195
|
-
function stripWildcards(pattern) {
|
|
196
|
-
return pattern.replace(/\*/g, '');
|
|
197
|
-
}
|
|
198
|
-
exports.stripWildcards = stripWildcards;
|
|
199
|
-
/**
|
|
200
|
-
* Determines if haystack starts with needle.
|
|
201
|
-
*/
|
|
202
|
-
function startsWith(haystack, needle) {
|
|
203
|
-
if (haystack.length < needle.length) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
if (haystack === needle) {
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
for (let i = 0; i < needle.length; i++) {
|
|
210
|
-
if (haystack[i] !== needle[i]) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
exports.startsWith = startsWith;
|
|
217
|
-
/**
|
|
218
|
-
* Determines if haystack ends with needle.
|
|
219
|
-
*/
|
|
220
|
-
function endsWith(haystack, needle) {
|
|
221
|
-
const diff = haystack.length - needle.length;
|
|
222
|
-
if (diff > 0) {
|
|
223
|
-
return haystack.indexOf(needle, diff) === diff;
|
|
224
|
-
}
|
|
225
|
-
else if (diff === 0) {
|
|
226
|
-
return haystack === needle;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.endsWith = endsWith;
|
|
233
|
-
function createRegExp(searchString, isRegex, options = {}) {
|
|
234
|
-
if (!searchString) {
|
|
235
|
-
throw new Error('Cannot create regex from empty string');
|
|
236
|
-
}
|
|
237
|
-
if (!isRegex) {
|
|
238
|
-
searchString = escapeRegExpCharacters(searchString);
|
|
239
|
-
}
|
|
240
|
-
if (options.wholeWord) {
|
|
241
|
-
if (!/\B/.test(searchString.charAt(0))) {
|
|
242
|
-
searchString = '\\b' + searchString;
|
|
243
|
-
}
|
|
244
|
-
if (!/\B/.test(searchString.charAt(searchString.length - 1))) {
|
|
245
|
-
searchString = searchString + '\\b';
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
let modifiers = '';
|
|
249
|
-
if (options.global) {
|
|
250
|
-
modifiers += 'g';
|
|
251
|
-
}
|
|
252
|
-
if (!options.matchCase) {
|
|
253
|
-
modifiers += 'i';
|
|
254
|
-
}
|
|
255
|
-
if (options.multiline) {
|
|
256
|
-
modifiers += 'm';
|
|
257
|
-
}
|
|
258
|
-
if (options.unicode) {
|
|
259
|
-
modifiers += 'u';
|
|
260
|
-
}
|
|
261
|
-
return new RegExp(searchString, modifiers);
|
|
262
|
-
}
|
|
263
|
-
exports.createRegExp = createRegExp;
|
|
264
|
-
function regExpLeadsToEndlessLoop(regexp) {
|
|
265
|
-
// Exit early if it's one of these special cases which are meant to match
|
|
266
|
-
// against an empty string
|
|
267
|
-
if (regexp.source === '^' || regexp.source === '^$' || regexp.source === '$' || regexp.source === '^\\s*$') {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
// We check against an empty string. If the regular expression doesn't advance
|
|
271
|
-
// (e.g. ends in an endless loop) it will match an empty string.
|
|
272
|
-
const match = regexp.exec('');
|
|
273
|
-
return !!(match && regexp.lastIndex === 0);
|
|
274
|
-
}
|
|
275
|
-
exports.regExpLeadsToEndlessLoop = regExpLeadsToEndlessLoop;
|
|
276
|
-
function regExpContainsBackreference(regexpValue) {
|
|
277
|
-
return !!regexpValue.match(/([^\\]|^)(\\\\)*\\\d+/);
|
|
278
|
-
}
|
|
279
|
-
exports.regExpContainsBackreference = regExpContainsBackreference;
|
|
280
|
-
function regExpFlags(regexp) {
|
|
281
|
-
return ((regexp.global ? 'g' : '') +
|
|
282
|
-
(regexp.ignoreCase ? 'i' : '') +
|
|
283
|
-
(regexp.multiline ? 'm' : '') +
|
|
284
|
-
(regexp.unicode ? 'u' : ''));
|
|
285
|
-
}
|
|
286
|
-
exports.regExpFlags = regExpFlags;
|
|
287
|
-
/**
|
|
288
|
-
* Returns first index of the string that is not whitespace.
|
|
289
|
-
* If string is empty or contains only whitespaces, returns -1
|
|
290
|
-
*/
|
|
291
|
-
function firstNonWhitespaceIndex(str) {
|
|
292
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
293
|
-
const chCode = str.charCodeAt(i);
|
|
294
|
-
if (chCode !== 32 /* Space */ && chCode !== 9 /* Tab */) {
|
|
295
|
-
return i;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return -1;
|
|
299
|
-
}
|
|
300
|
-
exports.firstNonWhitespaceIndex = firstNonWhitespaceIndex;
|
|
301
|
-
/**
|
|
302
|
-
* Returns the leading whitespace of the string.
|
|
303
|
-
* If the string contains only whitespaces, returns entire string
|
|
304
|
-
*/
|
|
305
|
-
function getLeadingWhitespace(str, start = 0, end = str.length) {
|
|
306
|
-
for (let i = start; i < end; i++) {
|
|
307
|
-
const chCode = str.charCodeAt(i);
|
|
308
|
-
if (chCode !== 32 /* Space */ && chCode !== 9 /* Tab */) {
|
|
309
|
-
return str.substring(start, i);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return str.substring(start, end);
|
|
313
|
-
}
|
|
314
|
-
exports.getLeadingWhitespace = getLeadingWhitespace;
|
|
315
|
-
/**
|
|
316
|
-
* Returns last index of the string that is not whitespace.
|
|
317
|
-
* If string is empty or contains only whitespaces, returns -1
|
|
318
|
-
*/
|
|
319
|
-
function lastNonWhitespaceIndex(str, startIndex = str.length - 1) {
|
|
320
|
-
for (let i = startIndex; i >= 0; i--) {
|
|
321
|
-
const chCode = str.charCodeAt(i);
|
|
322
|
-
if (chCode !== 32 /* Space */ && chCode !== 9 /* Tab */) {
|
|
323
|
-
return i;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return -1;
|
|
327
|
-
}
|
|
328
|
-
exports.lastNonWhitespaceIndex = lastNonWhitespaceIndex;
|
|
329
|
-
function compare(a, b) {
|
|
330
|
-
if (a < b) {
|
|
331
|
-
return -1;
|
|
332
|
-
}
|
|
333
|
-
else if (a > b) {
|
|
334
|
-
return 1;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
return 0;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
exports.compare = compare;
|
|
341
|
-
function compareIgnoreCase(a, b) {
|
|
342
|
-
const len = Math.min(a.length, b.length);
|
|
343
|
-
for (let i = 0; i < len; i++) {
|
|
344
|
-
let codeA = a.charCodeAt(i);
|
|
345
|
-
let codeB = b.charCodeAt(i);
|
|
346
|
-
if (codeA === codeB) {
|
|
347
|
-
// equal
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
if (isUpperAsciiLetter(codeA)) {
|
|
351
|
-
codeA += 32;
|
|
352
|
-
}
|
|
353
|
-
if (isUpperAsciiLetter(codeB)) {
|
|
354
|
-
codeB += 32;
|
|
355
|
-
}
|
|
356
|
-
const diff = codeA - codeB;
|
|
357
|
-
if (diff === 0) {
|
|
358
|
-
// equal -> ignoreCase
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
else if (isLowerAsciiLetter(codeA) && isLowerAsciiLetter(codeB)) {
|
|
362
|
-
//
|
|
363
|
-
return diff;
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
return compare(a.toLowerCase(), b.toLowerCase());
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (a.length < b.length) {
|
|
370
|
-
return -1;
|
|
371
|
-
}
|
|
372
|
-
else if (a.length > b.length) {
|
|
373
|
-
return 1;
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
return 0;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
exports.compareIgnoreCase = compareIgnoreCase;
|
|
380
|
-
function isLowerAsciiLetter(code) {
|
|
381
|
-
return code >= 97 /* a */ && code <= 122 /* z */;
|
|
382
|
-
}
|
|
383
|
-
exports.isLowerAsciiLetter = isLowerAsciiLetter;
|
|
384
|
-
function isUpperAsciiLetter(code) {
|
|
385
|
-
return code >= 65 /* A */ && code <= 90 /* Z */;
|
|
386
|
-
}
|
|
387
|
-
exports.isUpperAsciiLetter = isUpperAsciiLetter;
|
|
388
|
-
function isAsciiLetter(code) {
|
|
389
|
-
return isLowerAsciiLetter(code) || isUpperAsciiLetter(code);
|
|
390
|
-
}
|
|
391
|
-
function equalsIgnoreCase(a, b) {
|
|
392
|
-
const len1 = a ? a.length : 0;
|
|
393
|
-
const len2 = b ? b.length : 0;
|
|
394
|
-
if (len1 !== len2) {
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
return doEqualsIgnoreCase(a, b);
|
|
398
|
-
}
|
|
399
|
-
exports.equalsIgnoreCase = equalsIgnoreCase;
|
|
400
|
-
function doEqualsIgnoreCase(a, b, stopAt = a.length) {
|
|
401
|
-
if (typeof a !== 'string' || typeof b !== 'string') {
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
for (let i = 0; i < stopAt; i++) {
|
|
405
|
-
const codeA = a.charCodeAt(i);
|
|
406
|
-
const codeB = b.charCodeAt(i);
|
|
407
|
-
if (codeA === codeB) {
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
// a-z A-Z
|
|
411
|
-
if (isAsciiLetter(codeA) && isAsciiLetter(codeB)) {
|
|
412
|
-
const diff = Math.abs(codeA - codeB);
|
|
413
|
-
if (diff !== 0 && diff !== 32) {
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
// Any other charcode
|
|
419
|
-
if (String.fromCharCode(codeA).toLowerCase() !== String.fromCharCode(codeB).toLowerCase()) {
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
function startsWithIgnoreCase(str, candidate) {
|
|
427
|
-
const candidateLength = candidate.length;
|
|
428
|
-
if (candidate.length > str.length) {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
return doEqualsIgnoreCase(str, candidate, candidateLength);
|
|
432
|
-
}
|
|
433
|
-
exports.startsWithIgnoreCase = startsWithIgnoreCase;
|
|
434
|
-
/**
|
|
435
|
-
* @returns the length of the common prefix of the two strings.
|
|
436
|
-
*/
|
|
437
|
-
function commonPrefixLength(a, b) {
|
|
438
|
-
let i;
|
|
439
|
-
const len = Math.min(a.length, b.length);
|
|
440
|
-
for (i = 0; i < len; i++) {
|
|
441
|
-
if (a.charCodeAt(i) !== b.charCodeAt(i)) {
|
|
442
|
-
return i;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
return len;
|
|
446
|
-
}
|
|
447
|
-
exports.commonPrefixLength = commonPrefixLength;
|
|
448
|
-
/**
|
|
449
|
-
* @returns the length of the common suffix of the two strings.
|
|
450
|
-
*/
|
|
451
|
-
function commonSuffixLength(a, b) {
|
|
452
|
-
let i;
|
|
453
|
-
const len = Math.min(a.length, b.length);
|
|
454
|
-
const aLastIndex = a.length - 1;
|
|
455
|
-
const bLastIndex = b.length - 1;
|
|
456
|
-
for (i = 0; i < len; i++) {
|
|
457
|
-
if (a.charCodeAt(aLastIndex - i) !== b.charCodeAt(bLastIndex - i)) {
|
|
458
|
-
return i;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return len;
|
|
462
|
-
}
|
|
463
|
-
exports.commonSuffixLength = commonSuffixLength;
|
|
464
|
-
function substrEquals(a, aStart, aEnd, b, bStart, bEnd) {
|
|
465
|
-
while (aStart < aEnd && bStart < bEnd) {
|
|
466
|
-
if (a[aStart] !== b[bStart]) {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
aStart += 1;
|
|
470
|
-
bStart += 1;
|
|
471
|
-
}
|
|
472
|
-
return true;
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* Return the overlap between the suffix of `a` and the prefix of `b`.
|
|
476
|
-
* For instance `overlap("foobar", "arr, I'm a pirate") === 2`.
|
|
477
|
-
*/
|
|
478
|
-
function overlap(a, b) {
|
|
479
|
-
const aEnd = a.length;
|
|
480
|
-
let bEnd = b.length;
|
|
481
|
-
let aStart = aEnd - bEnd;
|
|
482
|
-
if (aStart === 0) {
|
|
483
|
-
return a === b ? aEnd : 0;
|
|
484
|
-
}
|
|
485
|
-
else if (aStart < 0) {
|
|
486
|
-
bEnd += aStart;
|
|
487
|
-
aStart = 0;
|
|
488
|
-
}
|
|
489
|
-
while (aStart < aEnd && bEnd > 0) {
|
|
490
|
-
if (substrEquals(a, aStart, aEnd, b, 0, bEnd)) {
|
|
491
|
-
return bEnd;
|
|
492
|
-
}
|
|
493
|
-
bEnd -= 1;
|
|
494
|
-
aStart += 1;
|
|
495
|
-
}
|
|
496
|
-
return 0;
|
|
497
|
-
}
|
|
498
|
-
exports.overlap = overlap;
|
|
499
|
-
// --- unicode
|
|
500
|
-
// http://en.wikipedia.org/wiki/Surrogate_pair
|
|
501
|
-
// Returns the code point starting at a specified index in a string
|
|
502
|
-
// Code points U+0000 to U+D7FF and U+E000 to U+FFFF are represented on a single character
|
|
503
|
-
// Code points U+10000 to U+10FFFF are represented on two consecutive characters
|
|
504
|
-
// export function getUnicodePoint(str:string, index:number, len:number):number {
|
|
505
|
-
// const chrCode = str.charCodeAt(index);
|
|
506
|
-
// if (0xD800 <= chrCode && chrCode <= 0xDBFF && index + 1 < len) {
|
|
507
|
-
// const nextChrCode = str.charCodeAt(index + 1);
|
|
508
|
-
// if (0xDC00 <= nextChrCode && nextChrCode <= 0xDFFF) {
|
|
509
|
-
// return (chrCode - 0xD800) << 10 + (nextChrCode - 0xDC00) + 0x10000;
|
|
510
|
-
// }
|
|
511
|
-
// }
|
|
512
|
-
// return chrCode;
|
|
513
|
-
// }
|
|
514
|
-
function isHighSurrogate(charCode) {
|
|
515
|
-
return 0xd800 <= charCode && charCode <= 0xdbff;
|
|
516
|
-
}
|
|
517
|
-
exports.isHighSurrogate = isHighSurrogate;
|
|
518
|
-
function isLowSurrogate(charCode) {
|
|
519
|
-
return 0xdc00 <= charCode && charCode <= 0xdfff;
|
|
520
|
-
}
|
|
521
|
-
exports.isLowSurrogate = isLowSurrogate;
|
|
522
|
-
/**
|
|
523
|
-
* Generated using https://github.com/alexandrudima/unicode-utils/blob/master/generate-rtl-test.js
|
|
524
|
-
*/
|
|
525
|
-
const CONTAINS_RTL = /(?:[\u05BE\u05C0\u05C3\u05C6\u05D0-\u05F4\u0608\u060B\u060D\u061B-\u064A\u066D-\u066F\u0671-\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u0710\u0712-\u072F\u074D-\u07A5\u07B1-\u07EA\u07F4\u07F5\u07FA-\u0815\u081A\u0824\u0828\u0830-\u0858\u085E-\u08BD\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFD3D\uFD50-\uFDFC\uFE70-\uFEFC]|\uD802[\uDC00-\uDD1B\uDD20-\uDE00\uDE10-\uDE33\uDE40-\uDEE4\uDEEB-\uDF35\uDF40-\uDFFF]|\uD803[\uDC00-\uDCFF]|\uD83A[\uDC00-\uDCCF\uDD00-\uDD43\uDD50-\uDFFF]|\uD83B[\uDC00-\uDEBB])/;
|
|
526
|
-
/**
|
|
527
|
-
* Returns true if `str` contains any Unicode character that is classified as "R" or "AL".
|
|
528
|
-
*/
|
|
529
|
-
function containsRTL(str) {
|
|
530
|
-
return CONTAINS_RTL.test(str);
|
|
531
|
-
}
|
|
532
|
-
exports.containsRTL = containsRTL;
|
|
533
|
-
/**
|
|
534
|
-
* Generated using https://github.com/alexandrudima/unicode-utils/blob/master/generate-emoji-test.js
|
|
535
|
-
*/
|
|
536
|
-
const CONTAINS_EMOJI = /(?:[\u231A\u231B\u23F0\u23F3\u2600-\u27BF\u2B50\u2B55]|\uD83C[\uDDE6-\uDDFF\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F\uDE80-\uDEF8]|\uD83E[\uDD00-\uDDE6])/;
|
|
537
|
-
function containsEmoji(str) {
|
|
538
|
-
return CONTAINS_EMOJI.test(str);
|
|
539
|
-
}
|
|
540
|
-
exports.containsEmoji = containsEmoji;
|
|
541
|
-
const IS_BASIC_ASCII = /^[\t\n\r\x20-\x7E]*$/;
|
|
542
|
-
/**
|
|
543
|
-
* Returns true if `str` contains only basic ASCII characters in the range 32 - 126 (including 32 and 126) or \n, \r, \t
|
|
544
|
-
*/
|
|
545
|
-
function isBasicASCII(str) {
|
|
546
|
-
return IS_BASIC_ASCII.test(str);
|
|
547
|
-
}
|
|
548
|
-
exports.isBasicASCII = isBasicASCII;
|
|
549
|
-
function containsFullWidthCharacter(str) {
|
|
550
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
551
|
-
if (isFullWidthCharacter(str.charCodeAt(i))) {
|
|
552
|
-
return true;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
return false;
|
|
556
|
-
}
|
|
557
|
-
exports.containsFullWidthCharacter = containsFullWidthCharacter;
|
|
558
|
-
function isFullWidthCharacter(charCode) {
|
|
559
|
-
// Do a cheap trick to better support wrapping of wide characters, treat them as 2 columns
|
|
560
|
-
// http://jrgraphix.net/research/unicode_blocks.php
|
|
561
|
-
// 2E80 — 2EFF CJK Radicals Supplement
|
|
562
|
-
// 2F00 — 2FDF Kangxi Radicals
|
|
563
|
-
// 2FF0 — 2FFF Ideographic Description Characters
|
|
564
|
-
// 3000 — 303F CJK Symbols and Punctuation
|
|
565
|
-
// 3040 — 309F Hiragana
|
|
566
|
-
// 30A0 — 30FF Katakana
|
|
567
|
-
// 3100 — 312F Bopomofo
|
|
568
|
-
// 3130 — 318F Hangul Compatibility Jamo
|
|
569
|
-
// 3190 — 319F Kanbun
|
|
570
|
-
// 31A0 — 31BF Bopomofo Extended
|
|
571
|
-
// 31F0 — 31FF Katakana Phonetic Extensions
|
|
572
|
-
// 3200 — 32FF Enclosed CJK Letters and Months
|
|
573
|
-
// 3300 — 33FF CJK Compatibility
|
|
574
|
-
// 3400 — 4DBF CJK Unified Ideographs Extension A
|
|
575
|
-
// 4DC0 — 4DFF Yijing Hexagram Symbols
|
|
576
|
-
// 4E00 — 9FFF CJK Unified Ideographs
|
|
577
|
-
// A000 — A48F Yi Syllables
|
|
578
|
-
// A490 — A4CF Yi Radicals
|
|
579
|
-
// AC00 — D7AF Hangul Syllables
|
|
580
|
-
// [IGNORE] D800 — DB7F High Surrogates
|
|
581
|
-
// [IGNORE] DB80 — DBFF High Private Use Surrogates
|
|
582
|
-
// [IGNORE] DC00 — DFFF Low Surrogates
|
|
583
|
-
// [IGNORE] E000 — F8FF Private Use Area
|
|
584
|
-
// F900 — FAFF CJK Compatibility Ideographs
|
|
585
|
-
// [IGNORE] FB00 — FB4F Alphabetic Presentation Forms
|
|
586
|
-
// [IGNORE] FB50 — FDFF Arabic Presentation Forms-A
|
|
587
|
-
// [IGNORE] FE00 — FE0F Variation Selectors
|
|
588
|
-
// [IGNORE] FE20 — FE2F Combining Half Marks
|
|
589
|
-
// [IGNORE] FE30 — FE4F CJK Compatibility Forms
|
|
590
|
-
// [IGNORE] FE50 — FE6F Small Form Variants
|
|
591
|
-
// [IGNORE] FE70 — FEFF Arabic Presentation Forms-B
|
|
592
|
-
// FF00 — FFEF Halfwidth and Fullwidth Forms
|
|
593
|
-
// [https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms]
|
|
594
|
-
// of which FF01 - FF5E fullwidth ASCII of 21 to 7E
|
|
595
|
-
// [IGNORE] and FF65 - FFDC halfwidth of Katakana and Hangul
|
|
596
|
-
// [IGNORE] FFF0 — FFFF Specials
|
|
597
|
-
charCode = +charCode; // @perf
|
|
598
|
-
return ((charCode >= 0x2e80 && charCode <= 0xd7af) ||
|
|
599
|
-
(charCode >= 0xf900 && charCode <= 0xfaff) ||
|
|
600
|
-
(charCode >= 0xff01 && charCode <= 0xff5e));
|
|
601
|
-
}
|
|
602
|
-
exports.isFullWidthCharacter = isFullWidthCharacter;
|
|
603
|
-
/**
|
|
604
|
-
* Given a string and a max length returns a shorted version. Shorting
|
|
605
|
-
* happens at favorable positions - such as whitespace or punctuation characters.
|
|
606
|
-
*/
|
|
607
|
-
function lcut(text, n) {
|
|
608
|
-
if (text.length < n) {
|
|
609
|
-
return text;
|
|
610
|
-
}
|
|
611
|
-
const re = /\b/g;
|
|
612
|
-
let i = 0;
|
|
613
|
-
while (re.test(text)) {
|
|
614
|
-
if (text.length - re.lastIndex < n) {
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
i = re.lastIndex;
|
|
618
|
-
re.lastIndex += 1;
|
|
619
|
-
}
|
|
620
|
-
return text.substring(i).replace(/^\s/, exports.empty);
|
|
621
|
-
}
|
|
622
|
-
exports.lcut = lcut;
|
|
623
|
-
// Escape codes
|
|
624
|
-
// http://en.wikipedia.org/wiki/ANSI_escape_code
|
|
625
|
-
const EL = /\x1B\x5B[12]?K/g; // Erase in line
|
|
626
|
-
const COLOR_START = /\x1b\[\d+m/g; // Color
|
|
627
|
-
const COLOR_END = /\x1b\[0?m/g; // Color
|
|
628
|
-
function removeAnsiEscapeCodes(str) {
|
|
629
|
-
if (str) {
|
|
630
|
-
str = str.replace(EL, '');
|
|
631
|
-
str = str.replace(COLOR_START, '');
|
|
632
|
-
str = str.replace(COLOR_END, '');
|
|
633
|
-
}
|
|
634
|
-
return str;
|
|
635
|
-
}
|
|
636
|
-
exports.removeAnsiEscapeCodes = removeAnsiEscapeCodes;
|
|
637
|
-
exports.removeAccents = (function () {
|
|
638
|
-
if (typeof String.prototype.normalize !== 'function') {
|
|
639
|
-
// ☹️ no ES6 features...
|
|
640
|
-
return function (str) {
|
|
641
|
-
return str;
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
else {
|
|
645
|
-
// transform into NFD form and remove accents
|
|
646
|
-
// see: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463#37511463
|
|
647
|
-
const regex = /[\u0300-\u036f]/g;
|
|
648
|
-
return function (str) {
|
|
649
|
-
return str.normalize('NFD').replace(regex, exports.empty);
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
})();
|
|
653
|
-
// -- UTF-8 BOM
|
|
654
|
-
exports.UTF8_BOM_CHARACTER = String.fromCharCode(65279 /* UTF8_BOM */);
|
|
655
|
-
function startsWithUTF8BOM(str) {
|
|
656
|
-
return !!(str && str.length > 0 && str.charCodeAt(0) === 65279 /* UTF8_BOM */);
|
|
657
|
-
}
|
|
658
|
-
exports.startsWithUTF8BOM = startsWithUTF8BOM;
|
|
659
|
-
function stripUTF8BOM(str) {
|
|
660
|
-
return startsWithUTF8BOM(str) ? str.substr(1) : str;
|
|
661
|
-
}
|
|
662
|
-
exports.stripUTF8BOM = stripUTF8BOM;
|
|
663
|
-
function safeBtoa(str) {
|
|
664
|
-
return btoa(encodeURIComponent(str)); // we use encodeURIComponent because btoa fails for non Latin 1 values
|
|
665
|
-
}
|
|
666
|
-
exports.safeBtoa = safeBtoa;
|
|
667
|
-
function repeat(s, count) {
|
|
668
|
-
let result = '';
|
|
669
|
-
for (let i = 0; i < count; i++) {
|
|
670
|
-
result += s;
|
|
671
|
-
}
|
|
672
|
-
return result;
|
|
673
|
-
}
|
|
674
|
-
exports.repeat = repeat;
|
|
675
|
-
/**
|
|
676
|
-
* Checks if the characters of the provided query string are included in the
|
|
677
|
-
* target string. The characters do not have to be contiguous within the string.
|
|
678
|
-
*/
|
|
679
|
-
function fuzzyContains(target, query) {
|
|
680
|
-
if (!target || !query) {
|
|
681
|
-
return false; // return early if target or query are undefined
|
|
682
|
-
}
|
|
683
|
-
if (target.length < query.length) {
|
|
684
|
-
return false; // impossible for query to be contained in target
|
|
685
|
-
}
|
|
686
|
-
const queryLen = query.length;
|
|
687
|
-
const targetLower = target.toLowerCase();
|
|
688
|
-
let index = 0;
|
|
689
|
-
let lastIndexOf = -1;
|
|
690
|
-
while (index < queryLen) {
|
|
691
|
-
const indexOf = targetLower.indexOf(query[index], lastIndexOf + 1);
|
|
692
|
-
if (indexOf < 0) {
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
lastIndexOf = indexOf;
|
|
696
|
-
index++;
|
|
697
|
-
}
|
|
698
|
-
return true;
|
|
699
|
-
}
|
|
700
|
-
exports.fuzzyContains = fuzzyContains;
|
|
701
|
-
function containsUppercaseCharacter(target, ignoreEscapedChars = false) {
|
|
702
|
-
if (!target) {
|
|
703
|
-
return false;
|
|
704
|
-
}
|
|
705
|
-
if (ignoreEscapedChars) {
|
|
706
|
-
target = target.replace(/\\./g, '');
|
|
707
|
-
}
|
|
708
|
-
return target.toLowerCase() !== target;
|
|
709
|
-
}
|
|
710
|
-
exports.containsUppercaseCharacter = containsUppercaseCharacter;
|
|
711
|
-
function uppercaseFirstLetter(str) {
|
|
712
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
713
|
-
}
|
|
714
|
-
exports.uppercaseFirstLetter = uppercaseFirstLetter;
|
|
715
|
-
function getNLines(str, n = 1) {
|
|
716
|
-
if (n === 0) {
|
|
717
|
-
return '';
|
|
718
|
-
}
|
|
719
|
-
let idx = -1;
|
|
720
|
-
do {
|
|
721
|
-
idx = str.indexOf('\n', idx + 1);
|
|
722
|
-
n--;
|
|
723
|
-
} while (n > 0 && idx >= 0);
|
|
724
|
-
return idx >= 0 ? str.substr(0, idx) : str;
|
|
725
|
-
}
|
|
726
|
-
exports.getNLines = getNLines;
|
|
727
|
-
/**
|
|
728
|
-
* See http://en.wikipedia.org/wiki/Surrogate_pair
|
|
729
|
-
*/
|
|
730
|
-
function computeCodePoint(highSurrogate, lowSurrogate) {
|
|
731
|
-
return ((highSurrogate - 0xd800) << 10) + (lowSurrogate - 0xdc00) + 0x10000;
|
|
732
|
-
}
|
|
733
|
-
exports.computeCodePoint = computeCodePoint;
|
|
734
|
-
/**
|
|
735
|
-
* get the code point that begins at offset `offset`
|
|
736
|
-
*/
|
|
737
|
-
function getNextCodePoint(str, len, offset) {
|
|
738
|
-
const charCode = str.charCodeAt(offset);
|
|
739
|
-
if (isHighSurrogate(charCode) && offset + 1 < len) {
|
|
740
|
-
const nextCharCode = str.charCodeAt(offset + 1);
|
|
741
|
-
if (isLowSurrogate(nextCharCode)) {
|
|
742
|
-
return computeCodePoint(charCode, nextCharCode);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
return charCode;
|
|
746
|
-
}
|
|
747
|
-
exports.getNextCodePoint = getNextCodePoint;
|
|
748
|
-
/**
|
|
749
|
-
* A manual encoding of `str` to UTF8.
|
|
750
|
-
* Use only in environments which do not offer native conversion methods!
|
|
751
|
-
*/
|
|
752
|
-
function encodeUTF8(str) {
|
|
753
|
-
const strLen = str.length;
|
|
754
|
-
// See https://en.wikipedia.org/wiki/UTF-8
|
|
755
|
-
// first loop to establish needed buffer size
|
|
756
|
-
let neededSize = 0;
|
|
757
|
-
let strOffset = 0;
|
|
758
|
-
while (strOffset < strLen) {
|
|
759
|
-
const codePoint = getNextCodePoint(str, strLen, strOffset);
|
|
760
|
-
strOffset += codePoint >= 65536 /* UNICODE_SUPPLEMENTARY_PLANE_BEGIN */ ? 2 : 1;
|
|
761
|
-
if (codePoint < 0x0080) {
|
|
762
|
-
neededSize += 1;
|
|
763
|
-
}
|
|
764
|
-
else if (codePoint < 0x0800) {
|
|
765
|
-
neededSize += 2;
|
|
766
|
-
}
|
|
767
|
-
else if (codePoint < 0x10000) {
|
|
768
|
-
neededSize += 3;
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
neededSize += 4;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
// second loop to actually encode
|
|
775
|
-
const arr = new Uint8Array(neededSize);
|
|
776
|
-
strOffset = 0;
|
|
777
|
-
let arrOffset = 0;
|
|
778
|
-
while (strOffset < strLen) {
|
|
779
|
-
const codePoint = getNextCodePoint(str, strLen, strOffset);
|
|
780
|
-
strOffset += codePoint >= 65536 /* UNICODE_SUPPLEMENTARY_PLANE_BEGIN */ ? 2 : 1;
|
|
781
|
-
if (codePoint < 0x0080) {
|
|
782
|
-
arr[arrOffset++] = codePoint;
|
|
783
|
-
}
|
|
784
|
-
else if (codePoint < 0x0800) {
|
|
785
|
-
arr[arrOffset++] = 0b11000000 | ((codePoint & 0b00000000000000000000011111000000) >>> 6);
|
|
786
|
-
arr[arrOffset++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
|
|
787
|
-
}
|
|
788
|
-
else if (codePoint < 0x10000) {
|
|
789
|
-
arr[arrOffset++] = 0b11100000 | ((codePoint & 0b00000000000000001111000000000000) >>> 12);
|
|
790
|
-
arr[arrOffset++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6);
|
|
791
|
-
arr[arrOffset++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
|
|
792
|
-
}
|
|
793
|
-
else {
|
|
794
|
-
arr[arrOffset++] = 0b11110000 | ((codePoint & 0b00000000000111000000000000000000) >>> 18);
|
|
795
|
-
arr[arrOffset++] = 0b10000000 | ((codePoint & 0b00000000000000111111000000000000) >>> 12);
|
|
796
|
-
arr[arrOffset++] = 0b10000000 | ((codePoint & 0b00000000000000000000111111000000) >>> 6);
|
|
797
|
-
arr[arrOffset++] = 0b10000000 | ((codePoint & 0b00000000000000000000000000111111) >>> 0);
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
return arr;
|
|
801
|
-
}
|
|
802
|
-
exports.encodeUTF8 = encodeUTF8;
|
|
803
|
-
/**
|
|
804
|
-
* A manual decoding of a UTF8 string.
|
|
805
|
-
* Use only in environments which do not offer native conversion methods!
|
|
806
|
-
*/
|
|
807
|
-
function decodeUTF8(buffer) {
|
|
808
|
-
// https://en.wikipedia.org/wiki/UTF-8
|
|
809
|
-
const len = buffer.byteLength;
|
|
810
|
-
const result = [];
|
|
811
|
-
let offset = 0;
|
|
812
|
-
while (offset < len) {
|
|
813
|
-
const v0 = buffer[offset];
|
|
814
|
-
let codePoint;
|
|
815
|
-
if (v0 >= 0b11110000 && offset + 3 < len) {
|
|
816
|
-
// 4 bytes
|
|
817
|
-
codePoint =
|
|
818
|
-
(((buffer[offset++] & 0b00000111) << 18) >>> 0) |
|
|
819
|
-
(((buffer[offset++] & 0b00111111) << 12) >>> 0) |
|
|
820
|
-
(((buffer[offset++] & 0b00111111) << 6) >>> 0) |
|
|
821
|
-
(((buffer[offset++] & 0b00111111) << 0) >>> 0);
|
|
822
|
-
}
|
|
823
|
-
else if (v0 >= 0b11100000 && offset + 2 < len) {
|
|
824
|
-
// 3 bytes
|
|
825
|
-
codePoint =
|
|
826
|
-
(((buffer[offset++] & 0b00001111) << 12) >>> 0) |
|
|
827
|
-
(((buffer[offset++] & 0b00111111) << 6) >>> 0) |
|
|
828
|
-
(((buffer[offset++] & 0b00111111) << 0) >>> 0);
|
|
829
|
-
}
|
|
830
|
-
else if (v0 >= 0b11000000 && offset + 1 < len) {
|
|
831
|
-
// 2 bytes
|
|
832
|
-
codePoint = (((buffer[offset++] & 0b00011111) << 6) >>> 0) | (((buffer[offset++] & 0b00111111) << 0) >>> 0);
|
|
833
|
-
}
|
|
834
|
-
else {
|
|
835
|
-
// 1 byte
|
|
836
|
-
codePoint = buffer[offset++];
|
|
837
|
-
}
|
|
838
|
-
if ((codePoint >= 0 && codePoint <= 0xd7ff) || (codePoint >= 0xe000 && codePoint <= 0xffff)) {
|
|
839
|
-
// Basic Multilingual Plane
|
|
840
|
-
result.push(String.fromCharCode(codePoint));
|
|
841
|
-
}
|
|
842
|
-
else if (codePoint >= 0x010000 && codePoint <= 0x10ffff) {
|
|
843
|
-
// Supplementary Planes
|
|
844
|
-
const uPrime = codePoint - 0x10000;
|
|
845
|
-
const w1 = 0xd800 + ((uPrime & 0b11111111110000000000) >>> 10);
|
|
846
|
-
const w2 = 0xdc00 + ((uPrime & 0b00000000001111111111) >>> 0);
|
|
847
|
-
result.push(String.fromCharCode(w1));
|
|
848
|
-
result.push(String.fromCharCode(w2));
|
|
849
|
-
}
|
|
850
|
-
else {
|
|
851
|
-
// illegal code point
|
|
852
|
-
result.push(String.fromCharCode(0xfffd));
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
return result.join('');
|
|
856
|
-
}
|
|
857
|
-
exports.decodeUTF8 = decodeUTF8;
|
|
858
|
-
//# sourceMappingURL=strings.js.map
|