This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from 'react'; | |
| export default function useDeviceDetect() { | |
| const [isMobile, setMobile] = useState(false); | |
| useEffect(() => { | |
| const userAgent = typeof window.navigator === 'undefined' ? '' : navigator.userAgent; | |
| const mobile = Boolean(userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile|WPDesktop/i)); | |
| setMobile(mobile); | |
| }, []); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Type guard to filter out null-ish values | |
| * | |
| * @category Guards | |
| * @example array.filter(notNullish) | |
| */ | |
| export function notNullish<T>(v: T | null | undefined): v is NonNullable<T> { | |
| return v != null | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Replace backslash to slash | |
| * | |
| * @category String | |
| */ | |
| export function slash(str: string) { | |
| return str.replace(/\\/g, '/') | |
| } | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type Merge<T, P> = P & Omit<T, keyof P> | |
| export type UnionStringArray<T extends Readonly<string[]>> = T[number] | |
| export type Omit<T, K> = Pick<T, Exclude<keyof T, K>> | |
| export type LiteralUnion<T extends U, U extends any = string> = | |
| | T | |
| | (U & { _?: never }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function getFirstItem<T>(array: T[]): T | undefined { | |
| return array != null && array.length ? array[0] : undefined | |
| } | |
| export function getLastItem<T>(array: T[]): T | undefined { | |
| const length = array == null ? 0 : array.length | |
| return length ? array[length - 1] : undefined | |
| } | |
| export function getPrevItem<T>(index: number, array: T[], loop = true): T { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Is a given element currently in the viewport? | |
| This hook tracks that information using | |
| IntersectionObserver. | |
| */ | |
| import { useState, useEffect } from 'react'; | |
| function useIsOnscreen( | |
| elementRef, | |
| defaultState = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Tab } from "@headlessui/react"; | |
| const feature = { | |
| items: [ | |
| { | |
| id: 1, | |
| title: "Title 1", | |
| description: `Feature <strong>Item 1</strong> description.`, | |
| image: { | |
| src: "https://images.unsplash.com/photo-1447078806655-40579c2520d6?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxfDB8MXxyYW5kb218MHx8fHx8fHx8MTYyNTUyODc0MA&ixlib=rb-1.2.1&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=1080", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect } from "react"; | |
| export default function useDebounce(value, delay) { | |
| const [debouncedValue, setDebouncedValue] = useState(value); | |
| useEffect(() => { | |
| const handler = setTimeout(() => { | |
| setDebouncedValue(value); | |
| }, delay); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // const options = { | |
| // root: document.querySelector('.ct-inner-content'), | |
| // rootMargin: '0px', | |
| // threshold: 1.0 | |
| // } | |
| const div = document.querySelector("#div_id"); | |
| const options = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://luigicruz.dev/feed.xml | |
| import { readFileSync, readdirSync, writeFileSync } from 'fs' | |
| import { join } from 'path' | |
| import RSS from 'rss' | |
| import matter from 'gray-matter' | |
| async function generate() { | |
| const feed = new RSS({ | |
| title: 'Luigi Cruz', |
NewerOlder