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 / dom.ts
Created June 15, 2025 07:43
Dom utility factory
type Tag = keyof HTMLElementTagNameMap
type Dom = {
[T in Tag]: <A extends HTMLElementTagNameMap[T]>(
attrs: Partial<A>
) => HTMLElementTagNameMap[T]
}
// prettier-ignore
const TAGS: Tag[] = ['a','abbr','address','area','article','aside','audio','b','base','bdi','bdo','blockquote','body','br','button','canvas','caption','cite','code','col','colgroup','data','datalist','dd','del','details','dfn','dialog','div','dl','dt','em','embed','fieldset','figcaption','figure','footer','form','h1','h2','h3','h4','h5','h6','head','header','hgroup','hr','html','i','iframe','img','input','ins','kbd','label','legend','li','link','main','map','mark','menu','meta','meter','nav','noscript','object','ol','optgroup','option','output','p','picture','pre','progress','q','rp','rt','ruby','s','samp','script','search','section','select','slot','small','source','span','strong','style','sub','summary','sup','table','tbody','td','template','textarea','tfoot','th','thead','time','title','tr','track','u','ul','var','video','wbr',]
export class Alias<T> {
name: string
constructor(name: string) {
this.name = name
return this as Alias<T>
}
}
@guiseek
guiseek / main.ts
Created April 2, 2025 19:57
DI Skills
type Concrete<T> = new (...params: any[]) => T;
type Abstract<T> = abstract new (...params: any[]) => T;
type Factory<T> = (...params: any[]) => T;
type AsyncFactory<T> = (...params: any[]) => Promise<T>;
type Ref<T> = Concrete<T> | Abstract<T>;
type Use<T> = Concrete<T>;
export type Abstract<T, P extends unknown[] = never[]> = abstract new (
...args: P
) => T;
@guiseek
guiseek / di.ts
Created March 23, 2025 06:21
Tiny Dependency Injection
import { Abstract, AsyncFactory, Constructor, Factory, Params } from './types';
import { validate } from './validate';
import { Token } from './token';
type Ref<T> = Token<T> | Abstract<T> | Constructor<T>;
type Use<T> = Constructor<T> | Factory<T> | AsyncFactory<T> | T;
interface Config<T> {
ref: Ref<T>;
@guiseek
guiseek / logger.ts
Created March 10, 2025 03:11
NodeJS Console Table Logger
import { createWriteStream, PathLike } from "node:fs";
import { Console } from "node:console";
export const logger = <T>(path: PathLike, data: T[]) => {
const stream = createWriteStream(path);
const console = new Console(stream);
console.table(data);
@guiseek
guiseek / abstract.ts
Created November 14, 2024 08:11
Create providers
export type Abstract<T = any> = abstract new (...params: any[]) => T;
import {Abstract} from './abstract'
import {Type} from './type'
export type AbstractConstructorParams<T extends Type> =
ConstructorParameters<T> extends {
length: 1
}
? [Abstract<ConstructorParameters<T>[0]>]
: ConstructorParameters<T> extends {length: 2}
? [
@guiseek
guiseek / action.ts
Created August 15, 2024 07:49
State
import {Callback} from './callback'
export class Action<T> {
constructor(public type: string, public value: T) {}
}
export const createAction = <T>(type: string) => {
return class extends Action<T> {
constructor(value: T) {
super(type, value)
@guiseek
guiseek / merge.ts
Created August 3, 2024 22:59
merge form input events
interface Callback<T> {
(value: T): void;
}
function merge<T>(form: HTMLFormElement) {
const watchers = new Set<Callback<T>>();
const fields = Array.from(form.elements) as HTMLInputElement[];
const value = <T>(form: HTMLFormElement) => {
const data = new FormData(form);