Skip to content

Commit 5b9e740

Browse files
authored
Merge pull request #6 from meech-ward/dev
Dev
2 parents 4148f3e + 5ae72c5 commit 5b9e740

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3511
-336
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ dist
131131

132132
package-lock.json
133133
.idea/
134+
135+
docs/push.sh

.prettierrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"tabWidth": 2,
33
"useTabs": false,
44
"semi": false,
5-
"printWidth": 120
5+
"printWidth": 120,
6+
"endOfLine": "crlf",
7+
"trailingComma": "none"
68
}

README.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,37 @@ This works for sync and async code, and you can choose the error handling style
66

77
Scroll to the bottom for the motivation section (why `try,catch,finally` blocks are bad).
88

9+
## Docs
10+
11+
[https://mightfail.dev](https://mightfail.dev)
12+
913
## Install
1014

1115
[![JSR](https://jsr.io/badges/@might/fail)](https://jsr.io/@might/fail)
1216
[![npm version](https://img.shields.io/npm/v/might-fail.svg)](https://www.npmjs.com/package/might-fail)
1317

1418

15-
1619
## Style
1720

1821
There's three different styles to choose from and they all work the same way, but you can choose your favorite API.
1922

2023
All examples are in the default style, but you **can** use any of the three styles.
2124

22-
### Default
25+
26+
### Tuple Style
2327

2428
```ts
2529
import { mightFail } from "might-fail"; // from "@might/fail"
2630

27-
const { error, result } = await mightFail(promise);
31+
const [error, result] = await mightFail(promise);
2832
```
2933

30-
### Tuple Style
34+
### Object Style
3135

3236
```ts
33-
import { mightFail } from "might-fail/tuple"; // from "@might/fail/tuple"
37+
import { mightFail } from "might-fail"; // from "@might/fail"
3438

35-
const [error, result] = await mightFail(promise);
39+
const { error, result } = await mightFail(promise);
3640
```
3741

3842
### Go Style
@@ -49,7 +53,7 @@ const [result, error] = await mightFail(promise);
4953
### Wrap Promise in `mightFail`
5054

5155
```ts
52-
const { error, result } = await mightFail(axios.get("/posts"));
56+
const [ error, result ] = await mightFail(axios.get("/posts"));
5357

5458
if (error) {
5559
// handle error
@@ -63,7 +67,7 @@ posts.map((post) => console.log(post.title));
6367
**or:**
6468

6569
```ts
66-
const { error: networkError, result } = await mightFail(fetch("/posts"));
70+
const [ networkError, result ] = await mightFail(fetch("/posts"));
6771

6872
if (networkError) {
6973
// handle network error
@@ -75,7 +79,7 @@ if (!result.ok) {
7579
return;
7680
}
7781

78-
const { error: convertToJSONError, result: posts } = await mightFail(
82+
const [ convertToJSONError, posts ] = await mightFail(
7983
result.json()
8084
);
8185

@@ -91,7 +95,7 @@ posts.map((post) => console.log(post.title));
9195

9296
```ts
9397
const get = makeMightFail(axios.get);
94-
const { error, result } = await get("/posts");
98+
const [ error, result ] = await get("/posts");
9599

96100
if (error) {
97101
// handle error
@@ -108,7 +112,7 @@ posts.map((post) => console.log(post.title));
108112
### Wrap throwing functions in `mightFailSync`
109113

110114
```ts
111-
const {error, result} = mightFailSync(() => JSON.parse("")); // JSON.parse might throw
115+
const [ error, result ] = mightFailSync(() => JSON.parse("")); // JSON.parse might throw
112116
if (error) {
113117
console.error('Parsing failed:', error);
114118
return
@@ -124,7 +128,7 @@ function parseJSON(jsonString: string) {
124128
}
125129
const safeParseJSON = makeMightFailSync(parseJSON);
126130

127-
const { error, result } = safeParseJSON("");
131+
const [ error, result ] = safeParseJSON("");
128132

129133
if (error) {
130134
console.error("Parsing failed:", error);

docs/README.md

+221
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
## Might Fail Docs
2+
3+
### Blocks
4+
5+
#### YouTube
6+
7+
```mdx
8+
<YouTube videoId="PbkwqVZsUgs" startTime={230} />
9+
```
10+
11+
#### Example Block
12+
13+
```mdx
14+
<SideBySide ratio="3:5">
15+
<ExampleCard>
16+
Return a single root element, div or empty tag `<>`
17+
</ExampleCard>
18+
\`\`\`some-component.jsx
19+
// focus(1:2)
20+
return (
21+
<div>
22+
<h1 className="header">Hello</h1>
23+
<h2>World</h2>
24+
<img className="image" src="https://picsum.photos/200" alt="random"></img>
25+
</div>
26+
)
27+
\`\`\`
28+
</SideBySide>
29+
```
30+
31+
#### Instruction Block
32+
33+
```mdx
34+
<Instruction>
35+
<Instruction.Action step={1}>
36+
Add this code to your thing:
37+
</Instruction.Action>
38+
<Instruction.Implementation>
39+
40+
```App.js
41+
return (
42+
<div className="App">
43+
<h1 className="heading">Hello</h1>
44+
<h2>World</h2>
45+
<h3>{new Date().toString()}</h3>
46+
</div>
47+
)
48+
```
49+
</Instruction.Implementation>
50+
</Instruction>
51+
```
52+
53+
```mdx
54+
<Instruction ratio="">
55+
type Ratio = "1" | "1:1" | "2:3" | "3:2" | "3:5" | "5:3" | "4:7" | "1:2" | "1:0" | "0:1"
56+
```
57+
58+
#### Tabs
59+
60+
```
61+
<Tabs>
62+
<Tab name="npx">
63+
```sh
64+
npx create-next-app@latest
65+
```
66+
</Tab>
67+
<Tab name="yarn">
68+
```sh
69+
yarn create next-app
70+
```
71+
</Tab>
72+
<Tab name="pnpm">
73+
```sh
74+
pnpm create next-app
75+
```
76+
</Tab>
77+
<Tab name="bunx">
78+
```sh
79+
bunx create-next-app
80+
```
81+
</Tab>
82+
</Tabs>
83+
```
84+
85+
## Card
86+
87+
```
88+
<Card>
89+
</Card>
90+
```
91+
92+
## File Tree
93+
94+
```mdx
95+
<Card>
96+
<FileTree focus={[{depth: number, item: number}]}>
97+
- src
98+
- app
99+
- page.tsx
100+
</FileTree>
101+
</Card>
102+
```
103+
104+
```mdx
105+
<Instruction ratio="1:1">
106+
<Instruction.Action step={1}>
107+
Create a new file inside of `create-post` called `page.tsx`.
108+
</Instruction.Action>
109+
<Instruction.Implementation>
110+
<Card>
111+
<FileTree focus={[{depth: 4, item: 1}]}>
112+
- src
113+
- app
114+
- page.tsx
115+
- create-post (`/create-post` route)
116+
- page.tsx (UI)
117+
</FileTree>
118+
</Card>
119+
</Instruction.Implementation>
120+
</Instruction>
121+
```
122+
123+
## Code
124+
125+
```mdx
126+
<CodeWithOutput>
127+
```users.ts
128+
import { pgTable, text, varchar, timestamp } from "drizzle-orm/pg-core"
129+
130+
export const users = pgTable("users", {
131+
id: text("id").primaryKey(),
132+
username: varchar("username", { length: 30 }).notNull(),
133+
firstName: varchar("first_name", { length: 50 }).notNull(),
134+
lastName: varchar("last_name", { length: 50 }).notNull(),
135+
avatar: text("avatar").notNull(),
136+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
137+
})
138+
```
139+
```sql
140+
CREATE TABLE IF NOT EXISTS "users" (
141+
"id" text PRIMARY KEY NOT NULL,
142+
"username" varchar(30) NOT NULL,
143+
"first_name" varchar(50) NOT NULL,
144+
"last_name" varchar(50) NOT NULL,
145+
"avatar" text NOT NULL,
146+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
147+
);
148+
```
149+
</CodeWithOutput>
150+
```
151+
152+
153+
```mdx
154+
<CodeTabs>
155+
```/home/ubuntu/index.html
156+
<!DOCTYPE html>
157+
<html lang="en">
158+
<head>
159+
<meta charset="UTF-8">
160+
<title>Hello World</title>
161+
</head>
162+
<body>
163+
<h1>Hello World</h1>
164+
<p>🌎</p>
165+
</body>
166+
</html>
167+
```
168+
```/home/ubuntu/404.html
169+
<!DOCTYPE html>
170+
<html lang="en">
171+
<head>
172+
<meta charset="UTF-8">
173+
<title>404 - Page Not Found</title>
174+
</head>
175+
<body>
176+
<h1>404 - Page not found</h1>
177+
<p>🤷‍♀️</p>
178+
</body>
179+
</html>
180+
```
181+
</CodeTabs>
182+
```
183+
184+
**Not yet fully working:**
185+
```mdx
186+
<CodeSideBySide>
187+
```users.ts
188+
// toolbar sql
189+
import { text, varchar, pgTable, timestamp } from "drizzle-orm/pg-core"
190+
191+
export const users = pgTable("users", {
192+
id: text("id").primaryKey(),
193+
username: varchar("username", { length: 30 }).notNull(),
194+
firstName: varchar("first_name", { length: 50 }).notNull(),
195+
lastName: varchar("last_name", { length: 50 }).notNull(),
196+
avatar: text("avatar").notNull(),
197+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
198+
})
199+
```
200+
```schema.sql
201+
-- toolbar sql
202+
CREATE TABLE IF NOT EXISTS "users" (
203+
"id" text PRIMARY KEY NOT NULL,
204+
"username" varchar(30) NOT NULL,
205+
"first_name" varchar(50) NOT NULL,
206+
"last_name" varchar(50) NOT NULL,
207+
"avatar" text NOT NULL,
208+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
209+
);
210+
```
211+
</CodeSideBySide>
212+
```
213+
214+
## Image
215+
216+
The image path needs to be aboslute to where it is in the markdown system.
217+
append dark or light to the end of the image path to switch between the two.
218+
219+
```md
220+
![Create Project](/part-2/10-setup-neon-images/project-creation-dark.png) ![Create Project](/part-2/10-setup-neon-images/project-creation-light.png)
221+
```

0 commit comments

Comments
 (0)