aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/util
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-08-23 18:15:21 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-23 18:15:21 -0700
commitaa08c35c062d0db004b9aaedcd8d427eda8aa7c7 (patch)
tree5a72d23bfec03de04709aea2835af5c552c2fdff /docs/guides/util
parent20d42dfaa3c23c1302dd3d5837ba6714dc891ac4 (diff)
downloadbun-aa08c35c062d0db004b9aaedcd8d427eda8aa7c7.tar.gz
bun-aa08c35c062d0db004b9aaedcd8d427eda8aa7c7.tar.zst
bun-aa08c35c062d0db004b9aaedcd8d427eda8aa7c7.zip
Add Debugger docs and a couple guides (#4281)
* Add debugger docs. Add guides. * Add files
Diffstat (limited to 'docs/guides/util')
-rw-r--r--docs/guides/util/detect-bun.md23
-rw-r--r--docs/guides/util/hash-a-password.md2
2 files changed, 24 insertions, 1 deletions
diff --git a/docs/guides/util/detect-bun.md b/docs/guides/util/detect-bun.md
new file mode 100644
index 000000000..0a2506b5c
--- /dev/null
+++ b/docs/guides/util/detect-bun.md
@@ -0,0 +1,23 @@
+---
+name: Detect when code is executed with Bun
+---
+
+The recommended way to conditionally detect when code is being executed with `bun` is to check for the existence of the `Bun` global.
+
+This is similar to how you'd check for the existence of the `window` variable to detect when code is being executed in a browser.
+
+```ts
+if (typeof Bun !== "undefined") {
+ // this code will only run when the file is run with Bun
+}
+```
+
+---
+
+In TypeScript environments, the previous approach will result in a type error unless `bun-types` is globally installed. To avoid this, you can check `process.versions` instead.
+
+```ts
+if (process.versions.bun) {
+ // this code will only run when the file is run with Bun
+}
+```
diff --git a/docs/guides/util/hash-a-password.md b/docs/guides/util/hash-a-password.md
index 6941bfcfe..61a59aeaf 100644
--- a/docs/guides/util/hash-a-password.md
+++ b/docs/guides/util/hash-a-password.md
@@ -8,7 +8,7 @@ The `Bun.password.hash()` function provides a fast, built-in mechanism for secur
const password = "super-secure-pa$$word";
const hash = await Bun.password.hash(password);
-// => $argon2id$v=19$m=65536,t=2,p=1$tFq+9AVr1bfPxQdh6E8DQRhEXg/M/SqYCNu6gVdRRNs$GzJ8PuBi+K+BVojzPfS5mjnC8OpLGtv8KJqF99eP6a4
+// => $argon2id$v=19$m=65536,t=2,p=1$tFq+9AVr1bfPxQdh6E8DQRhEXg/M/...
```
---