-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Boyne
authored and
David Boyne
committed
Sep 9, 2024
1 parent
631ace6
commit 12d20a7
Showing
14 changed files
with
510 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Time | ||
id: time | ||
slug: /time | ||
sidebar_label: 24. Time | ||
description: Create time/date values in Wing | ||
keywords: [Wing language, time, date] | ||
--- | ||
|
||
```js playground example title="main.w" | ||
let now = datetime.utcNow(); | ||
|
||
log(now.toIso()); | ||
|
||
let then = datetime.fromIso("2020-09-09"); | ||
log(then.toIso()); | ||
|
||
log(then.year); | ||
log(then.month); | ||
log(then.dayOfWeek); | ||
log(then.dayOfMonth); | ||
log(then.hours); | ||
log(then.min); | ||
log(then.sec); | ||
log(then.ms); | ||
|
||
log(then.timestamp); | ||
log(then.timestampMs); | ||
log(then.timezone); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
2024-09-09T12:25:01.080Z | ||
2020-09-09T00:00:00.000Z | ||
2020 | ||
8 | ||
3 | ||
9 | ||
0 | ||
0 | ||
0 | ||
0 | ||
1599609600 | ||
1599609600000 | ||
0 | ||
``` | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: Random | ||
id: random | ||
slug: /random | ||
sidebar_label: 25. Random | ||
description: Create random values in Wing | ||
keywords: [Wing language, random] | ||
--- | ||
|
||
```js playground example title="main.w" | ||
bring math; | ||
|
||
log(math.random(100)); | ||
|
||
log(math.ceil(math.random(100))); | ||
|
||
log((math.random()*5)+5); | ||
|
||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console, output will vary | ||
46.58171364582826 | ||
4 | ||
5.721934646951212 | ||
``` | ||
|
||
|
||
|
||
|
28 changes: 28 additions & 0 deletions
28
example_versioned_docs/version-latest/26-number-parsing.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: Number parsing | ||
id: number-parsing | ||
slug: /number-parsing | ||
sidebar_label: 26. Number Parsing | ||
description: Parse values into numbers | ||
keywords: [Wing language, random] | ||
--- | ||
|
||
```js playground example title="main.w" | ||
let j = Json { a: 100 }; | ||
|
||
let x:num = num.fromStr("1"); | ||
let y:num = num.fromJson(j.get("a")); | ||
|
||
log(x); | ||
log(y); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
1 | ||
100 | ||
``` | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: URL parsing | ||
id: url-parsing | ||
slug: /url-parsing | ||
sidebar_label: 27. URL parsing | ||
description: Parse urls in Wing | ||
keywords: [Wing language, URL] | ||
--- | ||
|
||
Parse urls using the http module, works with inflight closures. | ||
|
||
```js playground example title="main.w" | ||
bring http; | ||
bring cloud; | ||
|
||
new cloud.Function(inflight () => { | ||
let parts = http.parseUrl("postgres://user:[email protected]:5432/path?k=v#f"); | ||
|
||
log(parts.hostname); | ||
log(parts.host); | ||
log(parts.hash); | ||
log(parts.origin); | ||
log(parts.username); | ||
log(parts.password); | ||
log(parts.pathname); | ||
log(parts.port); | ||
log(parts.protocol); | ||
log(parts.search); | ||
|
||
}); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console and invoke the cloud function | ||
host.com | ||
host.com:5432 | ||
#f | ||
null | ||
user | ||
pass | ||
/path | ||
5432 | ||
postgres: | ||
?k=v | ||
``` | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: SHA256 Hashes | ||
id: sha256 | ||
slug: /sha256 | ||
sidebar_label: 28. SHA256 Hashes | ||
description: Hash values in Wing with SHA256 | ||
keywords: [Wing language, Hash, SHA256] | ||
--- | ||
|
||
```js playground example title="main.w" | ||
bring util; | ||
|
||
let value = util.sha256("sha256 this string"); | ||
|
||
log(value); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
1af1dfa857bf1d8814fe1af8983c18080019922e557f15a8a0d3db739d77aacb | ||
``` | ||
|
||
|
||
|
||
|
31 changes: 31 additions & 0 deletions
31
example_versioned_docs/version-latest/29-base64-encoding.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: Base64 Encoding | ||
id: base64-encoding | ||
slug: /base64-encoding | ||
sidebar_label: 29. Base64 Encoding | ||
description: Encode and decode Base64 values | ||
keywords: [Wing language, Base64] | ||
--- | ||
|
||
```js playground example title="main.w" | ||
bring util; | ||
|
||
let data = "abc123!?$*&()'-=@~"; | ||
|
||
let encoded = util.base64Encode(data); | ||
log(encoded); | ||
|
||
|
||
let decoded = util.base64Decode(encoded); | ||
log(decoded); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
YWJjMTIzIT8kKiYoKSctPUB+ | ||
abc123!?$*&()'-=@~ | ||
``` | ||
44 changes: 44 additions & 0 deletions
44
example_versioned_docs/version-latest/30-reading-writing-files.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: Reading and writing files | ||
id: reading-and-writing-files | ||
slug: /reading-and-writing-files | ||
sidebar_label: 30. Reading and writing files | ||
description: Reading and writing files with Wing | ||
keywords: [Wing language, Reading files, Writing files] | ||
--- | ||
|
||
```js playground example title="main.w" | ||
bring fs; | ||
|
||
let filename:str = "/tmp/test.txt"; | ||
|
||
log(fs.exists(filename)); | ||
|
||
fs.writeFile(filename, "hello world!"); | ||
fs.exists(filename); | ||
|
||
let file = fs.readFile(filename); | ||
|
||
log(file); | ||
log(fs.extension(filename) ?? ""); | ||
log(fs.isDir(filename)); | ||
|
||
fs.appendFile(filename, "testing"); | ||
|
||
let extendedValue = fs.readFile(filename); | ||
|
||
log(extendedValue); | ||
``` | ||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
true | ||
hello world! | ||
txt | ||
false | ||
hello world!testing | ||
``` | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Directories | ||
id: directories | ||
slug: /directories | ||
sidebar_label: 31. Directories | ||
description: Directories | ||
keywords: [Wing language, Directories] | ||
--- | ||
|
||
Use the fs module to make, read, check, remove directories with Wing. | ||
|
||
```js playground example title="main.w" | ||
bring fs; | ||
|
||
// Make directory | ||
fs.mkdir("subdir"); | ||
|
||
// Check if path is directory | ||
fs.isDir("subdir"); | ||
|
||
// Set permissions on directory | ||
fs.setPermissions("subdir", "0755"); | ||
|
||
// Try and parse | ||
if let dirTryFrom = fs.tryReaddir("random-folder") { | ||
log("Directory is there"); | ||
} else { | ||
log("No directory found"); | ||
} | ||
|
||
// Remove a directory | ||
fs.remove("subdir"); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
No directory found | ||
``` | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: Testing | ||
id: testing | ||
slug: /testing | ||
sidebar_label: 32. Testing | ||
description: Directories | ||
keywords: [Wing language, Directories] | ||
--- | ||
|
||
Wing incorporates a [lightweight testing framework](/docs/concepts/tests), which is built around the wing test command and the test keyword. | ||
|
||
```js playground example title="main.w" | ||
bring math; | ||
bring cloud; | ||
let b = new cloud.Bucket(); | ||
|
||
test "abs" { | ||
assert(1 == math.abs(-1)); | ||
} | ||
|
||
test "bucket list should include created file" { | ||
b.put("file", "lorem ipsum"); | ||
let listOfFile = b.list(); | ||
assert(listOfFile.length == 1); | ||
} | ||
|
||
test "bucket starts empty" { | ||
let listOfFile = b.list(); | ||
assert(listOfFile.length == 0); | ||
} | ||
|
||
test "this test fails" { | ||
throw("test throws an exception fails"); | ||
} | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
No directory found | ||
``` | ||
|
||
|
||
|
||
|
Oops, something went wrong.