Skip to content

Instantly share code, notes, and snippets.

View guiseek's full-sized avatar
🌱
Winners don't care what others think, the real battle is overcoming yourself.

Guilherme Siquinelli guiseek

🌱
Winners don't care what others think, the real battle is overcoming yourself.
View GitHub Profile
@guiseek
guiseek / file-tree.html
Created December 9, 2023 15:32
File Tree
<file-tree class="not-content">
<ul>
<li class="directory" data-filetype="dir">
<details>
<summary>
<span class="tree-entry">
<span class="">
<span>
<span class="sr-only">Directory</span>
<svg
@guiseek
guiseek / extend.ts
Created December 9, 2023 06:46
Custom element extend eecorator
interface CustomConstructor<K extends keyof HTMLElementTagNameMap>
extends CustomElementConstructor {
new (...params: any[]): HTMLElementTagNameMap[K]
prototype: HTMLElementTagNameMap[K]
}
export const extend = <K extends keyof HTMLElementTagNameMap>(inherite: K) => {
return <T extends CustomConstructor<K>>(target: T) => {
customElements.define(`txs-${inherite}`, target, {extends: inherite})
}
@guiseek
guiseek / deep-pick.ts
Created December 6, 2023 16:55
Deep Pick
export const deepPick = <T extends object>(value: T) => {
return <K extends keyof T & string>(path: K) => {
return path.split('.').reduce<T[K]>((prev, curr) => {
return typeof prev[curr] === 'object' ? prev[curr] : prev;
}, value as T[K]);
};
};
export function deep<T extends object>(value: T) {
// prettier-ignore
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>
<body>
<figure id="figure">
@guiseek
guiseek / slugify.util.ts
Created September 9, 2023 09:49
Slugify
export const slugify = (...args: (string | number)[]): string => {
const value = args.join(' ');
return value
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.trim()
.replace(/[^a-z0-9 ]/g, '')
.replace(/\s+/g, '-');
@guiseek
guiseek / typed-form.ts
Created September 2, 2023 07:42
Angular Typed Form
type DetectTypedForm<T> =
T extends Array<infer U>
? FormArray<DetectTypedForm<U>>
: T extends Date
? FormControl<Date>
: T extends object
? FormGroup<TypedForm<T>>
: T extends true | false
? FormControl<boolean>
: T extends PropertyKey
@guiseek
guiseek / typed-form-model.ts
Last active August 27, 2023 00:22
Angular Recursive TypedForm
import type {TypedForm} from './typed-form'
type TypedFormModel<T> = {
// Verifique cada tipo do model
[K in keyof T]: TypedForm<T[K]>
}
export type {TypedFormModel}
type DOMEventMapDefinitions = [
[HTMLElement, HTMLElementEventMap],
[Document, DocumentEventMap],
[Window, WindowEventMap],
[FileReader, FileReaderEventMap],
[Element, ElementEventMap],
[Animation, AnimationEventMap],
[EventSource, EventSourceEventMap],
[AbortSignal, AbortSignalEventMap],
[AbstractWorker, AbstractWorkerEventMap],
@guiseek
guiseek / code.d.ts
Last active July 29, 2023 03:57
Create Nx Monorepo from Figma Figjam
type NxPluginName =
| 'js'
| 'web'
| 'node'
| 'nest'
| 'react'
| 'angular'
| 'express'
type NxProjectType = 'application' | 'library'
@guiseek
guiseek / main.ts
Created July 12, 2023 06:45
WebRTC Local
function create<K extends keyof HTMLElementTagNameMap>(
name: K,
attributes: Partial<HTMLElementTagNameMap[K]>,
...children: Element[]
): HTMLElementTagNameMap[K] {
const el = document.createElement(name)
if (children) el.append(...children)
return Object.assign(el, attributes)
}