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
@mixin grid($cols, $rowGap: 0, $colGap: 0, $flexGrow: false) { | |
display: flex; | |
gap: #{$rowGap}px #{$colGap}px; | |
flex-wrap: wrap; | |
.col { | |
flex-basis: calc((100% - #{$colGap}px * (#{$cols} - 1)) / #{$cols}); | |
@if $flexGrow == true { | |
flex-grow: 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
function groupStrings(strings) { | |
return Object.values(strings.sort().reduce((a, str) => { | |
const s = str.toLowerCase(); | |
const f = s[0]; | |
a[f] = a[f] ? [...a[f], s] : [s]; | |
return a; | |
}, {})); | |
} |
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
/** | |
* Format bytes as human-readable text. | |
* @param {number} bytes Number of bytes. | |
* @param {number} decimalPlaces Number of decimal places to display. | |
* @param {number} baseQuantity Number of bytes in a kilobyte. | |
* @param {string[]} sizes The unites to use for each power of the baseQuantity. | |
* @return {string} Formatted byte size. | |
*/ | |
export const formatBytes = ( | |
bytes, |
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() { | |
if (typeof URL != 'function') { | |
rewriteURL(); | |
} else if (!('searchParams' in new URL(window.location))) { | |
rewriteURL(); | |
} | |
function rewriteURL() { | |
// Overwrite URL if no searchParams property exists. |
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 Converted<T, TOriginal, TNew> = T extends TOriginal | |
? TNew | |
: T extends Array<infer U> | |
? Converted<U, TOriginal, TNew>[] | |
: T extends object | |
? { [K in keyof T]: Converted<T[K], TOriginal, TNew> } | |
: T; | |
function convert<T, TOriginal, TNew>( | |
value: 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
/** | |
* Construct a type based off T where TDefinedField is defined when | |
* T matches TDefinedState. | |
*/ | |
type DefinedWhen< | |
T extends Record<string, any>, | |
TDefinedField extends keyof T, | |
TDefinedState extends Partial<T>, | |
> = | |
| (Omit<T, TDefinedField | keyof TDefinedState> & |
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
/** | |
* Conducts a binary search on a sorted array of items to find the index of a | |
* specific target. If the target is not found, it returns the nearest index | |
* based on the comparator function. | |
* | |
* @param items - The sorted array of items to search within. | |
* @param compare - A comparator function that returns: | |
* - a negative number if `item` is less than the target, | |
* - a positive number if `item` is greater than the target, | |
* - and 0 if `item` is equal to the target. |
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
/** | |
* Converts a hyphenated string to camel case. | |
* | |
* @example | |
* camelCase('foo-bar') // 'fooBar' | |
*/ | |
export function camelCase<S>(str: S): CamelCase<S> { | |
return ( | |
typeof str === 'string' | |
? str.toLowerCase().replace(/-+([^-])/g, (_, c) => c.toUpperCase()) |
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 os from "node:os"; | |
import path from "node:path"; | |
/** | |
* Get the path to an app specific config directory based on operating system | |
* standards. | |
* @param projectName | |
* @returns | |
*/ | |
export function getOSConfigDir(projectName: string): string { |
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
/** | |
* Attempts to get the path to the file that called the function that called | |
* this function. | |
* @example | |
* | |
* #### Caller: | |
* ```ts | |
* // /path/to/file.ts | |
* import { foo } from './path/to/foo.ts'; | |
* |
OlderNewer