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 memoize<TMemoizedFn extends (...args: any[]) => any>( | |
callback: TMemoizedFn, | |
checkArgs: boolean = true | |
): TMemoizedFn { | |
let memoized: true; | |
let memory: ReturnType<TMemoizedFn>; | |
let previousArgs: unknown[]; | |
return function __memoized(...args: unknown[]): ReturnType<TMemoizedFn> { | |
if (!memoized || (checkArgs && !isSameArgs(previousArgs, args))) { | |
memory = callback(...args); |
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 type StringConcat<TArgs extends string[]> = _Flatten<TArgs>; | |
type _Flatten<TArgs extends string[], _TArg extends string = ""> = | |
TArgs extends [infer TCurrent extends string, ...infer TNext extends string[]] | |
? _Flatten<TNext, `${_TArg}${TCurrent}`> | |
: _TArg; | |
export function stringConcat<const TArgs extends string[]>(...args: TArgs): StringConcat<TArgs> { | |
if (args.length === 0) return "" as StringConcat<TArgs>; | |
return "".concat(...args) as StringConcat<TArgs>; |
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 _JoinableElement = string | number | null | undefined | boolean; | |
type _JoinableArray = _JoinableElement[]; | |
export type JoinArray< | |
TArray extends _JoinableArray, | |
TDelimiter extends string = " " | |
> = _JoinArray<TArray, TDelimiter>; | |
type _JoinArray< | |
TArray extends _JoinableArray, |
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 com.google.common.base.Preconditions; | |
import com.google.errorprone.annotations.CanIgnoreReturnValue; | |
import com.google.errorprone.annotations.CheckReturnValue; | |
import lombok.Getter; | |
import org.checkerframework.checker.index.qual.NonNegative; | |
import org.checkerframework.checker.nullness.qual.NonNull; | |
import org.checkerframework.checker.nullness.qual.Nullable; | |
import org.checkerframework.dataflow.qual.Pure; | |
import java.util.*; |
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
package io.github.aparx.skywarz.utils.material; | |
import com.google.common.base.Preconditions; | |
import org.apache.commons.lang3.Validate; | |
import org.bukkit.DyeColor; | |
import org.bukkit.Material; | |
import org.checkerframework.checker.nullness.qual.NonNull; | |
import java.util.EnumMap; | |
import java.util.function.Function; |
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 Vinzent Zeband - you will need (./types imports) | |
* https://gist.github.com/zvint/a7fd6cdcb9054dd9b9d53164d0088e33 */ | |
import type { RecursiveRecord, SplitToTuple, SplitToUnion } from './types'; | |
// <==================================> | |
// MAIN OBJECT-PATH TYPES | |
// <==================================> | |
/** Non-specific property key that can be used to represent a path segment. */ | |
export type GenericPathSegment = string | number; |
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
// prettier-config-ignore | |
/** Typesafe alternative to Typescript's "Extract" type-utility */ | |
export type UnionExtract<TUnion, TKeys extends TUnion> = TUnion extends TKeys | |
? TUnion | |
: never; | |
// prettier-config-ignore | |
/** Typesafe alternative to Typescript's "Exclude" type-utility */ | |
export type UnionExclude<TUnion, TKeys extends TUnion> = TUnion extends TKeys | |
? never |
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
/* | |
* Example: | |
* | |
* | |
*/ | |
const ExampleUnitMap = { xl: 3.0, md: 1.0, sm: 0.5, }; | |
type ExampleUnit = keyof typeof ExampleUnitMap; |
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, useEffect } from 'react'; | |
export default function useDetectEventOutside< | |
TNode extends Node, | |
TEventType extends keyof DocumentEventMap | |
>( | |
reference: RefObject<TNode>, | |
eventType: TEventType, | |
eventListener: (this: Document, ev: DocumentEventMap[TEventType]) => any | |
) { |
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 type Primitives = | |
| number | |
| string | |
| boolean | |
| bigint | |
| symbol | |
| undefined | |
| null; | |
export type DeepReadonly<TInput> = TInput extends Primitives | Function |
NewerOlder