@rubriclab/bunl 0.1.25 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils.ts CHANGED
@@ -1,6 +1,149 @@
1
- import { humanId } from "human-id";
2
- /**
3
- * Generate a human-readable unique identifier
4
- * Eg. all-zebras-eat
5
- */
6
- export const uid = () => humanId({ capitalize: false, separator: "-" });
1
+ const adjectives = [
2
+ 'agile',
3
+ 'bold',
4
+ 'calm',
5
+ 'deft',
6
+ 'easy',
7
+ 'fair',
8
+ 'glad',
9
+ 'hale',
10
+ 'idle',
11
+ 'just',
12
+ 'keen',
13
+ 'lush',
14
+ 'mild',
15
+ 'neat',
16
+ 'open',
17
+ 'pale',
18
+ 'rare',
19
+ 'safe',
20
+ 'tall',
21
+ 'vast',
22
+ 'warm',
23
+ 'zany',
24
+ 'able',
25
+ 'blue',
26
+ 'cool',
27
+ 'dark',
28
+ 'even',
29
+ 'fast',
30
+ 'good',
31
+ 'high',
32
+ 'kind',
33
+ 'lean',
34
+ 'long',
35
+ 'next',
36
+ 'pink',
37
+ 'real',
38
+ 'slim',
39
+ 'true',
40
+ 'wide',
41
+ 'zero'
42
+ ]
43
+
44
+ const nouns = [
45
+ 'ant',
46
+ 'bee',
47
+ 'cat',
48
+ 'dog',
49
+ 'elk',
50
+ 'fox',
51
+ 'gnu',
52
+ 'hen',
53
+ 'ibis',
54
+ 'jay',
55
+ 'koi',
56
+ 'lynx',
57
+ 'moth',
58
+ 'newt',
59
+ 'owl',
60
+ 'puma',
61
+ 'quail',
62
+ 'ram',
63
+ 'seal',
64
+ 'toad',
65
+ 'urchin',
66
+ 'vole',
67
+ 'wolf',
68
+ 'yak',
69
+ 'ape',
70
+ 'bass',
71
+ 'crow',
72
+ 'dove',
73
+ 'eel',
74
+ 'frog',
75
+ 'goat',
76
+ 'hawk',
77
+ 'ibex',
78
+ 'lark',
79
+ 'mole',
80
+ 'oryx',
81
+ 'pike',
82
+ 'rook',
83
+ 'swan',
84
+ 'wren'
85
+ ]
86
+
87
+ function pick<T>(arr: T[]): T {
88
+ const index = Math.floor(Math.random() * arr.length)
89
+ if (!arr[index]) {
90
+ throw new Error('Array is empty')
91
+ }
92
+ return arr[index]
93
+ }
94
+
95
+ export function uid(): string {
96
+ return `${pick(adjectives)}-${pick(adjectives)}-${pick(nouns)}`
97
+ }
98
+
99
+ export function openBrowser(url: string): void {
100
+ const cmds: Record<string, string[]> = {
101
+ darwin: ['open', url],
102
+ win32: ['cmd', '/c', 'start', url]
103
+ }
104
+ const args = cmds[process.platform] ?? ['xdg-open', url]
105
+ Bun.spawn(args, { stdio: ['ignore', 'ignore', 'ignore'] })
106
+ }
107
+
108
+ export function toBase64(buf: ArrayBuffer): string {
109
+ return Buffer.from(buf).toString('base64')
110
+ }
111
+
112
+ export function fromBase64(str: string): Uint8Array<ArrayBuffer> {
113
+ const buf = Buffer.from(str, 'base64')
114
+ return new Uint8Array(buf.buffer as ArrayBuffer, buf.byteOffset, buf.byteLength)
115
+ }
116
+
117
+ export function page(title: string, body: string): string {
118
+ return `<!DOCTYPE html>
119
+ <html lang="en">
120
+ <head>
121
+ <meta charset="utf-8">
122
+ <meta name="viewport" content="width=device-width, initial-scale=1">
123
+ <title>${title} — bunl</title>
124
+ <style>
125
+ * { margin: 0; padding: 0; box-sizing: border-box; }
126
+ body {
127
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
128
+ background: #fff;
129
+ color: #000;
130
+ min-height: 100vh;
131
+ display: flex;
132
+ align-items: center;
133
+ justify-content: center;
134
+ padding: 2rem;
135
+ }
136
+ main { max-width: 480px; width: 100%; }
137
+ h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 1rem; }
138
+ p { color: #666; line-height: 1.6; margin-bottom: 0.75rem; }
139
+ code { background: #f5f5f5; padding: 0.15em 0.4em; border-radius: 3px; font-size: 0.9em; }
140
+ a { color: #000; }
141
+ </style>
142
+ </head>
143
+ <body>
144
+ <main>
145
+ ${body}
146
+ </main>
147
+ </body>
148
+ </html>`
149
+ }
package/bun.lockb DELETED
Binary file
package/demo.ts DELETED
@@ -1,18 +0,0 @@
1
- import { serve } from "bun";
2
-
3
- const port = 3000;
4
-
5
- serve({
6
- port,
7
- fetch: async (req) => {
8
- const url = new URL(req.url);
9
- console.log(req.method, url.pathname, url.search);
10
-
11
- const bod = await req.text();
12
- bod && console.log("Body: ", bod);
13
-
14
- return new Response(`hello from localhost:${port}`);
15
- },
16
- });
17
-
18
- console.log(`Serving app at http://localhost:${port}`);
package/fly.toml DELETED
@@ -1,19 +0,0 @@
1
- # See https://fly.io/docs/reference/configuration/ for information about how to use this file.
2
-
3
- app = 'tunnel'
4
- primary_region = 'yul'
5
-
6
- [build]
7
-
8
- [http_service]
9
- internal_port = 1234
10
- force_https = false
11
- auto_stop_machines = "suspend"
12
- auto_start_machines = true
13
- min_machines_running = 0
14
- processes = ['app']
15
-
16
- [[vm]]
17
- memory = '1gb'
18
- cpu_kind = 'shared'
19
- cpus = 1
package/index.ts DELETED
@@ -1,67 +0,0 @@
1
- import "localenv";
2
- import optimist from "optimist";
3
- import Debug from "debug";
4
- import { CreateServer } from "./server";
5
- import { type AddressInfo } from "ws";
6
-
7
- const debug = Debug("localtunnel");
8
-
9
- const argv = optimist
10
- .usage("Usage: $0 --port [num]")
11
- .options("secure", {
12
- default: false,
13
- describe: "use this flag to indicate proxy over https",
14
- })
15
- .options("port", {
16
- default: "80",
17
- describe: "listen on this port for outside requests",
18
- })
19
- .options("address", {
20
- default: "0.0.0.0",
21
- describe: "IP address to bind to",
22
- })
23
- .options("domain", {
24
- describe:
25
- "Specify the base domain name. This is optional if hosting localtunnel from a regular example.com domain. This is required if hosting a localtunnel server from a subdomain (i.e. lt.example.dom where clients will be client-app.lt.example.come)",
26
- })
27
- .options("max-sockets", {
28
- default: 10,
29
- describe:
30
- "maximum number of tcp sockets each client is allowed to establish at one time (the tunnels)",
31
- }).argv;
32
-
33
- if (argv.help) {
34
- console.log("Showing help");
35
- optimist.showHelp();
36
- process.exit();
37
- }
38
-
39
- const server = CreateServer({
40
- max_tcp_sockets: argv["max-sockets"],
41
- secure: argv.secure,
42
- domain: argv.domain,
43
- });
44
-
45
- server.listen(argv.port, argv.address, () => {
46
- debug("server listening on port: %d", (server.address() as AddressInfo).port);
47
- });
48
-
49
- process.on("SIGINT", () => {
50
- console.error("SIGINT");
51
- process.exit();
52
- });
53
-
54
- process.on("SIGTERM", () => {
55
- console.warn("SIGTERM");
56
- // process.exit();
57
- });
58
-
59
- process.on("uncaughtException", (err) => {
60
- console.error("err:");
61
- console.error(err);
62
- });
63
-
64
- process.on("unhandledRejection", (reason, promise) => {
65
- console.error("reason:");
66
- console.error(reason);
67
- });