or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

environment-detection.mdenvironment-variables.mdindex.mdplatform-detection.mdprovider-detection.mdruntime-detection.md

environment-detection.mddocs/

0

# Environment Detection

1

2

Boolean flags for detecting various environment states including CI, debug, test, production, development modes, and terminal capabilities.

3

4

## Capabilities

5

6

### CI Environment Detection

7

8

Detects continuous integration environments through environment variables and provider detection.

9

10

```typescript { .api }

11

/**

12

* Detects if running in a CI environment

13

* Based on CI environment variable or detected CI provider

14

*/

15

const isCI: boolean;

16

```

17

18

**Usage Examples:**

19

20

```typescript

21

import { isCI } from "std-env";

22

23

if (isCI) {

24

console.log("Running in CI environment");

25

// Disable interactive prompts

26

// Enable CI-specific logging

27

}

28

```

29

30

### Debug Mode Detection

31

32

Detects debug mode based on the DEBUG environment variable.

33

34

```typescript { .api }

35

/**

36

* Detects if DEBUG environment variable is set to a truthy value

37

*/

38

const isDebug: boolean;

39

```

40

41

**Usage Examples:**

42

43

```typescript

44

import { isDebug } from "std-env";

45

46

if (isDebug) {

47

console.log("Debug mode enabled");

48

// Enable verbose logging

49

// Show debug information

50

}

51

```

52

53

### Test Environment Detection

54

55

Detects test environments based on NODE_ENV or TEST environment variables.

56

57

```typescript { .api }

58

/**

59

* Detects if running in test environment

60

* True when NODE_ENV is 'test' or TEST environment variable is truthy

61

*/

62

const isTest: boolean;

63

```

64

65

**Usage Examples:**

66

67

```typescript

68

import { isTest } from "std-env";

69

70

if (isTest) {

71

console.log("Running in test environment");

72

// Use test database

73

// Mock external services

74

}

75

```

76

77

### Production Environment Detection

78

79

Detects production environments based on NODE_ENV.

80

81

```typescript { .api }

82

/**

83

* Detects if NODE_ENV is set to 'production'

84

*/

85

const isProduction: boolean;

86

```

87

88

**Usage Examples:**

89

90

```typescript

91

import { isProduction } from "std-env";

92

93

if (isProduction) {

94

console.log("Running in production");

95

// Enable optimizations

96

// Disable debug features

97

}

98

```

99

100

### Development Environment Detection

101

102

Detects development environments based on NODE_ENV.

103

104

```typescript { .api }

105

/**

106

* Detects if NODE_ENV is 'dev' or 'development'

107

*/

108

const isDevelopment: boolean;

109

```

110

111

**Usage Examples:**

112

113

```typescript

114

import { isDevelopment } from "std-env";

115

116

if (isDevelopment) {

117

console.log("Running in development");

118

// Enable hot reloading

119

// Show development tools

120

}

121

```

122

123

### Minimal Environment Detection

124

125

Detects minimal environments where rich UI features should be disabled.

126

127

```typescript { .api }

128

/**

129

* Detects minimal environment conditions

130

* True when MINIMAL env var is set, running in CI, test, or TTY unavailable

131

*/

132

const isMinimal: boolean;

133

```

134

135

**Usage Examples:**

136

137

```typescript

138

import { isMinimal } from "std-env";

139

140

if (isMinimal) {

141

// Disable animations

142

// Use simplified output

143

// Skip interactive features

144

}

145

```

146

147

### TTY Detection

148

149

Detects if stdout TTY is available for interactive features.

150

151

```typescript { .api }

152

/**

153

* Detects if stdout TTY is available

154

* Checks process.stdout.isTTY when available

155

*/

156

const hasTTY: boolean;

157

```

158

159

**Usage Examples:**

160

161

```typescript

162

import { hasTTY } from "std-env";

163

164

if (hasTTY) {

165

// Enable interactive prompts

166

// Use colored output

167

// Show progress bars

168

}

169

```

170

171

### Window Object Detection

172

173

Detects if running in a browser environment with window object.

174

175

```typescript { .api }

176

/**

177

* Detects if global window object is available

178

* Indicates browser environment

179

*/

180

const hasWindow: boolean;

181

```

182

183

**Usage Examples:**

184

185

```typescript

186

import { hasWindow } from "std-env";

187

188

if (hasWindow) {

189

console.log("Running in browser");

190

// Use browser APIs

191

// Access DOM

192

} else {

193

console.log("Running in server environment");

194

}

195

```

196

197

### Color Support Detection

198

199

Detects terminal color support for enhanced output formatting.

200

201

```typescript { .api }

202

/**

203

* Detects if terminal supports colors

204

* Based on NO_COLOR, FORCE_COLOR, TTY status, and CI environment

205

*/

206

const isColorSupported: boolean;

207

```

208

209

**Usage Examples:**

210

211

```typescript

212

import { isColorSupported } from "std-env";

213

214

if (isColorSupported) {

215

console.log("\x1b[32mGreen text\x1b[0m");

216

} else {

217

console.log("Plain text");

218

}

219

```

220

221

## Detection Logic

222

223

The environment detection uses the following logic:

224

225

- **isCI**: `env.CI` is truthy OR detected CI provider

226

- **isDebug**: `env.DEBUG` is truthy

227

- **isTest**: `nodeENV === "test"` OR `env.TEST` is truthy

228

- **isProduction**: `nodeENV === "production"`

229

- **isDevelopment**: `nodeENV === "dev"` OR `nodeENV === "development"`

230

- **isMinimal**: `env.MINIMAL` is truthy OR `isCI` OR `isTest` OR `!hasTTY`

231

- **hasTTY**: `process.stdout.isTTY` is truthy

232

- **hasWindow**: `typeof window !== "undefined"`

233

- **isColorSupported**: `!env.NO_COLOR` AND (`env.FORCE_COLOR` OR `hasTTY` OR `isWindows` OR `isCI`) AND `env.TERM !== "dumb"`