This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sorts an array of values using the criteria specified in a function. This is | |
* similar to the Python sort function in that `criteria` is run once for each | |
* value and then the return is used to sort the original values. Quick sort is | |
* used to sort the values. | |
* @template T | |
* @param {T[]} values | |
* The array of values that will be directly sorted and returned. | |
* @param {(value:T,index:number,values:T[])=>any} criteria | |
* A function that will return a value for each value in `values` indicating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A quick implementation of quick sort. | |
* @template T | |
* @param {T[]} values | |
* The values to sort. | |
* @returns {T[]} | |
* The sorted array of values. | |
*/ | |
function quickSort(values) { | |
const segments = [{start: 0, end: values.length - 1}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Takes a value and turns it into an array if it isn't already. | |
* @param {*} value | |
* The value that should be turned into an array. If this is already an | |
* array just return it. If this is a non-iterable value or is a string | |
* literal the returned value will be an array containing this value. | |
* Otherwise if this is iterable it will be returned as a new array. | |
* @returns {any[]} | |
* If `value` is already an array it will be returned, otherwise return a | |
* new array representing `value`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.addSelect({ | |
name: 'Value Field', | |
path: 'valueField', | |
category: ['Display'], | |
description: 'The field containing the values that will be represented by the bars on the bar chart.', | |
settings: { | |
options: [], | |
getOptions(context) { | |
const results = context.data[0]?.fields.map(f => ({value: f.name, label: `${f.name} (${f.type})`})) ?? []; | |
return results as any as Promise<SelectableValue[]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sends a request to the specified URL. | |
* @param {string} url | |
* The URL to which the request will be sent. | |
* @param {?request__Options=} options | |
* The various options to set on the request. | |
* @returns {Promise<XMLHttpRequest>} | |
* A promise of the corresponding `XMLHttpRequest`. | |
*/ | |
function request(url, options) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Continually calls `getValue()` with a state object that can be modified and | |
* the returned value will be compared to what was previously returned. If the | |
* return value is different than the previous, the `callback()` function will | |
* be called. | |
* @param {(currValue: any, state: State) => Value} getValue | |
* A function that is called after every interval (as specified by | |
* `msInterval`). The arguments passed will be (1) the previous value | |
* returned by this function and (2) the state object (which on the initial | |
* call starts off as an empty object but can be augmented). The return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function diff(left, right) { | |
function recurse(left, right, leftSeen, rightSeen, path) { | |
if (left === right || (left !== left && right !== right)) return []; | |
// If the constructors are different or if left and right are null and | |
// undefined but they are not the same... | |
if (left.constructor !== right?.constructor || left == null) { | |
return [{left, right, path, message: 'The values are not of the same type.'}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tries to turn a string value that looks like a boolean, number, null, | |
* undefined or BigInt into one of those types. | |
* @template {string} T | |
* @param {T} input | |
* @param {boolean} parseUrlBools | |
* @return {T|boolean|number|null|undefined|BigInt} | |
*/ | |
function infer(input, parseUrlBools) { | |
if (input && 'string' === typeof input) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Chris West | |
* Source: https://gist.github.com/westc/a921e805036707d7c5f818a32124789a#file-regexp-cls | |
* Description: | |
* A wrapper class for making it easier to work with regular expressions and | |
* also for accessing named capture groups (which wasn't when this solution | |
* was written). | |
*/ | |
public class RegExp { | |
private Pattern pat; |