custom-electron-titlebar 3.2.5 → 3.2.9
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/.vscode/launch.json +49 -0
- package/.vscode/tasks.json +34 -0
- package/README.md +15 -24
- package/_config.yml +1 -0
- package/{lib → build}/browser/browser.d.ts +0 -0
- package/{lib → build}/browser/browser.js +1 -0
- package/build/browser/browser.js.map +1 -0
- package/{lib → build}/browser/event.d.ts +0 -0
- package/{lib → build}/browser/event.js +3 -1
- package/build/browser/event.js.map +1 -0
- package/{lib → build}/browser/iframe.d.ts +0 -0
- package/{lib/base → build}/browser/iframe.js +1 -0
- package/build/browser/iframe.js.map +1 -0
- package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
- package/{lib → build}/browser/keyboardEvent.js +1 -0
- package/build/browser/keyboardEvent.js.map +1 -0
- package/{lib → build}/browser/mouseEvent.d.ts +0 -0
- package/{lib → build}/browser/mouseEvent.js +1 -0
- package/build/browser/mouseEvent.js.map +1 -0
- package/{lib → build}/common/arrays.d.ts +0 -0
- package/{lib → build}/common/arrays.js +1 -0
- package/build/common/arrays.js.map +1 -0
- package/{lib → build}/common/async.d.ts +0 -0
- package/{lib → build}/common/async.js +1 -0
- package/build/common/async.js.map +1 -0
- package/{lib → build}/common/charCode.d.ts +0 -0
- package/{lib/base → build}/common/charCode.js +1 -0
- package/build/common/charCode.js.map +1 -0
- package/{lib → build}/common/color.d.ts +0 -0
- package/{lib → build}/common/color.js +1 -0
- package/build/common/color.js.map +1 -0
- package/{lib → build}/common/dom.d.ts +0 -0
- package/{lib → build}/common/dom.js +17 -14
- package/build/common/dom.js.map +1 -0
- package/{lib → build}/common/event.d.ts +0 -0
- package/{lib → build}/common/event.js +2 -1
- package/build/common/event.js.map +1 -0
- package/{lib → build}/common/iterator.d.ts +0 -0
- package/{lib → build}/common/iterator.js +1 -0
- package/build/common/iterator.js.map +1 -0
- package/{lib → build}/common/keyCodes.d.ts +0 -0
- package/{lib → build}/common/keyCodes.js +1 -0
- package/build/common/keyCodes.js.map +1 -0
- package/{lib → build}/common/lifecycle.d.ts +0 -0
- package/{lib → build}/common/lifecycle.js +1 -0
- package/build/common/lifecycle.js.map +1 -0
- package/{lib → build}/common/linkedList.d.ts +0 -0
- package/{lib → build}/common/linkedList.js +1 -0
- package/build/common/linkedList.js.map +1 -0
- package/{lib → build}/common/platform.d.ts +0 -0
- package/{lib → build}/common/platform.js +1 -0
- package/build/common/platform.js.map +1 -0
- package/{lib → build}/index.d.ts +0 -0
- package/{lib → build}/index.js +1 -0
- package/build/index.js.map +1 -0
- package/{lib → build}/menu/menu.d.ts +0 -0
- package/{lib → build}/menu/menu.js +39 -38
- package/build/menu/menu.js.map +1 -0
- package/{lib → build}/menu/menuitem.d.ts +10 -2
- package/{lib → build}/menu/menuitem.js +71 -29
- package/build/menu/menuitem.js.map +1 -0
- package/{lib → build}/menubar.d.ts +0 -0
- package/{lib → build}/menubar.js +38 -34
- package/build/menubar.js.map +1 -0
- package/{lib → build}/themebar.d.ts +0 -0
- package/{lib → build}/themebar.js +31 -2
- package/build/themebar.js.map +1 -0
- package/{lib → build}/titlebar.d.ts +0 -0
- package/{lib → build}/titlebar.js +72 -59
- package/build/titlebar.js.map +1 -0
- package/package.json +13 -7
- package/lib/base/browser/browser.d.ts +0 -25
- package/lib/base/browser/browser.js +0 -117
- package/lib/base/browser/canIUse.d.ts +0 -18
- package/lib/base/browser/canIUse.js +0 -63
- package/lib/base/browser/dom.d.ts +0 -230
- package/lib/base/browser/dom.js +0 -1080
- package/lib/base/browser/event.d.ts +0 -12
- package/lib/base/browser/event.js +0 -28
- package/lib/base/browser/iframe.d.ts +0 -33
- package/lib/base/browser/keyboardEvent.d.ts +0 -40
- package/lib/base/browser/keyboardEvent.js +0 -256
- package/lib/base/browser/mouseEvent.d.ts +0 -69
- package/lib/base/browser/mouseEvent.js +0 -146
- package/lib/base/common/arrays.d.ts +0 -149
- package/lib/base/common/arrays.js +0 -549
- package/lib/base/common/async.d.ts +0 -259
- package/lib/base/common/async.js +0 -728
- package/lib/base/common/cancellation.d.ts +0 -29
- package/lib/base/common/cancellation.js +0 -114
- package/lib/base/common/charCode.d.ts +0 -415
- package/lib/base/common/color.d.ts +0 -163
- package/lib/base/common/color.js +0 -495
- package/lib/base/common/errors.d.ts +0 -65
- package/lib/base/common/errors.js +0 -164
- package/lib/base/common/event.d.ts +0 -248
- package/lib/base/common/event.js +0 -703
- package/lib/base/common/functional.d.ts +0 -1
- package/lib/base/common/functional.js +0 -21
- package/lib/base/common/iterator.d.ts +0 -16
- package/lib/base/common/iterator.js +0 -82
- package/lib/base/common/keyCodes.d.ts +0 -268
- package/lib/base/common/keyCodes.js +0 -292
- package/lib/base/common/lifecycle.d.ts +0 -67
- package/lib/base/common/lifecycle.js +0 -234
- package/lib/base/common/linkedList.d.ts +0 -16
- package/lib/base/common/linkedList.js +0 -128
- package/lib/base/common/network.d.ts +0 -65
- package/lib/base/common/network.js +0 -124
- package/lib/base/common/path.d.ts +0 -39
- package/lib/base/common/path.js +0 -1407
- package/lib/base/common/platform.d.ts +0 -53
- package/lib/base/common/platform.js +0 -176
- package/lib/base/common/process.d.ts +0 -5
- package/lib/base/common/process.js +0 -18
- package/lib/base/common/sequence.d.ts +0 -27
- package/lib/base/common/sequence.js +0 -32
- package/lib/base/common/uri.d.ts +0 -153
- package/lib/base/common/uri.js +0 -612
- package/lib/browser/iframe.js +0 -109
- package/lib/common/charCode.js +0 -6
- package/lib/menu.d.ts +0 -53
- package/lib/menu.js +0 -532
- package/lib/menuitem.d.ts +0 -46
- package/lib/menuitem.js +0 -295
- package/lib/vs/base/browser/browser.d.ts +0 -25
- package/lib/vs/base/browser/browser.js +0 -117
- package/lib/vs/base/browser/canIUse.d.ts +0 -18
- package/lib/vs/base/browser/canIUse.js +0 -63
- package/lib/vs/base/browser/dom.d.ts +0 -230
- package/lib/vs/base/browser/dom.js +0 -1080
- package/lib/vs/base/browser/event.d.ts +0 -12
- package/lib/vs/base/browser/event.js +0 -28
- package/lib/vs/base/browser/iframe.d.ts +0 -33
- package/lib/vs/base/browser/iframe.js +0 -109
- package/lib/vs/base/browser/keyboardEvent.d.ts +0 -40
- package/lib/vs/base/browser/keyboardEvent.js +0 -256
- package/lib/vs/base/browser/mouseEvent.d.ts +0 -69
- package/lib/vs/base/browser/mouseEvent.js +0 -146
- package/lib/vs/base/common/arrays.d.ts +0 -149
- package/lib/vs/base/common/arrays.js +0 -549
- package/lib/vs/base/common/async.d.ts +0 -259
- package/lib/vs/base/common/async.js +0 -728
- package/lib/vs/base/common/cancellation.d.ts +0 -29
- package/lib/vs/base/common/cancellation.js +0 -114
- package/lib/vs/base/common/charCode.d.ts +0 -415
- package/lib/vs/base/common/charCode.js +0 -6
- package/lib/vs/base/common/color.d.ts +0 -163
- package/lib/vs/base/common/color.js +0 -495
- package/lib/vs/base/common/errors.d.ts +0 -65
- package/lib/vs/base/common/errors.js +0 -164
- package/lib/vs/base/common/event.d.ts +0 -248
- package/lib/vs/base/common/event.js +0 -703
- package/lib/vs/base/common/functional.d.ts +0 -1
- package/lib/vs/base/common/functional.js +0 -21
- package/lib/vs/base/common/iterator.d.ts +0 -16
- package/lib/vs/base/common/iterator.js +0 -82
- package/lib/vs/base/common/keyCodes.d.ts +0 -268
- package/lib/vs/base/common/keyCodes.js +0 -292
- package/lib/vs/base/common/lifecycle.d.ts +0 -67
- package/lib/vs/base/common/lifecycle.js +0 -234
- package/lib/vs/base/common/linkedList.d.ts +0 -16
- package/lib/vs/base/common/linkedList.js +0 -128
- package/lib/vs/base/common/network.d.ts +0 -65
- package/lib/vs/base/common/network.js +0 -124
- package/lib/vs/base/common/path.d.ts +0 -39
- package/lib/vs/base/common/path.js +0 -1407
- package/lib/vs/base/common/platform.d.ts +0 -53
- package/lib/vs/base/common/platform.js +0 -176
- package/lib/vs/base/common/process.d.ts +0 -5
- package/lib/vs/base/common/process.js +0 -18
- package/lib/vs/base/common/sequence.d.ts +0 -27
- package/lib/vs/base/common/sequence.js +0 -32
- package/lib/vs/base/common/uri.d.ts +0 -153
- package/lib/vs/base/common/uri.js +0 -612
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { CancellationToken } from './cancellation';
|
|
2
|
-
import { ISplice } from './sequence';
|
|
3
|
-
/**
|
|
4
|
-
* Returns the last element of an array.
|
|
5
|
-
* @param array The array.
|
|
6
|
-
* @param n Which element from the end (default is zero).
|
|
7
|
-
*/
|
|
8
|
-
export declare function tail<T>(array: ArrayLike<T>, n?: number): T;
|
|
9
|
-
export declare function tail2<T>(arr: T[]): [T[], T];
|
|
10
|
-
export declare function equals<T>(one: ReadonlyArray<T> | undefined, other: ReadonlyArray<T> | undefined, itemEquals?: (a: T, b: T) => boolean): boolean;
|
|
11
|
-
export declare function binarySearch<T>(array: ReadonlyArray<T>, key: T, comparator: (op1: T, op2: T) => number): number;
|
|
12
|
-
/**
|
|
13
|
-
* Takes a sorted array and a function p. The array is sorted in such a way that all elements where p(x) is false
|
|
14
|
-
* are located before all elements where p(x) is true.
|
|
15
|
-
* @returns the least x for which p(x) is true or array.length if no element fullfills the given function.
|
|
16
|
-
*/
|
|
17
|
-
export declare function findFirstInSorted<T>(array: ReadonlyArray<T>, p: (x: T) => boolean): number;
|
|
18
|
-
declare type Compare<T> = (a: T, b: T) => number;
|
|
19
|
-
/**
|
|
20
|
-
* Like `Array#sort` but always stable. Usually runs a little slower `than Array#sort`
|
|
21
|
-
* so only use this when actually needing stable sort.
|
|
22
|
-
*/
|
|
23
|
-
export declare function mergeSort<T>(data: T[], compare: Compare<T>): T[];
|
|
24
|
-
export declare function groupBy<T>(data: ReadonlyArray<T>, compare: (a: T, b: T) => number): T[][];
|
|
25
|
-
/**
|
|
26
|
-
* Diffs two *sorted* arrays and computes the splices which apply the diff.
|
|
27
|
-
*/
|
|
28
|
-
export declare function sortedDiff<T>(before: ReadonlyArray<T>, after: ReadonlyArray<T>, compare: (a: T, b: T) => number): ISplice<T>[];
|
|
29
|
-
/**
|
|
30
|
-
* Takes two *sorted* arrays and computes their delta (removed, added elements).
|
|
31
|
-
* Finishes in `Math.min(before.length, after.length)` steps.
|
|
32
|
-
*/
|
|
33
|
-
export declare function delta<T>(before: ReadonlyArray<T>, after: ReadonlyArray<T>, compare: (a: T, b: T) => number): {
|
|
34
|
-
removed: T[];
|
|
35
|
-
added: T[];
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Returns the top N elements from the array.
|
|
39
|
-
*
|
|
40
|
-
* Faster than sorting the entire array when the array is a lot larger than N.
|
|
41
|
-
*
|
|
42
|
-
* @param array The unsorted array.
|
|
43
|
-
* @param compare A sort function for the elements.
|
|
44
|
-
* @param n The number of elements to return.
|
|
45
|
-
* @return The first n elemnts from array when sorted with compare.
|
|
46
|
-
*/
|
|
47
|
-
export declare function top<T>(array: ReadonlyArray<T>, compare: (a: T, b: T) => number, n: number): T[];
|
|
48
|
-
/**
|
|
49
|
-
* Asynchronous variant of `top()` allowing for splitting up work in batches between which the event loop can run.
|
|
50
|
-
*
|
|
51
|
-
* Returns the top N elements from the array.
|
|
52
|
-
*
|
|
53
|
-
* Faster than sorting the entire array when the array is a lot larger than N.
|
|
54
|
-
*
|
|
55
|
-
* @param array The unsorted array.
|
|
56
|
-
* @param compare A sort function for the elements.
|
|
57
|
-
* @param n The number of elements to return.
|
|
58
|
-
* @param batch The number of elements to examine before yielding to the event loop.
|
|
59
|
-
* @return The first n elemnts from array when sorted with compare.
|
|
60
|
-
*/
|
|
61
|
-
export declare function topAsync<T>(array: T[], compare: (a: T, b: T) => number, n: number, batch: number, token?: CancellationToken): Promise<T[]>;
|
|
62
|
-
/**
|
|
63
|
-
* @returns New array with all falsy values removed. The original array IS NOT modified.
|
|
64
|
-
*/
|
|
65
|
-
export declare function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[];
|
|
66
|
-
/**
|
|
67
|
-
* Remove all falsey values from `array`. The original array IS modified.
|
|
68
|
-
*/
|
|
69
|
-
export declare function coalesceInPlace<T>(array: Array<T | undefined | null>): void;
|
|
70
|
-
/**
|
|
71
|
-
* Moves the element in the array for the provided positions.
|
|
72
|
-
*/
|
|
73
|
-
export declare function move(array: any[], from: number, to: number): void;
|
|
74
|
-
/**
|
|
75
|
-
* @returns false if the provided object is an array and not empty.
|
|
76
|
-
*/
|
|
77
|
-
export declare function isFalsyOrEmpty(obj: any): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* @returns True if the provided object is an array and has at least one element.
|
|
80
|
-
*/
|
|
81
|
-
export declare function isNonEmptyArray<T>(obj: T[] | undefined | null): obj is T[];
|
|
82
|
-
export declare function isNonEmptyArray<T>(obj: readonly T[] | undefined | null): obj is readonly T[];
|
|
83
|
-
/**
|
|
84
|
-
* Removes duplicates from the given array. The optional keyFn allows to specify
|
|
85
|
-
* how elements are checked for equalness by returning a unique string for each.
|
|
86
|
-
*/
|
|
87
|
-
export declare function distinct<T>(array: ReadonlyArray<T>, keyFn?: (t: T) => string): T[];
|
|
88
|
-
export declare function distinctES6<T>(array: ReadonlyArray<T>): T[];
|
|
89
|
-
export declare function uniqueFilter<T>(keyFn: (t: T) => string): (t: T) => boolean;
|
|
90
|
-
export declare function lastIndex<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): number;
|
|
91
|
-
/**
|
|
92
|
-
* @deprecated ES6: use `Array.findIndex`
|
|
93
|
-
*/
|
|
94
|
-
export declare function firstIndex<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): number;
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated ES6: use `Array.find`
|
|
97
|
-
*/
|
|
98
|
-
export declare function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T): T;
|
|
99
|
-
export declare function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): T | undefined;
|
|
100
|
-
export declare function firstOrDefault<T, NotFound = T>(array: ReadonlyArray<T>, notFoundValue: NotFound): T | NotFound;
|
|
101
|
-
export declare function firstOrDefault<T>(array: ReadonlyArray<T>): T | undefined;
|
|
102
|
-
export declare function commonPrefixLength<T>(one: ReadonlyArray<T>, other: ReadonlyArray<T>, equals?: (a: T, b: T) => boolean): number;
|
|
103
|
-
export declare function flatten<T>(arr: T[][]): T[];
|
|
104
|
-
export declare function range(to: number): number[];
|
|
105
|
-
export declare function range(from: number, to: number): number[];
|
|
106
|
-
export declare function index<T>(array: ReadonlyArray<T>, indexer: (t: T) => string): {
|
|
107
|
-
[key: string]: T;
|
|
108
|
-
};
|
|
109
|
-
export declare function index<T, R>(array: ReadonlyArray<T>, indexer: (t: T) => string, mapper: (t: T) => R): {
|
|
110
|
-
[key: string]: R;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Inserts an element into an array. Returns a function which, when
|
|
114
|
-
* called, will remove that element from the array.
|
|
115
|
-
*/
|
|
116
|
-
export declare function insert<T>(array: T[], element: T): () => void;
|
|
117
|
-
/**
|
|
118
|
-
* Removes an element from an array if it can be found.
|
|
119
|
-
*/
|
|
120
|
-
export declare function remove<T>(array: T[], element: T): T | undefined;
|
|
121
|
-
/**
|
|
122
|
-
* Insert `insertArr` inside `target` at `insertIndex`.
|
|
123
|
-
* Please don't touch unless you understand https://jsperf.com/inserting-an-array-within-an-array
|
|
124
|
-
*/
|
|
125
|
-
export declare function arrayInsert<T>(target: T[], insertIndex: number, insertArr: T[]): T[];
|
|
126
|
-
/**
|
|
127
|
-
* Uses Fisher-Yates shuffle to shuffle the given array
|
|
128
|
-
*/
|
|
129
|
-
export declare function shuffle<T>(array: T[], _seed?: number): void;
|
|
130
|
-
/**
|
|
131
|
-
* Pushes an element to the start of the array, if found.
|
|
132
|
-
*/
|
|
133
|
-
export declare function pushToStart<T>(arr: T[], value: T): void;
|
|
134
|
-
/**
|
|
135
|
-
* Pushes an element to the end of the array, if found.
|
|
136
|
-
*/
|
|
137
|
-
export declare function pushToEnd<T>(arr: T[], value: T): void;
|
|
138
|
-
/**
|
|
139
|
-
* @deprecated ES6: use `Array.find`
|
|
140
|
-
*/
|
|
141
|
-
export declare function find<T>(arr: ArrayLike<T>, predicate: (value: T, index: number, arr: ArrayLike<T>) => any): T | undefined;
|
|
142
|
-
export declare function mapArrayOrNot<T, U>(items: T | T[], fn: (_: T) => U): U | U[];
|
|
143
|
-
export declare function asArray<T>(x: T | T[]): T[];
|
|
144
|
-
/**
|
|
145
|
-
* @deprecated Use `Array.from` or `[...iter]`
|
|
146
|
-
*/
|
|
147
|
-
export declare function toArray<T>(iterable: IterableIterator<T>): T[];
|
|
148
|
-
export declare function getRandomElement<T>(arr: T[]): T | undefined;
|
|
149
|
-
export {};
|
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getRandomElement = exports.toArray = exports.asArray = exports.mapArrayOrNot = exports.find = exports.pushToEnd = exports.pushToStart = exports.shuffle = exports.arrayInsert = exports.remove = exports.insert = exports.index = exports.range = exports.flatten = exports.commonPrefixLength = exports.firstOrDefault = exports.first = exports.firstIndex = exports.lastIndex = exports.uniqueFilter = exports.distinctES6 = exports.distinct = exports.isNonEmptyArray = exports.isFalsyOrEmpty = exports.move = exports.coalesceInPlace = exports.coalesce = exports.topAsync = exports.top = exports.delta = exports.sortedDiff = exports.groupBy = exports.mergeSort = exports.findFirstInSorted = exports.binarySearch = exports.equals = exports.tail2 = exports.tail = void 0;
|
|
8
|
-
const errors_1 = require("./errors");
|
|
9
|
-
/**
|
|
10
|
-
* Returns the last element of an array.
|
|
11
|
-
* @param array The array.
|
|
12
|
-
* @param n Which element from the end (default is zero).
|
|
13
|
-
*/
|
|
14
|
-
function tail(array, n = 0) {
|
|
15
|
-
return array[array.length - (1 + n)];
|
|
16
|
-
}
|
|
17
|
-
exports.tail = tail;
|
|
18
|
-
function tail2(arr) {
|
|
19
|
-
if (arr.length === 0) {
|
|
20
|
-
throw new Error('Invalid tail call');
|
|
21
|
-
}
|
|
22
|
-
return [arr.slice(0, arr.length - 1), arr[arr.length - 1]];
|
|
23
|
-
}
|
|
24
|
-
exports.tail2 = tail2;
|
|
25
|
-
function equals(one, other, itemEquals = (a, b) => a === b) {
|
|
26
|
-
if (one === other) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
if (!one || !other) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (one.length !== other.length) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
for (let i = 0, len = one.length; i < len; i++) {
|
|
36
|
-
if (!itemEquals(one[i], other[i])) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
exports.equals = equals;
|
|
43
|
-
function binarySearch(array, key, comparator) {
|
|
44
|
-
let low = 0, high = array.length - 1;
|
|
45
|
-
while (low <= high) {
|
|
46
|
-
const mid = ((low + high) / 2) | 0;
|
|
47
|
-
const comp = comparator(array[mid], key);
|
|
48
|
-
if (comp < 0) {
|
|
49
|
-
low = mid + 1;
|
|
50
|
-
}
|
|
51
|
-
else if (comp > 0) {
|
|
52
|
-
high = mid - 1;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return mid;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return -(low + 1);
|
|
59
|
-
}
|
|
60
|
-
exports.binarySearch = binarySearch;
|
|
61
|
-
/**
|
|
62
|
-
* Takes a sorted array and a function p. The array is sorted in such a way that all elements where p(x) is false
|
|
63
|
-
* are located before all elements where p(x) is true.
|
|
64
|
-
* @returns the least x for which p(x) is true or array.length if no element fullfills the given function.
|
|
65
|
-
*/
|
|
66
|
-
function findFirstInSorted(array, p) {
|
|
67
|
-
let low = 0, high = array.length;
|
|
68
|
-
if (high === 0) {
|
|
69
|
-
return 0; // no children
|
|
70
|
-
}
|
|
71
|
-
while (low < high) {
|
|
72
|
-
const mid = Math.floor((low + high) / 2);
|
|
73
|
-
if (p(array[mid])) {
|
|
74
|
-
high = mid;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
low = mid + 1;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return low;
|
|
81
|
-
}
|
|
82
|
-
exports.findFirstInSorted = findFirstInSorted;
|
|
83
|
-
/**
|
|
84
|
-
* Like `Array#sort` but always stable. Usually runs a little slower `than Array#sort`
|
|
85
|
-
* so only use this when actually needing stable sort.
|
|
86
|
-
*/
|
|
87
|
-
function mergeSort(data, compare) {
|
|
88
|
-
_sort(data, compare, 0, data.length - 1, []);
|
|
89
|
-
return data;
|
|
90
|
-
}
|
|
91
|
-
exports.mergeSort = mergeSort;
|
|
92
|
-
function _merge(a, compare, lo, mid, hi, aux) {
|
|
93
|
-
let leftIdx = lo, rightIdx = mid + 1;
|
|
94
|
-
for (let i = lo; i <= hi; i++) {
|
|
95
|
-
aux[i] = a[i];
|
|
96
|
-
}
|
|
97
|
-
for (let i = lo; i <= hi; i++) {
|
|
98
|
-
if (leftIdx > mid) {
|
|
99
|
-
// left side consumed
|
|
100
|
-
a[i] = aux[rightIdx++];
|
|
101
|
-
}
|
|
102
|
-
else if (rightIdx > hi) {
|
|
103
|
-
// right side consumed
|
|
104
|
-
a[i] = aux[leftIdx++];
|
|
105
|
-
}
|
|
106
|
-
else if (compare(aux[rightIdx], aux[leftIdx]) < 0) {
|
|
107
|
-
// right element is less -> comes first
|
|
108
|
-
a[i] = aux[rightIdx++];
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// left element comes first (less or equal)
|
|
112
|
-
a[i] = aux[leftIdx++];
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function _sort(a, compare, lo, hi, aux) {
|
|
117
|
-
if (hi <= lo) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const mid = lo + ((hi - lo) / 2) | 0;
|
|
121
|
-
_sort(a, compare, lo, mid, aux);
|
|
122
|
-
_sort(a, compare, mid + 1, hi, aux);
|
|
123
|
-
if (compare(a[mid], a[mid + 1]) <= 0) {
|
|
124
|
-
// left and right are sorted and if the last-left element is less
|
|
125
|
-
// or equals than the first-right element there is nothing else
|
|
126
|
-
// to do
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
_merge(a, compare, lo, mid, hi, aux);
|
|
130
|
-
}
|
|
131
|
-
function groupBy(data, compare) {
|
|
132
|
-
const result = [];
|
|
133
|
-
let currentGroup = undefined;
|
|
134
|
-
for (const element of mergeSort(data.slice(0), compare)) {
|
|
135
|
-
if (!currentGroup || compare(currentGroup[0], element) !== 0) {
|
|
136
|
-
currentGroup = [element];
|
|
137
|
-
result.push(currentGroup);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
currentGroup.push(element);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
exports.groupBy = groupBy;
|
|
146
|
-
/**
|
|
147
|
-
* Diffs two *sorted* arrays and computes the splices which apply the diff.
|
|
148
|
-
*/
|
|
149
|
-
function sortedDiff(before, after, compare) {
|
|
150
|
-
const result = [];
|
|
151
|
-
function pushSplice(start, deleteCount, toInsert) {
|
|
152
|
-
if (deleteCount === 0 && toInsert.length === 0) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const latest = result[result.length - 1];
|
|
156
|
-
if (latest && latest.start + latest.deleteCount === start) {
|
|
157
|
-
latest.deleteCount += deleteCount;
|
|
158
|
-
latest.toInsert.push(...toInsert);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
result.push({ start, deleteCount, toInsert });
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
let beforeIdx = 0;
|
|
165
|
-
let afterIdx = 0;
|
|
166
|
-
while (true) {
|
|
167
|
-
if (beforeIdx === before.length) {
|
|
168
|
-
pushSplice(beforeIdx, 0, after.slice(afterIdx));
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
if (afterIdx === after.length) {
|
|
172
|
-
pushSplice(beforeIdx, before.length - beforeIdx, []);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
const beforeElement = before[beforeIdx];
|
|
176
|
-
const afterElement = after[afterIdx];
|
|
177
|
-
const n = compare(beforeElement, afterElement);
|
|
178
|
-
if (n === 0) {
|
|
179
|
-
// equal
|
|
180
|
-
beforeIdx += 1;
|
|
181
|
-
afterIdx += 1;
|
|
182
|
-
}
|
|
183
|
-
else if (n < 0) {
|
|
184
|
-
// beforeElement is smaller -> before element removed
|
|
185
|
-
pushSplice(beforeIdx, 1, []);
|
|
186
|
-
beforeIdx += 1;
|
|
187
|
-
}
|
|
188
|
-
else if (n > 0) {
|
|
189
|
-
// beforeElement is greater -> after element added
|
|
190
|
-
pushSplice(beforeIdx, 0, [afterElement]);
|
|
191
|
-
afterIdx += 1;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
exports.sortedDiff = sortedDiff;
|
|
197
|
-
/**
|
|
198
|
-
* Takes two *sorted* arrays and computes their delta (removed, added elements).
|
|
199
|
-
* Finishes in `Math.min(before.length, after.length)` steps.
|
|
200
|
-
*/
|
|
201
|
-
function delta(before, after, compare) {
|
|
202
|
-
const splices = sortedDiff(before, after, compare);
|
|
203
|
-
const removed = [];
|
|
204
|
-
const added = [];
|
|
205
|
-
for (const splice of splices) {
|
|
206
|
-
removed.push(...before.slice(splice.start, splice.start + splice.deleteCount));
|
|
207
|
-
added.push(...splice.toInsert);
|
|
208
|
-
}
|
|
209
|
-
return { removed, added };
|
|
210
|
-
}
|
|
211
|
-
exports.delta = delta;
|
|
212
|
-
/**
|
|
213
|
-
* Returns the top N elements from the array.
|
|
214
|
-
*
|
|
215
|
-
* Faster than sorting the entire array when the array is a lot larger than N.
|
|
216
|
-
*
|
|
217
|
-
* @param array The unsorted array.
|
|
218
|
-
* @param compare A sort function for the elements.
|
|
219
|
-
* @param n The number of elements to return.
|
|
220
|
-
* @return The first n elemnts from array when sorted with compare.
|
|
221
|
-
*/
|
|
222
|
-
function top(array, compare, n) {
|
|
223
|
-
if (n === 0) {
|
|
224
|
-
return [];
|
|
225
|
-
}
|
|
226
|
-
const result = array.slice(0, n).sort(compare);
|
|
227
|
-
topStep(array, compare, result, n, array.length);
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
exports.top = top;
|
|
231
|
-
/**
|
|
232
|
-
* Asynchronous variant of `top()` allowing for splitting up work in batches between which the event loop can run.
|
|
233
|
-
*
|
|
234
|
-
* Returns the top N elements from the array.
|
|
235
|
-
*
|
|
236
|
-
* Faster than sorting the entire array when the array is a lot larger than N.
|
|
237
|
-
*
|
|
238
|
-
* @param array The unsorted array.
|
|
239
|
-
* @param compare A sort function for the elements.
|
|
240
|
-
* @param n The number of elements to return.
|
|
241
|
-
* @param batch The number of elements to examine before yielding to the event loop.
|
|
242
|
-
* @return The first n elemnts from array when sorted with compare.
|
|
243
|
-
*/
|
|
244
|
-
function topAsync(array, compare, n, batch, token) {
|
|
245
|
-
if (n === 0) {
|
|
246
|
-
return Promise.resolve([]);
|
|
247
|
-
}
|
|
248
|
-
return new Promise((resolve, reject) => {
|
|
249
|
-
(async () => {
|
|
250
|
-
const o = array.length;
|
|
251
|
-
const result = array.slice(0, n).sort(compare);
|
|
252
|
-
for (let i = n, m = Math.min(n + batch, o); i < o; i = m, m = Math.min(m + batch, o)) {
|
|
253
|
-
if (i > n) {
|
|
254
|
-
await new Promise(resolve => setTimeout(resolve)); // nextTick() would starve I/O.
|
|
255
|
-
}
|
|
256
|
-
if (token && token.isCancellationRequested) {
|
|
257
|
-
throw errors_1.canceled();
|
|
258
|
-
}
|
|
259
|
-
topStep(array, compare, result, i, m);
|
|
260
|
-
}
|
|
261
|
-
return result;
|
|
262
|
-
})()
|
|
263
|
-
.then(resolve, reject);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
exports.topAsync = topAsync;
|
|
267
|
-
function topStep(array, compare, result, i, m) {
|
|
268
|
-
for (const n = result.length; i < m; i++) {
|
|
269
|
-
const element = array[i];
|
|
270
|
-
if (compare(element, result[n - 1]) < 0) {
|
|
271
|
-
result.pop();
|
|
272
|
-
const j = findFirstInSorted(result, e => compare(element, e) < 0);
|
|
273
|
-
result.splice(j, 0, element);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* @returns New array with all falsy values removed. The original array IS NOT modified.
|
|
279
|
-
*/
|
|
280
|
-
function coalesce(array) {
|
|
281
|
-
return array.filter(e => !!e);
|
|
282
|
-
}
|
|
283
|
-
exports.coalesce = coalesce;
|
|
284
|
-
/**
|
|
285
|
-
* Remove all falsey values from `array`. The original array IS modified.
|
|
286
|
-
*/
|
|
287
|
-
function coalesceInPlace(array) {
|
|
288
|
-
let to = 0;
|
|
289
|
-
for (let i = 0; i < array.length; i++) {
|
|
290
|
-
if (!!array[i]) {
|
|
291
|
-
array[to] = array[i];
|
|
292
|
-
to += 1;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
array.length = to;
|
|
296
|
-
}
|
|
297
|
-
exports.coalesceInPlace = coalesceInPlace;
|
|
298
|
-
/**
|
|
299
|
-
* Moves the element in the array for the provided positions.
|
|
300
|
-
*/
|
|
301
|
-
function move(array, from, to) {
|
|
302
|
-
array.splice(to, 0, array.splice(from, 1)[0]);
|
|
303
|
-
}
|
|
304
|
-
exports.move = move;
|
|
305
|
-
/**
|
|
306
|
-
* @returns false if the provided object is an array and not empty.
|
|
307
|
-
*/
|
|
308
|
-
function isFalsyOrEmpty(obj) {
|
|
309
|
-
return !Array.isArray(obj) || obj.length === 0;
|
|
310
|
-
}
|
|
311
|
-
exports.isFalsyOrEmpty = isFalsyOrEmpty;
|
|
312
|
-
function isNonEmptyArray(obj) {
|
|
313
|
-
return Array.isArray(obj) && obj.length > 0;
|
|
314
|
-
}
|
|
315
|
-
exports.isNonEmptyArray = isNonEmptyArray;
|
|
316
|
-
/**
|
|
317
|
-
* Removes duplicates from the given array. The optional keyFn allows to specify
|
|
318
|
-
* how elements are checked for equalness by returning a unique string for each.
|
|
319
|
-
*/
|
|
320
|
-
function distinct(array, keyFn) {
|
|
321
|
-
if (!keyFn) {
|
|
322
|
-
return array.filter((element, position) => {
|
|
323
|
-
return array.indexOf(element) === position;
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
const seen = Object.create(null);
|
|
327
|
-
return array.filter((elem) => {
|
|
328
|
-
const key = keyFn(elem);
|
|
329
|
-
if (seen[key]) {
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
seen[key] = true;
|
|
333
|
-
return true;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
exports.distinct = distinct;
|
|
337
|
-
function distinctES6(array) {
|
|
338
|
-
const seen = new Set();
|
|
339
|
-
return array.filter(element => {
|
|
340
|
-
if (seen.has(element)) {
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
seen.add(element);
|
|
344
|
-
return true;
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
exports.distinctES6 = distinctES6;
|
|
348
|
-
function uniqueFilter(keyFn) {
|
|
349
|
-
const seen = Object.create(null);
|
|
350
|
-
return element => {
|
|
351
|
-
const key = keyFn(element);
|
|
352
|
-
if (seen[key]) {
|
|
353
|
-
return false;
|
|
354
|
-
}
|
|
355
|
-
seen[key] = true;
|
|
356
|
-
return true;
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
exports.uniqueFilter = uniqueFilter;
|
|
360
|
-
function lastIndex(array, fn) {
|
|
361
|
-
for (let i = array.length - 1; i >= 0; i--) {
|
|
362
|
-
const element = array[i];
|
|
363
|
-
if (fn(element)) {
|
|
364
|
-
return i;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return -1;
|
|
368
|
-
}
|
|
369
|
-
exports.lastIndex = lastIndex;
|
|
370
|
-
/**
|
|
371
|
-
* @deprecated ES6: use `Array.findIndex`
|
|
372
|
-
*/
|
|
373
|
-
function firstIndex(array, fn) {
|
|
374
|
-
for (let i = 0; i < array.length; i++) {
|
|
375
|
-
const element = array[i];
|
|
376
|
-
if (fn(element)) {
|
|
377
|
-
return i;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return -1;
|
|
381
|
-
}
|
|
382
|
-
exports.firstIndex = firstIndex;
|
|
383
|
-
function first(array, fn, notFoundValue = undefined) {
|
|
384
|
-
const index = firstIndex(array, fn);
|
|
385
|
-
return index < 0 ? notFoundValue : array[index];
|
|
386
|
-
}
|
|
387
|
-
exports.first = first;
|
|
388
|
-
function firstOrDefault(array, notFoundValue) {
|
|
389
|
-
return array.length > 0 ? array[0] : notFoundValue;
|
|
390
|
-
}
|
|
391
|
-
exports.firstOrDefault = firstOrDefault;
|
|
392
|
-
function commonPrefixLength(one, other, equals = (a, b) => a === b) {
|
|
393
|
-
let result = 0;
|
|
394
|
-
for (let i = 0, len = Math.min(one.length, other.length); i < len && equals(one[i], other[i]); i++) {
|
|
395
|
-
result++;
|
|
396
|
-
}
|
|
397
|
-
return result;
|
|
398
|
-
}
|
|
399
|
-
exports.commonPrefixLength = commonPrefixLength;
|
|
400
|
-
function flatten(arr) {
|
|
401
|
-
return [].concat(...arr);
|
|
402
|
-
}
|
|
403
|
-
exports.flatten = flatten;
|
|
404
|
-
function range(arg, to) {
|
|
405
|
-
let from = typeof to === 'number' ? arg : 0;
|
|
406
|
-
if (typeof to === 'number') {
|
|
407
|
-
from = arg;
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
from = 0;
|
|
411
|
-
to = arg;
|
|
412
|
-
}
|
|
413
|
-
const result = [];
|
|
414
|
-
if (from <= to) {
|
|
415
|
-
for (let i = from; i < to; i++) {
|
|
416
|
-
result.push(i);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
for (let i = from; i > to; i--) {
|
|
421
|
-
result.push(i);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return result;
|
|
425
|
-
}
|
|
426
|
-
exports.range = range;
|
|
427
|
-
function index(array, indexer, mapper) {
|
|
428
|
-
return array.reduce((r, t) => {
|
|
429
|
-
r[indexer(t)] = mapper ? mapper(t) : t;
|
|
430
|
-
return r;
|
|
431
|
-
}, Object.create(null));
|
|
432
|
-
}
|
|
433
|
-
exports.index = index;
|
|
434
|
-
/**
|
|
435
|
-
* Inserts an element into an array. Returns a function which, when
|
|
436
|
-
* called, will remove that element from the array.
|
|
437
|
-
*/
|
|
438
|
-
function insert(array, element) {
|
|
439
|
-
array.push(element);
|
|
440
|
-
return () => remove(array, element);
|
|
441
|
-
}
|
|
442
|
-
exports.insert = insert;
|
|
443
|
-
/**
|
|
444
|
-
* Removes an element from an array if it can be found.
|
|
445
|
-
*/
|
|
446
|
-
function remove(array, element) {
|
|
447
|
-
const index = array.indexOf(element);
|
|
448
|
-
if (index > -1) {
|
|
449
|
-
array.splice(index, 1);
|
|
450
|
-
return element;
|
|
451
|
-
}
|
|
452
|
-
return undefined;
|
|
453
|
-
}
|
|
454
|
-
exports.remove = remove;
|
|
455
|
-
/**
|
|
456
|
-
* Insert `insertArr` inside `target` at `insertIndex`.
|
|
457
|
-
* Please don't touch unless you understand https://jsperf.com/inserting-an-array-within-an-array
|
|
458
|
-
*/
|
|
459
|
-
function arrayInsert(target, insertIndex, insertArr) {
|
|
460
|
-
const before = target.slice(0, insertIndex);
|
|
461
|
-
const after = target.slice(insertIndex);
|
|
462
|
-
return before.concat(insertArr, after);
|
|
463
|
-
}
|
|
464
|
-
exports.arrayInsert = arrayInsert;
|
|
465
|
-
/**
|
|
466
|
-
* Uses Fisher-Yates shuffle to shuffle the given array
|
|
467
|
-
*/
|
|
468
|
-
function shuffle(array, _seed) {
|
|
469
|
-
let rand;
|
|
470
|
-
if (typeof _seed === 'number') {
|
|
471
|
-
let seed = _seed;
|
|
472
|
-
// Seeded random number generator in JS. Modified from:
|
|
473
|
-
// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
|
|
474
|
-
rand = () => {
|
|
475
|
-
const x = Math.sin(seed++) * 179426549; // throw away most significant digits and reduce any potential bias
|
|
476
|
-
return x - Math.floor(x);
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
rand = Math.random;
|
|
481
|
-
}
|
|
482
|
-
for (let i = array.length - 1; i > 0; i -= 1) {
|
|
483
|
-
const j = Math.floor(rand() * (i + 1));
|
|
484
|
-
const temp = array[i];
|
|
485
|
-
array[i] = array[j];
|
|
486
|
-
array[j] = temp;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
exports.shuffle = shuffle;
|
|
490
|
-
/**
|
|
491
|
-
* Pushes an element to the start of the array, if found.
|
|
492
|
-
*/
|
|
493
|
-
function pushToStart(arr, value) {
|
|
494
|
-
const index = arr.indexOf(value);
|
|
495
|
-
if (index > -1) {
|
|
496
|
-
arr.splice(index, 1);
|
|
497
|
-
arr.unshift(value);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
exports.pushToStart = pushToStart;
|
|
501
|
-
/**
|
|
502
|
-
* Pushes an element to the end of the array, if found.
|
|
503
|
-
*/
|
|
504
|
-
function pushToEnd(arr, value) {
|
|
505
|
-
const index = arr.indexOf(value);
|
|
506
|
-
if (index > -1) {
|
|
507
|
-
arr.splice(index, 1);
|
|
508
|
-
arr.push(value);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
exports.pushToEnd = pushToEnd;
|
|
512
|
-
/**
|
|
513
|
-
* @deprecated ES6: use `Array.find`
|
|
514
|
-
*/
|
|
515
|
-
function find(arr, predicate) {
|
|
516
|
-
for (let i = 0; i < arr.length; i++) {
|
|
517
|
-
const element = arr[i];
|
|
518
|
-
if (predicate(element, i, arr)) {
|
|
519
|
-
return element;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return undefined;
|
|
523
|
-
}
|
|
524
|
-
exports.find = find;
|
|
525
|
-
function mapArrayOrNot(items, fn) {
|
|
526
|
-
return Array.isArray(items) ?
|
|
527
|
-
items.map(fn) :
|
|
528
|
-
fn(items);
|
|
529
|
-
}
|
|
530
|
-
exports.mapArrayOrNot = mapArrayOrNot;
|
|
531
|
-
function asArray(x) {
|
|
532
|
-
return Array.isArray(x) ? x : [x];
|
|
533
|
-
}
|
|
534
|
-
exports.asArray = asArray;
|
|
535
|
-
/**
|
|
536
|
-
* @deprecated Use `Array.from` or `[...iter]`
|
|
537
|
-
*/
|
|
538
|
-
function toArray(iterable) {
|
|
539
|
-
const result = [];
|
|
540
|
-
for (let element of iterable) {
|
|
541
|
-
result.push(element);
|
|
542
|
-
}
|
|
543
|
-
return result;
|
|
544
|
-
}
|
|
545
|
-
exports.toArray = toArray;
|
|
546
|
-
function getRandomElement(arr) {
|
|
547
|
-
return arr[Math.floor(Math.random() * arr.length)];
|
|
548
|
-
}
|
|
549
|
-
exports.getRandomElement = getRandomElement;
|