See also 📢 Dead simple tweetable JavaScript Emitter pattern module using Map (ES2015) which uses this package.
Browser compatibility (all)
Chrome* | Edge | FF | IE | Opera | Safari | iOS |
---|---|---|---|---|---|---|
38 | 12 | 13 | -* | 25 | 7.1 | 8 |
Notes:
const uuid7Re = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | |
const parseUuid7Date = (uuid) => { | |
if (typeof uuid !== `string` || !uuid7Re.test(uuid)) { | |
throw new TypeError(`Expected UUIDv7. Received: ${String(uuid)} (${typeof uuid})`) | |
} | |
const timestampHex = uuid.slice(0, 13).replace(`-`, ``) | |
const timestamp = Number.parseInt(timestampHex, 16) | |
return new Date(timestamp) |
const uuid4to7 = (uuid, now = Date.now()) => { | |
const ts = now.toString(16).padStart(12, `0`) | |
return `${ts.slice(0, 8)}-${ts.slice(8)}-7${uuid.slice(15)}` | |
} | |
// generate new UUIDv7 | |
uuid4to7(crypto.randomUUID()) | |
// Conforms to example in the spec RFC4122bis C.6 |
/* | |
============================= | |
Railway Oriented Typescript | |
============================= | |
by @robinpokorny | |
*/ | |
/* === 1. Union basics === */ | |
const a: string | number = 42; |
See also 📢 Dead simple tweetable JavaScript Emitter pattern module using Map (ES2015) which uses this package.
Chrome* | Edge | FF | IE | Opera | Safari | iOS |
---|---|---|---|---|---|---|
38 | 12 | 13 | -* | 25 | 7.1 | 8 |
Notes:
#!/bin/bash | |
# Mirrors all GitHub repositories the current user has read access to. | |
# See license at the end of the file. | |
# Token from https://github.com/settings/tokens | |
OAUTH_TOKEN="<TODO TOKEN>" | |
# where should the files be saved | |
DIR="<TODO PATH>" |
/* | |
============================= | |
Railway Oriented Typescript | |
============================= | |
by @robinpokorny | |
*/ | |
/* === 1. Union basics === */ | |
const a: string | number = 42; |
function fire() { | |
local BRANCH=emergency-`date +%s`-`git config user.email` | |
git checkout -b $BRANCH | |
git add -A | |
git commit -m 'EMERGENCY!' | |
git push -f origin $BRANCH | |
} | |
# Inspired by https://www.reddit.com/r/ProgrammerHumor/comments/3nc531/in_case_of_fire/cvn1k27/ |
// And you will know my name is TypeScript | |
// When I lay my Tagged Union upon thee | |
// by @robinpokorny | |
// 1. Union of literals | |
// The cornerstone of any nutritious breakfast. | |
type Burger1 = `McDonalds` | `BigKahuna`; | |
const brettsBreakfast1_1: Burger1 = `BigKahuna`; | |
const brettsBreakfast1_2: Burger1 = `Whooper`; // Caught |
export const enum InformationalResponse { | |
Continue = 100, | |
SwitchingProtocols = 101, | |
Processing = 102, | |
EarlyHints = 103, | |
} | |
export const enum Success { | |
OK = 200, | |
Created = 201, |
const sum = (a, b) => a + b | |
const getMostProfitFromStockQuotes = (quotes, current = 0) => { | |
if (quotes.length < 2) return current | |
const max = Math.max(...quotes) | |
const maxAt = quotes.indexOf(max) | |
const left = quotes.slice(0, maxAt) |