View extracted-email-message.interface.ts
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
export interface EmailAttachment { | |
filename: string; | |
mimeType: string; | |
disposition: string; | |
related: boolean; | |
contentId: string; | |
content: unknown; | |
} | |
export interface EmailAddress { |
View index.ts
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 PostalMime = require('postal-mime'); | |
export interface EmailMessage { | |
readonly from: string; | |
readonly to: string; | |
readonly headers: Headers; | |
readonly raw: ReadableStream; | |
readonly rawSize: number; | |
setReject(reason: String): void; | |
forward(rcptTo: string, headers?: Headers): Promise<void>; |
View time-ago.ts
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 DAY_SECONDS = 86400; | |
const WEEK_SECONDS = 604800; | |
const YEAR_SECONDS = WEEK_SECONDS * 52; | |
export function timeAgo(date: Date) { | |
const epoch = Math.round(date.getTime() / 1000); | |
const now = Math.round(Date.now() / 1000); | |
const seconds = now - epoch; | |
const minutes = Math.round(seconds / 60); | |
const hours = Math.round(seconds / 3600); |
View isOneOfMyValues.ts
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 values = ['foo', 'bar'] as const; | |
type MyValues = typeof values[number]; | |
function isOneOfMyValues(elem: unknown): elem is MyValues { | |
const opts: string[] = [...values]; | |
return opts.includes(String(elem)); | |
} | |
function lengthOfMyThing(x: MyValues | null) { | |
if (isOneOfMyValues(x)) { |
View color-names.js
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
export const COLOR_NAMES = [ | |
'aliceblue', | |
'antiquewhite', | |
'aqua', | |
'aquamarine', | |
'azure', | |
'beige', | |
'bisque', | |
'black', | |
'blanchedalmond', |
View generate-svg.ts
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
// Credit:: https://github.com/cloudfour/simple-svg-placeholder | |
type SvgOptions = { | |
width: number | |
height: number | |
text: string | |
fontFamily: string | |
fontWeight: string | |
bgColor: string | |
textColor: string |
View fetch-thumbnail.ts
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 { IncomingRequest } from '../incoming-request' | |
const buckets: { [key: string]: string } = { | |
'bucket-name': 'https://bucket-url/', | |
} | |
interface RequestInitWithCf extends RequestInit { | |
cf: RequestInitCfProperties & { | |
image: BasicImageTransformations & { | |
quality?: number | undefined |
View hello-world.ts
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
export function helloWorld(): Response { | |
return new Response('Hello World', { | |
status: 200, | |
}) | |
} |
View merge-objects.ts
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
export const shallowMerge = <T extends object = Record<string, any>>( | |
...objects: T[] | |
): T => { | |
return objects.reduce((prev, cur) => ({ ...prev, ...cur }), {} as T); | |
}; | |
export const deepMerge = <T extends object = Record<string, any>>( | |
target: T, | |
...sources: object[] | |
): T => { |
View human-readable-list.ts
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
export const humanReadableList = ( | |
array: unknown[], | |
join: ',' | ';' = ',', | |
finalJoin = 'and', | |
): string => { | |
if (!Array.isArray(array) || array.length == 0) return ''; | |
if (array.length == 1) return String(array[0]); | |
const arr = array.slice(0), | |
last = arr.pop(); | |
return array.length > 2 |
NewerOlder