or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdpath-manipulation.mdpath-parsing.mdpath-resolution.mdplatform-operations.md

platform-operations.mddocs/

0

# Platform Operations

1

2

Platform-specific path operations and constants for Windows and POSIX systems, including long path support and platform identifiers.

3

4

## Capabilities

5

6

### Make Long Path

7

8

On Windows, converts a path to a long UNC path format to bypass the 260-character path length limitation. On POSIX systems, returns the path unchanged.

9

10

```javascript { .api }

11

/**

12

* Converts path to long UNC format on Windows, returns unchanged on POSIX

13

* @param {string} path - Path to convert

14

* @returns {string} Long UNC path on Windows, original path on POSIX

15

*/

16

function _makeLong(path: string): string;

17

```

18

19

**Usage Examples:**

20

21

```javascript

22

const path = require("path");

23

24

// Windows long path conversion

25

path.win32._makeLong("C:\\very\\long\\path\\to\\file.txt");

26

// Result: "\\\\?\\C:\\very\\long\\path\\to\\file.txt"

27

28

// UNC path conversion on Windows

29

path.win32._makeLong("\\\\server\\share\\file.txt");

30

// Result: "\\\\?\\UNC\\server\\share\\file.txt"

31

32

// Already absolute path on Windows

33

path.win32._makeLong("C:\\temp\\file.txt");

34

// Result: "\\\\?\\C:\\temp\\file.txt"

35

36

// POSIX systems - no conversion

37

path.posix._makeLong("/very/long/path/to/file.txt");

38

// Result: "/very/long/path/to/file.txt"

39

40

// Non-string input returns as-is

41

path._makeLong(null);

42

// Result: null

43

44

// Empty string returns empty string

45

path._makeLong("");

46

// Result: ""

47

48

// Relative paths that don't resolve to absolute remain unchanged

49

path.win32._makeLong("relative\\path");

50

// Result: "relative\\path" (unchanged because not absolute after resolution)

51

```

52

53

**Platform Behavior:**

54

55

```javascript

56

// On Windows platform

57

path._makeLong("C:\\Users\\Documents\\very-long-filename.txt");

58

// Result: "\\\\?\\C:\\Users\\Documents\\very-long-filename.txt"

59

60

// On POSIX platform

61

path._makeLong("/home/user/documents/very-long-filename.txt");

62

// Result: "/home/user/documents/very-long-filename.txt"

63

64

// Force platform-specific behavior

65

path.win32._makeLong("/posix/path"); // No conversion (not Windows path format)

66

path.posix._makeLong("C:\\windows"); // Returns unchanged

67

```

68

69

## Platform Constants

70

71

### Path Separator

72

73

The platform-specific path segment separator.

74

75

```javascript { .api }

76

/** Platform-specific path segment separator */

77

const sep: string;

78

```

79

80

**Values:**

81

82

```javascript

83

const path = require("path");

84

85

// Platform-specific separator

86

console.log(path.sep);

87

// POSIX: "/"

88

// Windows: "\\"

89

90

// Force specific platform behavior

91

console.log(path.posix.sep); // Always "/"

92

console.log(path.win32.sep); // Always "\\"

93

```

94

95

**Usage Examples:**

96

97

```javascript

98

// Split path using platform separator

99

const pathParts = "/users/john/docs".split(path.posix.sep);

100

// Result: ["", "users", "john", "docs"]

101

102

const winParts = "C:\\Users\\John\\docs".split(path.win32.sep);

103

// Result: ["C:", "Users", "John", "docs"]

104

105

// Build path using separator

106

const buildPath = ["users", "john", "docs"].join(path.sep);

107

// POSIX: "users/john/docs"

108

// Windows: "users\\john\\docs"

109

```

110

111

### Path Delimiter

112

113

The platform-specific PATH environment variable delimiter.

114

115

```javascript { .api }

116

/** Platform-specific PATH delimiter */

117

const delimiter: string;

118

```

119

120

**Values:**

121

122

```javascript

123

const path = require("path");

124

125

// Platform-specific PATH delimiter

126

console.log(path.delimiter);

127

// POSIX: ":"

128

// Windows: ";"

129

130

// Force specific platform behavior

131

console.log(path.posix.delimiter); // Always ":"

132

console.log(path.win32.delimiter); // Always ";"

133

```

134

135

**Usage Examples:**

136

137

```javascript

138

// Parse PATH environment variable

139

const pathEnv = process.env.PATH;

140

const pathDirs = pathEnv.split(path.delimiter);

141

142

// POSIX example: "/usr/bin:/usr/local/bin:/bin"

143

// Results in: ["/usr/bin", "/usr/local/bin", "/bin"]

144

145

// Windows example: "C:\\Windows;C:\\Windows\\System32"

146

// Results in: ["C:\\Windows", "C:\\Windows\\System32"]

147

148

// Build PATH string

149

const newPath = ["/usr/local/bin", "/usr/bin", "/bin"].join(path.posix.delimiter);

150

// Result: "/usr/local/bin:/usr/bin:/bin"

151

152

const winPath = ["C:\\Tools", "C:\\Windows"].join(path.win32.delimiter);

153

// Result: "C:\\Tools;C:\\Windows"

154

```

155

156

## Cross-Platform Access

157

158

Both Windows and POSIX implementations are always available regardless of the current platform:

159

160

```javascript { .api }

161

/** POSIX path utilities (available on all platforms) */

162

const posix: {

163

resolve(...paths: string[]): string;

164

normalize(path: string): string;

165

isAbsolute(path: string): boolean;

166

join(...paths: string[]): string;

167

relative(from: string, to: string): string;

168

dirname(path: string): string;

169

basename(path: string, ext?: string): string;

170

extname(path: string): string;

171

parse(pathString: string): ParsedPath;

172

format(pathObject: PathObject): string;

173

_makeLong(path: string): string;

174

readonly sep: "/";

175

readonly delimiter: ":";

176

};

177

178

/** Windows path utilities (available on all platforms) */

179

const win32: {

180

resolve(...paths: string[]): string;

181

normalize(path: string): string;

182

isAbsolute(path: string): boolean;

183

join(...paths: string[]): string;

184

relative(from: string, to: string): string;

185

dirname(path: string): string;

186

basename(path: string, ext?: string): string;

187

extname(path: string): string;

188

parse(pathString: string): ParsedPath;

189

format(pathObject: PathObject): string;

190

_makeLong(path: string): string;

191

readonly sep: "\\";

192

readonly delimiter: ";";

193

};

194

```

195

196

**Usage Examples:**

197

198

```javascript

199

const path = require("path");

200

201

// Process Windows paths on any platform

202

const winPath = path.win32.normalize("C:/Users\\John/../Jane");

203

// Result: "C:\\Users\\Jane"

204

205

// Process POSIX paths on any platform

206

const posixPath = path.posix.normalize("/users//john/../jane");

207

// Result: "/users/jane"

208

209

// Determine path type and process accordingly

210

function processPath(inputPath) {

211

if (inputPath.match(/^[a-zA-Z]:/)) {

212

// Looks like Windows path

213

return path.win32.normalize(inputPath);

214

} else {

215

// Treat as POSIX path

216

return path.posix.normalize(inputPath);

217

}

218

}

219

220

// Cross-platform path building

221

function buildCrossPlatformPath(parts, targetPlatform) {

222

if (targetPlatform === "win32") {

223

return parts.join(path.win32.sep);

224

} else {

225

return parts.join(path.posix.sep);

226

}

227

}

228

```

229

230

## Platform Detection

231

232

The module automatically exports the appropriate implementation based on the current platform:

233

234

```javascript

235

// Main export is platform-dependent

236

const path = require("path");

237

238

// On Windows: path === path.win32

239

// On POSIX: path === path.posix

240

241

// Check current platform behavior

242

if (path.sep === "\\") {

243

console.log("Using Windows path implementation");

244

} else {

245

console.log("Using POSIX path implementation");

246

}

247

```