Skip to content

Instantly share code, notes, and snippets.

View palpich's full-sized avatar
🧐
Time to think

Viacheslav Landau palpich

🧐
Time to think
View GitHub Profile
@palpich
palpich / replacer.ts
Created July 22, 2022 12:42
Find all spaces in str and replace to new line symbol
let str = 'foo bar baz'
str = str.replaceAll(/(\b +\b)/gm, '\n')
// foo
// bar
// baz
@palpich
palpich / assignByKey.ts
Created July 4, 2022 21:20
Assign By Key
function assignByKey<T, S extends T, K extends keyof T & keyof S>(
target: T,
source: S,
key: K
) {
target[key] = source[key]
}
@palpich
palpich / string-literal.ts
Created June 30, 2022 13:15
String Literal
// https://github.com/microsoft/TypeScript/issues/42644#issuecomment-774315112
type StringLiteral<T> = T extends string
? string extends T
? never
: T
: never
@palpich
palpich / generate-password.ts
Last active April 12, 2022 11:52
Simple password generate
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)
}
@palpich
palpich / add.ts
Created February 17, 2021 14:37
sdfsdf
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;
<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)) {