Skip to content

Instantly share code, notes, and snippets.

View guiseek's full-sized avatar
🌱
Nós poderíamos ser muito melhores se não quiséssemos ser tão bons.

Guilherme Siquinelli guiseek

🌱
Nós poderíamos ser muito melhores se não quiséssemos ser tão bons.
View GitHub Profile
@guiseek
guiseek / jsx.d.ts
Last active January 18, 2024 16:04
JSX
declare namespace JSX {
type ElementTagNameMap = HTMLElementTagNameMap &
SVGElementTagNameMap &
MathMLElementTagNameMap;
type Element<K extends keyof ElementTagNameMap = 'div'> = {
[A in keyof ElementTagNameMap[K]]: ElementTagNameMap[K][A];
};
type IntrinsicElements = {
@guiseek
guiseek / between.ts
Created January 15, 2024 14:48
Between dates
// Date difference in seconds
// Calculating the date difference in seconds is as simple as subtracting the two Date objects and dividing by the number of milliseconds in a second (1000).
const dateDifferenceInSeconds = (dateInitial: Date, dateFinal: Date) =>
(dateFinal - dateInitial) / 1_000;
dateDifferenceInSeconds(
new Date('2020-12-24 00:00:15'),
new Date('2020-12-24 00:00:17')
); // 2
@guiseek
guiseek / deep-value.ts
Created January 12, 2024 01:13
Deep Value
type Path<T extends unknown[]> = T extends [
infer A,
infer B,
infer C,
infer D,
infer E,
infer F,
infer G,
infer H,
infer I
@guiseek
guiseek / deep-value.ts
Last active January 7, 2024 11:37
deep value
export function deepValue<T extends object, P1 extends keyof T>(
value: T,
...path: [P1]
): T[P1];
export function deepValue<
T extends object,
P1 extends keyof T,
P2 extends keyof T[P1]
>(value: T, ...path: [P1, P2]): T[P1][P2];
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@guiseek
guiseek / create.ts
Created December 22, 2023 22:45
create element
export const create = <K extends keyof HTMLElementTagNameMap>(
name: K,
attrs: Partial<HTMLElementTagNameMap[K]> = {},
...children: Element[]
): HTMLElementTagNameMap[K] => {
const el = document.createElement(name);
el.append(...children);
return Object.assign(el, attrs);
};
@guiseek
guiseek / bit.ts
Created December 15, 2023 23:17
Text State
import {determineValue} from './utilities'
import type {Primitive} from './types'
export class Bit<T extends Primitive> extends Text {
constructor(public initialValue: T) {
super(initialValue.toLocaleString())
}
set = (value: T) => {
this.textContent = value.toLocaleString()
import {ElementType, TagsByType} from '../types'
const ns = {
html: 'http://www.w3.org/1999/xhtml',
svg: 'http://www.w3.org/2000/svg',
mathMl: 'http://www.w3.org/1998/Math/MathML',
}
export function createElement<
Type extends ElementType,
@guiseek
guiseek / types.ts
Created December 10, 2023 06:43
HTML, SVG and MathML ElementTagNameMaps
export type HTMLs = HTMLElementTagNameMap
export type SVGs = SVGElementTagNameMap
export type MathMLs = MathMLElementTagNameMap
export type Tags = keyof (HTMLs | SVGs | MathMLs)
export type HTMLByTag<K extends keyof HTMLs> = HTMLs[K]
export type SVGByTag<K extends keyof SVGs> = SVGs[K]
export type MathMLByTag<K extends keyof MathMLs> = MathMLs[K]
@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