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
type AllowedFieldsWithType<TObj, TKey> = { | |
[K in keyof TObj]: TObj[K] extends TKey ? K : never; | |
}; | |
export type FieldsOfType<T, K> = AllowedFieldsWithType<T, K>[keyof T]; | |
// Usage Example: | |
// | |
// const obj = { | |
// foo: 'bar', |
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
/** | |
* Creates a deep clone of an object. | |
* | |
* Internally uses `structuredClone` when available and | |
* `JSON.parse(JSON.stringify(obj))` as fallback. | |
* | |
* @param obj - The object to be cloned. | |
* @return The deep clone of the object. | |
*/ | |
export default function cloneDeep<T>(value: T): 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
import { RefObject, useCallback, useEffect, useState } from 'react'; | |
export interface ScrollToOptions { | |
x?: number; | |
y?: number; | |
behavior?: ScrollBehavior; | |
} | |
export interface UseScrollOptions { | |
disabled?: boolean; |
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 { getContext, setContext } from "svelte"; | |
/** | |
* The context object. | |
*/ | |
export interface Context<T> { | |
get: () => T; | |
set: (ctx: T) => 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
import findValue, { FindValueFilterMapper } from './findValue'; | |
describe('findValue(value, predicate)', () => { | |
const FILTER_MAPPER: FindValueFilterMapper<number, string> = (v) => { | |
if (v < 0) { | |
return [true, 'negative']; | |
} | |
if (v % 2 === 1) { | |
return [false, 'odd']; | |
} |
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 eventually(callback, timeout = 2000, pollInterval = 50) { | |
return new Promise((resolve, reject) => { | |
let intervalTimer; | |
let lastError; | |
const timeoutTimer = setTimeout(() => { | |
if (!intervalTimer) return; | |
clearTimeout(intervalTimer); | |
reject(lastError || new Error('eventually timed out')); |
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
const observer = new IntersectionObserver((entries) => { | |
entries.forEach((entry) => { | |
let eventType: string; | |
if (entry.isIntersecting) { | |
eventType = 'viewportenter'; | |
} else { | |
eventType = 'viewportleave'; | |
} |
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
<script lang="ts"> | |
import { createEventDispatcher } from 'svelte'; | |
import { CubeSide } from './CubeSide'; | |
export let view: CubeSide = CubeSide.Front; | |
export let transition: boolean = false; | |
export let transitionDuration: number = 2000; | |
export let backface: boolean = false; | |
export let perspective: string = '1000px'; | |
export let width: string = '100%'; |
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 function formDataToObject(formData: FormData): Record<string, FormDataEntryValue> { | |
const data: Record<string, FormDataEntryValue> = {}; | |
for (let [key, value] of formData.entries()) { | |
data[key] = value; | |
} | |
return data; | |
} |
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
#/bin/bash | |
set -ex | |
VERSION="8.8.4" | |
# or: VERSION="$1" | |
if [ "$VERSION" = "" ] | |
then | |
echo "no version specified" >&2 |
NewerOlder