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
export default function stopPropagation(fn: (e: Event) => void) { | |
return function (this: (e: Event) => void, event: Event) { | |
event.stopPropagation(); | |
fn.call(this, event); | |
}; | |
} |
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
export default function clickOutside(node: HTMLElement) { | |
const handleClick = (event: MouseEvent) => { | |
if (!node.contains(event.target as Node)) { | |
node.dispatchEvent(new CustomEvent('outsideclick')); | |
} | |
}; | |
// The node has been mounted to the DOM | |
window.addEventListener('click', handleClick); |
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 generic Firestore converter that provides type inference | |
export const genericConverter = <T>() => ({ | |
toFirestore: (data: PartialWithFieldValue<T>) => data ?? {}, | |
fromFirestore: (snap: QueryDocumentSnapshot) => snap.data() as T, | |
}); | |
// A wrapper of collection() that uses a generic converter to provide type inference | |
export const typedCollection = <T>(db: Firestore, name: string) => | |
collection(db, name).withConverter<T>(genericConverter<T>()); |
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
{ | |
"bracketSameLine": true, | |
"printWidth": 80, | |
"singleQuote": true, | |
"tabWidth": 2, | |
"trailingComma": "all", | |
"useTabs": true | |
} |
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
import _ from 'lodash'; | |
/** | |
* Converts a tab-separted-values (TSV) file to a set of JSON objects | |
* where each value is keyed according to the heading row | |
*/ | |
const tsvToJson = tsv => { | |
// Split lines and filter any empties | |
const lines = tsv | |
.split('\n') // Split lines |
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 collection of static utility methods for unit testing. | |
*/ | |
@IsTest | |
public class TestUtil { | |
// ID generator configuration | |
private static final Integer ID_RESERVED_CHARACTERS = 7; | |
private static final Integer ID_INCREMENTER_PREFIX_LENGTH = 1; | |
private static final String BASE62_ALPHABET = '0123456789abcdefghijklmnopqrstuvwqyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
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 registry built around the Salesforce Mocking API that allows declarative mocking of HTTP callouts. Mocks responses | |
* can be registered either for a specific endpoint and path or for all paths on an endpoint, with the former taking | |
* precedence. | |
*/ | |
@IsTest | |
public class HttpMockRegistry { | |
// Default mock response for HTTP requests | |
public static final HttpResponse DEFAULT_MOCK_RESPONSE = createSuccessResponse('Default mock response'); |
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 UUID generator that can construct unique IDs in a variety of formats. | |
* | |
* A UUID is generated immediately upon instantiation of this class. The UUID can be retrieved in its normal form | |
* (e.g. f111b8c5-ca2f-4a1a-8d0d-a8dd5f37c05f) or as a shortened web-safe form (e.g. jp64hwPZ-Lh7vY8INQA7ImQPbQE), which | |
* is constructed by converting the UUID to Base64 and replacing '/' and '+' with '-' and '_', respectively. | |
*/ | |
public class Uuid { | |
private static final String HEX_PREFIX = '0x'; |
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 traversable JSON data structure. | |
* | |
* Conceptually, JSON is a general tree, or array of general trees. It is represented in Apex using Map<String, Object> | |
* for objects, List<Object> for arrays, String for strings, and either Integer or Decimal for numbers. This class wraps | |
* these data types in order to provide an interface for traversiing and querying the entire JSON structure. | |
* | |
* Each node contains a single value that must be a valid JSON value. That is, Map<String, Object>, List<Object>, | |
* String, Decimal, Integer, or null. When traversing or querying a JSON structure, any value returned is always wrapped | |
* in a JsonData instance to allow subsequent traversal or query. |
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
/* | |
* Returns the type of a given object. This is a hack around the fact that we can't access the type of an object. | |
* @param {Object} obj An object | |
* @returns {Type} the type of the object | |
*/ | |
private static Type getType(Object obj) { | |
String typeName = 'Date'; | |
// Attempt to cast the object to Datetime | |
// If it succeeds, the object is a date |