This file contains hidden or 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
let str = 'foo bar baz' | |
str = str.replaceAll(/(\b +\b)/gm, '\n') | |
// foo | |
// bar | |
// baz |
This file contains hidden or 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 assignByKey<T, S extends T, K extends keyof T & keyof S>( | |
target: T, | |
source: S, | |
key: K | |
) { | |
target[key] = source[key] | |
} |
This file contains hidden or 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
// https://github.com/microsoft/TypeScript/issues/42644#issuecomment-774315112 | |
type StringLiteral<T> = T extends string | |
? string extends T | |
? never | |
: T | |
: never |
This file contains hidden or 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 generatePassword(length: number) { | |
const dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
const array = new Uint8Array(length); | |
self.crypto.getRandomValues(array); | |
let password = '' | |
for (var i = 0; i < array.length; i++) { | |
password += dict.charAt(array[i] % dict.length) | |
} |
This file contains hidden or 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 add(val: number): typeof add; | |
function add(): number; | |
function add(val?: number): number | typeof add { | |
if (val === undefined) return 0; | |
let sum = val; | |
function nextFn(val1: number): typeof nextFn; | |
function nextFn(): number; |
This file contains hidden or 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="tsx"> | |
import Vue, { VNode, AsyncComponent } from 'vue' | |
import { camelCase, upperFirst, mergeProps } from '@tds/c-utils' | |
interface Icons { | |
[key: string]: AsyncComponent<any> | |
} | |
const icons: Icons = {} | |
function getAsyncComponent(name = '') { | |
if (!(name in icons)) { |