Skip to content

Commit

Permalink
more cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
STRd6 committed Sep 3, 2023
1 parent 03e191e commit a2a1d20
Showing 1 changed file with 117 additions and 1 deletion.
118 changes: 117 additions & 1 deletion civet.dev/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ x <? "string" // typeof x === "string"
`````

```ts
// conditionals
// if conditions
if x < 3
"it's small"
Expand Down Expand Up @@ -167,6 +167,39 @@ if [, dir, base] := /^(.*\/)?([^/]*)$/.exec file
console.log dir, base
```

```ts
// Switch
switch dir
when '>' then civet.x++
when '<'
civet.x--
civet.x = 0 if civet.x < 0
else
civet.waiting += 5
```

```ts
// Pattern Matching
switch s
""
console.log "nothing"
/\s+/
console.log "whitespace"
"hi"
console.log "greeting"
```

```ts
// Pattern destructuring
switch x
[{type: "text", content: /\s+/}, ...rest]
console.log "leading whitespace"
[{type: "text", content}, ...rest]
console.log "leading text:", content
[{type}, ...rest]
console.log "leading type:", type
```

```ts
// JSX
// Better binding
Expand All @@ -182,4 +215,87 @@ if [, dir, base] := /^(.*\/)?([^/]*)$/.exec file
<.item>
```

```ts
// Object globs
point = data{x,y}
point = data.{x,y};
point.{x,y} = data
point3D = { point.{x,y}, z: 0 }
complex := obj.{x:a, b.c()?.y}
merged := data.{...global, ...user};
data.{a, b, ...rest} = result
```

```ts
// Property Access
json.x.y
json.'long property'
json.`${movie} name`
matrix.0.0
array.-1
```

```ts
// Await operators
await.allSettled promises
await.all promises
await.race promises
```

```ts
// Range literals
letters := ['a'..'f']
numbers := [1..10]
reversed := [10..1]
indices := [0...array.length]
```

```ts
// slicing and splicing
start := numbers[..2]
mid := numbers[3...-2]
end := numbers[-2..]
numbers[1...-1] = []
```

```ts
// Pipe operator
data
|> Object.keys
|> console.log
x.length
|> & + 1
|> .toString()
fetch url
|> await
|> .json()
|> await
|> return
// Pipe assignment
data |>= .content
```

```ts
// Thick Pipes
array
||> .pop()
||> .push 5
||> .sort()
||> .reverse()
count |> & + 1
||> console.log
|> & * 2
||> console.log
url |> fetch |> await
||> (response) => console.log response.status
|> .json() |> await
||> (json) => console.log "json:", json
|> callback
```

</div>

0 comments on commit a2a1d20

Please sign in to comment.