@atproto/common 0.3.3 → 0.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/common",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "license": "MIT",
5
5
  "description": "Shared web-platform-friendly code for atproto libraries",
6
6
  "keywords": [
@@ -20,7 +20,7 @@
20
20
  "multiformats": "^9.9.0",
21
21
  "pino": "^8.15.0",
22
22
  "zod": "3.21.4",
23
- "@atproto/common-web": "^0.2.3"
23
+ "@atproto/common-web": "^0.2.4"
24
24
  },
25
25
  "scripts": {
26
26
  "test": "jest",
package/src/env.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { parseIntWithFallback } from '@atproto/common-web'
2
+
3
+ export const envInt = (name: string): number | undefined => {
4
+ const str = process.env[name]
5
+ return parseIntWithFallback(str, undefined)
6
+ }
7
+
8
+ export const envStr = (name: string): string | undefined => {
9
+ const str = process.env[name]
10
+ if (str === undefined || str.length === 0) return undefined
11
+ return str
12
+ }
13
+
14
+ export const envBool = (name: string): boolean | undefined => {
15
+ const str = process.env[name]
16
+ if (str === 'true' || str === '1') return true
17
+ if (str === 'false' || str === '0') return false
18
+ return undefined
19
+ }
20
+
21
+ export const envList = (name: string): string[] => {
22
+ const str = process.env[name]
23
+ if (str === undefined || str.length === 0) return []
24
+ return str.split(',')
25
+ }
package/src/fs.ts CHANGED
@@ -13,3 +13,30 @@ export const fileExists = async (location: string): Promise<boolean> => {
13
13
  throw err
14
14
  }
15
15
  }
16
+
17
+ export const readIfExists = async (
18
+ filepath: string,
19
+ ): Promise<Uint8Array | undefined> => {
20
+ try {
21
+ return await fs.readFile(filepath)
22
+ } catch (err) {
23
+ if (isErrnoException(err) && err.code === 'ENOENT') {
24
+ return
25
+ }
26
+ throw err
27
+ }
28
+ }
29
+
30
+ export const rmIfExists = async (
31
+ filepath: string,
32
+ recursive = false,
33
+ ): Promise<void> => {
34
+ try {
35
+ await fs.rm(filepath, { recursive })
36
+ } catch (err) {
37
+ if (isErrnoException(err) && err.code === 'ENOENT') {
38
+ return
39
+ }
40
+ throw err
41
+ }
42
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '@atproto/common-web'
2
2
  export * from './dates'
3
+ export * from './env'
3
4
  export * from './fs'
4
5
  export * from './ipld'
5
6
  export * from './ipld-multi'