Skip to content

Instantly share code, notes, and snippets.

import { useState, useLayoutEffect } from 'react'
type FullScreenState = boolean
type ToggleFullScreen = () => void
function useFullScreen<E extends HTMLElement>(ref: React.RefObject<E>): [FullScreenState, ToggleFullScreen] {
const [isFullScreen, setFullScreen] = useState(
Boolean(document.fullscreenElement),
)
@jrson83
jrson83 / code.tsx
Created July 4, 2023 22:05 — forked from pettaysergey/code.tsx
Code-1
import * as React from 'react';
export const getNodeArray = <Props = any>(
components: React.ReactNode,
filter?: string | React.ComponentClass<any> | React.SFC<any>,
) => {
let result = React.Children.toArray(components).map(React.Children.only) as React.ReactElement<Props>[];
if (filter) {
result = result.filter((c) => {
@jrson83
jrson83 / bem-and-sass.md
Created July 2, 2023 01:07 — forked from radist2s/bem-and-sass.md
BEM & SASS best practices

BEM & SASS best practices

Every block should be in separated file named as block.

Filename: rating-star.scss

.rating-star {
    $font-size: 0.5em;
    
    display: inline-block; // `display` style may be set freely
@jrson83
jrson83 / changelog.js
Created June 1, 2023 11:10 — forked from NicolasRitouet/changelog.js
Changelog.js
#!/usr/bin/env node
// TODO(vojta): pre-commit hook for validating messages
// TODO(vojta): report errors, currently Q silence everything which really sucks
'use strict';
var child = require('child_process');
var fs = require('fs');
var util = require('util');
@jrson83
jrson83 / router.ts
Created May 20, 2023 18:00 — forked from idan/router.ts
basic router in typescript
export type Route = {
method: "*" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE"
path: string
regexp: RegExp
handler: (request: Request, route: MatchedRoute) => Promise<Response>
}
export type MatchedRoute = Route & {
url: URL
}
@jrson83
jrson83 / install-zsh-windows-git-bash.md
Created April 12, 2023 11:01 — forked from fworks/install-zsh-windows-git-bash.md
Zsh / Oh-my-zsh on Windows Git Bash
@jrson83
jrson83 / Action.ts
Created March 2, 2023 23:21 — forked from TClark1011/Action.ts
TS - Helpful Utilities
// branded types to allow for better type inference
// with default generic types
/* eslint-disable @typescript-eslint/naming-convention */
type NO_PAYLOAD = {
JgJES6BF8uyaOwF1: "FY7eBhPYJlqOxuVp";
};
type OPTIONAL_PAYLOAD = {
A7nWdXs0r5RLuHRf: "zPcrRNRIl4r5IHbA";
};
@jrson83
jrson83 / deep-merge.ts
Created March 2, 2023 23:16 — forked from havenchyk/deep-merge.ts
deep merge
function isPlainObject(item: unknown): item is Record<string, unknown> {
return item && (item as object).constructor === Object
}
function filterProto([key, value]: [string, unknown]) {
// Avoid prototype pollution
return key !== '__proto__'
}
const deepmerge = (
@jrson83
jrson83 / glob.ts
Created March 1, 2023 02:02 — forked from jonathantneal/glob.ts
Return a list of files, like import.meta.glob in Vite, without calling the files.
import glob from 'fast-glob'
import nodeURL from 'url'
import process from 'process'
/** Returns pathnames matching the given pattern. */
const sync = (source: string) => glob.sync(source, options()) as string[]
/** Returns pathnames matching the given pattern. */
const async = (source: string) => glob(source, options()) as Promise<string[]>
// Adapted from https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_transpiler_loader
import { readFileSync, writeFileSync } from 'fs'
import { dirname } from 'path'
import { URL, pathToFileURL, fileURLToPath } from 'url'
import esbuild from 'esbuild'
const baseURL = pathToFileURL(`${process.cwd()}/`).href
const tsExtensionRegex = /\.(tsx?)$/
function readJSON(path) {