or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-swc--html-darwin-arm64

Super-fast HTML minifier native binary for macOS ARM64 (Apple Silicon)

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@swc/html-darwin-arm64@1.13.x

To install, run

npx @tessl/cli install tessl/npm-swc--html-darwin-arm64@1.13.0

0

# @swc/html-darwin-arm64

1

2

@swc/html-darwin-arm64 is a platform-specific native binary package for macOS ARM64 (Apple Silicon) that provides super-fast HTML minification capabilities. This package contains a compiled Rust binary that implements high-performance HTML parsing, minification, and optimization features as part of the SWC (Speedy Web Compiler) ecosystem.

3

4

## Package Information

5

6

- **Package Name**: @swc/html-darwin-arm64

7

- **Package Type**: npm

8

- **Language**: Rust (compiled to N-API native module)

9

- **Installation**: Automatically installed as dependency of `@swc/html` on macOS ARM64 systems

10

- **Platform**: macOS (darwin) ARM64 only

11

- **Main Binary**: swc-html.darwin-arm64.node

12

13

## Core Imports

14

15

This package is a platform-specific native dependency and is not used directly. Instead, it provides native implementation for the `@swc/html` package APIs. Import from the main package:

16

17

```typescript

18

import { minify, minifySync, minifyFragment, minifyFragmentSync, type Options, type FragmentOptions } from "@swc/html";

19

```

20

21

For CommonJS:

22

23

```javascript

24

const { minify, minifySync, minifyFragment, minifyFragmentSync } = require("@swc/html");

25

```

26

27

**Note**: The `@swc/html-darwin-arm64` package is automatically selected as a dependency on macOS ARM64 systems and cannot be imported directly. Type definitions for `TransformOutput`, `Element`, `Attribute`, and `Diagnostic` are available from function return types.

28

29

## Basic Usage

30

31

```typescript

32

import { minify, type Options } from "@swc/html";

33

34

// Basic HTML minification

35

const result = await minify(`

36

<html>

37

<head>

38

<title> Example Page </title>

39

</head>

40

<body>

41

<!-- This is a comment -->

42

<p class="text"> Hello World! </p>

43

</body>

44

</html>

45

`);

46

47

console.log(result.code); // Minified HTML

48

49

// With configuration options

50

const options: Options = {

51

collapseWhitespaces: "smart",

52

removeComments: true,

53

removeEmptyAttributes: true,

54

minifyJs: true,

55

minifyCss: true

56

};

57

58

const minified = await minify(htmlContent, options);

59

```

60

61

## Architecture

62

63

The @swc/html-darwin-arm64 package provides native performance through:

64

65

- **N-API Integration**: Rust binary compiled to Node.js native addon

66

- **Platform Detection**: Automatically loaded on macOS ARM64 systems via @swc/html

67

- **High Performance**: Memory-efficient HTML parsing and minification in Rust

68

- **Zero JavaScript API**: All functionality exposed through parent @swc/html package

69

70

## Capabilities

71

72

### HTML Minification

73

74

Core HTML minification functionality with extensive configuration options for whitespace handling, comment removal, and attribute optimization.

75

76

```typescript { .api }

77

/**

78

* Asynchronously minifies HTML content with options

79

* @param content - HTML content as string or Buffer

80

* @param options - Optional minification configuration

81

* @returns Promise resolving to TransformOutput with minified code

82

*/

83

function minify(

84

content: string | Buffer,

85

options?: Options

86

): Promise<TransformOutput>;

87

88

/**

89

* Synchronously minifies HTML content with options

90

* @param content - HTML content as string or Buffer

91

* @param options - Optional minification configuration

92

* @returns TransformOutput with minified code

93

*/

94

function minifySync(

95

content: string | Buffer,

96

options?: Options

97

): TransformOutput;

98

```

99

100

### Fragment Minification

101

102

HTML fragment minification with parsing context support for handling partial HTML documents.

103

104

```typescript { .api }

105

/**

106

* Asynchronously minifies HTML fragment with context options

107

* @param content - HTML fragment as string or Buffer

108

* @param options - Optional fragment-specific configuration

109

* @returns Promise resolving to TransformOutput with minified fragment

110

*/

111

function minifyFragment(

112

content: string | Buffer,

113

options?: FragmentOptions

114

): Promise<TransformOutput>;

115

116

/**

117

* Synchronously minifies HTML fragment with context options

118

* @param content - HTML fragment as string or Buffer

119

* @param options - Optional fragment-specific configuration

120

* @returns TransformOutput with minified fragment

121

*/

122

function minifyFragmentSync(

123

content: string | Buffer,

124

options?: FragmentOptions

125

): TransformOutput;

126

```

127

128

## Types

129

130

### Core Types

131

132

```typescript { .api }

133

interface TransformOutput {

134

/** Minified HTML content */

135

code: string;

136

/** Optional array of diagnostic messages */

137

errors?: Array<Diagnostic>;

138

}

139

140

interface Diagnostic {

141

/** Diagnostic level (error, warning, etc.) */

142

level: string;

143

/** Diagnostic message text */

144

message: string;

145

/** Source location span information */

146

span: any;

147

}

148

149

type MinifierType = "js-module" | "js-script" | "json" | "css" | "html";

150

```

151

152

### Configuration Types

153

154

```typescript { .api }

155

interface Options {

156

/** Input filename for error reporting */

157

filename?: string;

158

/** Whether content is from iframe srcdoc */

159

iframeSrcdoc?: boolean;

160

/** Whether scripting is enabled during parsing */

161

scriptingEnabled?: boolean;

162

/** Force HTML5 doctype */

163

forceSetHtml5Doctype?: boolean;

164

165

/** Whitespace collapse strategy */

166

collapseWhitespaces?:

167

| "none"

168

| "all"

169

| "smart"

170

| "conservative"

171

| "advanced-conservative"

172

| "only-metadata";

173

174

/** Remove empty metadata elements */

175

removeEmptyMetadataElements?: boolean;

176

/** Remove HTML comments */

177

removeComments?: boolean;

178

/** Preserve specific comments matching patterns */

179

preserveComments?: string[];

180

/** Minify conditional comments */

181

minifyConditionalComments?: boolean;

182

183

/** Remove empty attributes */

184

removeEmptyAttributes?: boolean;

185

/** Remove redundant attributes */

186

removeRedundantAttributes?: "none" | "all" | "smart";

187

/** Collapse boolean attributes */

188

collapseBooleanAttributes?: boolean;

189

/** Normalize attribute formatting */

190

normalizeAttributes?: boolean;

191

192

/** Minify JSON content in script tags */

193

minifyJson?: boolean | { pretty?: boolean };

194

/** Minify JavaScript content in script tags */

195

minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any };

196

/** Minify CSS content in style tags */

197

minifyCss?:

198

| boolean

199

| { lib: "lightningcss" }

200

| { lib: "swc"; parser?: any; minifier?: any; codegen?: any };

201

202

/** Minify additional script content by type */

203

minifyAdditionalScriptsContent?: [string, MinifierType][];

204

/** Minify additional attributes by type */

205

minifyAdditionalAttributes?: [string, MinifierType][];

206

207

/** Sort space-separated attribute values */

208

sortSpaceSeparatedAttributeValues?: boolean;

209

/** Sort attributes alphabetically */

210

sortAttributes?: boolean;

211

/** Omit optional HTML tags */

212

tagOmission?: boolean | "keep-head-and-body";

213

/** Self-close void elements */

214

selfClosingVoidElements?: boolean;

215

/** Optimize quotes around attribute values */

216

quotes?: boolean;

217

}

218

219

interface FragmentOptions extends Options {

220

/** HTML parsing mode */

221

mode?: "no-quirks" | "limited-quirks" | "quirks";

222

/** Context element for fragment parsing */

223

context_element?: Element;

224

/** Form element context */

225

form_element?: Element;

226

}

227

```

228

229

### Element Types

230

231

```typescript { .api }

232

interface Element {

233

/** HTML tag name */

234

tagName: string;

235

/** Element namespace */

236

namespace: string;

237

/** Array of element attributes */

238

attributes: Array<Attribute>;

239

/** Whether element is self-closing */

240

isSelfClosing: boolean;

241

}

242

243

interface Attribute {

244

/** Optional attribute namespace */

245

namespace?: string;

246

/** Optional attribute prefix */

247

prefix?: string;

248

/** Attribute name */

249

name: string;

250

/** Optional attribute value */

251

value?: string;

252

}

253

```

254

255

## Key Features

256

257

The native binary provides these HTML minification capabilities:

258

259

- **Whitespace Optimization**: Multiple strategies for collapsing whitespace while preserving layout

260

- **Comment Processing**: Remove or preserve comments with pattern matching support

261

- **Attribute Optimization**: Normalize, sort, and remove redundant attributes

262

- **Boolean Attribute Collapsing**: Convert `checked="checked"` to `checked`

263

- **Integrated Content Minification**: Minify JavaScript, CSS, and JSON within HTML

264

- **Tag Omission**: Remove optional HTML tags where safe

265

- **Quote Optimization**: Optimize quotes around attribute values

266

- **Advanced Parsing**: Support for different HTML parsing modes and fragment contexts

267

- **Self-closing Elements**: Proper handling of void elements

268

- **Performance**: High-speed processing through Rust implementation

269

270

## Error Handling

271

272

All minification functions return a `TransformOutput` object that includes:

273

- `code`: The minified HTML string

274

- `errors`: Optional array of `Diagnostic` objects for warnings or non-fatal errors

275

276

```typescript

277

const result = await minify(htmlContent);

278

if (result.errors && result.errors.length > 0) {

279

result.errors.forEach(error => {

280

console.warn(`${error.level}: ${error.message}`);

281

});

282

}

283

```