This file contains 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 React, { ComponentType, LazyExoticComponent } from "react"; | |
type Transformer = <T>(name: keyof T) => (module: T) => { default: T[keyof T] }; | |
const transformer: Transformer = ( | |
(name) => (module) => ({ default: module[name] }) | |
); | |
This file contains 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
/* | |
analyze reserved properties from bundled dts for terser | |
$ pnpm tsm analyze.ts src/*.{ts, tsx} -i src/index.ts | |
{ | |
"reservedProperties": [ | |
"result", | |
"value", | |
"pubTypeKey", | |
"ikey", |
This file contains 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://stackoverflow.com/a/69288824 | |
export type Expand<T> = T extends (...args: infer A) => infer R | |
? (...args: Expand<A>) => Expand<R> | |
: T extends infer O | |
? { [K in keyof O]: O[K] } | |
: never; | |
export type ExpandRecursively<T> = T extends (...args: infer A) => infer R | |
? (...args: ExpandRecursively<A>) => ExpandRecursively<R> |
This file contains 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
interface Messenger { | |
sendText: () => void; | |
sendFile: () => void; | |
checkStatus?: () => void; | |
} | |
type RequiredFields<T> = { | |
[K in keyof T as T[K] extends Required<T>[K] ? K : never]: T[K]; | |
}; |
This file contains 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
// sample shopping cart data | |
const shopping_cart = { | |
items: [ | |
{ id: '1', name: 'T-Shirt Game of Thrones', size: 'XL', taxCode: 'IVA23', quantity: 1, unitPrice: 24.99 }, | |
{ id: '2', name: 'T-Shirt Big Bang Theory', size: 'L', taxCode: 'IVA23', quantity: 2, unitPrice: 12.50 }, | |
], | |
subTotal: 0, | |
tax: 0, | |
total: 0, | |
}; |
This file contains 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 { PerformanceObserver, performance } = require('perf_hooks'); | |
let arraySize = 1000000; | |
let iterations = 100; | |
console.log("Starting performance test with %d array size and %d iterations", arraySize, iterations); | |
let values = { | |
FORIN: 0, | |
FOROF: 0, |
This file contains 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
var http = require("http"); | |
var { readFileSync } = require("fs"); | |
var path = require("path"); | |
//create a server object: | |
http | |
.createServer(function (req, res) { | |
if (req.method === "GET" && req.url == "/") { | |
const file = readFileSync(path.join(__dirname, "/index.html")); | |
res.writeHead(200, { "Content-Type": "text/html" }); |
This file contains 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 express from 'express' | |
import compression from 'compression' | |
import { renderPage } from 'vite-plugin-ssr' | |
import { Options } from 'sirv' | |
import fs from 'fs' | |
import path from 'path' | |
import https from 'https' | |
const isProduction = process.env.NODE_ENV === 'production' | |
const root = `${__dirname}/..` |
This file contains 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 * as React from "react"; | |
const displayItem = (currentPage: number, maxPerPage: number, index:number): boolean => { | |
const currentPageStart = ((currentPage - 1) * maxPerPage) + 1; | |
const currentPageEnd = currentPage * maxPerPage; | |
if ((index + 1) >= currentPageStart && (index + 1) <= currentPageEnd ) { | |
return true; | |
} |
This file contains 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
// The basis of calculations, and your root html font size. | |
$base-font-size: 16px | |
// Change this to your type scale modifier. | |
// https://type-scale.com/ | |
$type-scale: 1.25 | |
// The desired unit supports "rem", "em", and "%". | |
$desired-unit: 'rem' | |
// Generate a type scale value based on the number of steps if this is ascending or descending. | |
// It is recommended to compile with the "--precision 3" flag to avoid long decimals. |
NewerOlder