or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-swc--html-linux-arm-gnueabihf

Super-fast HTML minifier - platform-specific native Node.js addon for Linux ARM gnueabihf architecture

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@swc/html-linux-arm-gnueabihf@1.13.x

To install, run

npx @tessl/cli install tessl/npm-swc--html-linux-arm-gnueabihf@1.13.0

index.mddocs/

SWC HTML Linux ARM

SWC HTML Linux ARM is a platform-specific native Node.js addon that provides super-fast HTML minification capabilities for Linux ARM gnueabihf architecture systems. It's part of the SWC (Speedy Web Compiler) ecosystem and contains a compiled native binary that exposes HTML minification functionality through Rust-powered Node.js bindings, offering optimal performance through native implementation.

Package Information

  • Package Name: @swc/html-linux-arm-gnueabihf
  • Package Type: npm
  • Language: TypeScript/Rust (native addon)
  • Installation: Automatically installed as optional dependency of @swc/html
  • Architecture: Linux ARM gnueabihf
  • Node.js: >=10

Core Imports

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

For CommonJS:

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

Basic Usage

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

// Asynchronous HTML minification
const result = await minify(`
  <html>
    <head>
      <title>  Example  </title>
    </head>
    <body>
      <p>   Hello   World   </p>
    </body>
  </html>
`, {
  collapseWhitespaces: "smart",
  removeComments: true
});

console.log(result.code);
// <html><head><title>Example</title></head><body><p>Hello World</p></body></html>

// Synchronous HTML minification  
const syncResult = minifySync('<p>  Hello  </p>', {
  collapseWhitespaces: "all"
});

console.log(syncResult.code);
// <p>Hello</p>

Architecture

SWC HTML Linux ARM is structured around several key components:

  • Platform-Specific Binary: Native .node file (swc-html.linux-arm-gnueabihf.node) compiled from Rust
  • TypeScript Interface: Type-safe wrapper providing async/sync APIs for both documents and fragments
  • Native Bindings: NAPI-RS powered bindings connecting TypeScript API to Rust implementation
  • Minification Engine: Rust-based HTML parser, minifier, and code generator with CSS/JS integration
  • Optional Dependency: Automatically installed when main @swc/html package detects compatible ARM Linux system

Capabilities

HTML Document Minification

Complete HTML document processing with comprehensive minification options.

/**
 * Asynchronously minifies complete HTML documents
 * @param content - HTML content as string or Buffer
 * @param options - Minification configuration options
 * @returns Promise resolving to minified HTML with optional errors
 */
function minify(
  content: string | Buffer,
  options?: Options
): Promise<TransformOutput>;

/**
 * Synchronously minifies complete HTML documents
 * @param content - HTML content as string or Buffer  
 * @param options - Minification configuration options
 * @returns Minified HTML with optional errors
 */
function minifySync(
  content: string | Buffer,
  options?: Options
): TransformOutput;

Usage Examples:

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

// Advanced minification with CSS and JS
const advancedResult = await minify(`
  <!DOCTYPE html>
  <html>
    <head>
      <style>
        body { margin: 0; padding: 10px; }
        .highlight { background: yellow; }
      </style>
      <script>
        function greet() {
          console.log("Hello World");
        }
      </script>
    </head>
    <body class="container">
      <h1 id="title">Welcome</h1>
      <p>This is a paragraph with lots of   whitespace.</p>
      <!-- This comment will be removed -->
      <button onclick="greet()">Click me</button>
    </body>
  </html>
`, {
  collapseWhitespaces: "smart",
  removeComments: true,
  minifyCss: true,
  minifyJs: true,
  removeEmptyAttributes: true,
  collapseBooleanAttributes: true
});

// Minimal configuration for quick processing
const quickResult = minifySync('<p>  Simple  text  </p>', {
  collapseWhitespaces: "all"
});

HTML Fragment Minification

HTML fragment processing with proper parsing context and document mode support.

/**
 * Asynchronously minifies HTML fragments with parsing context
 * @param content - HTML fragment content as string or Buffer
 * @param options - Fragment minification options with context
 * @returns Promise resolving to minified HTML fragment
 */
function minifyFragment(
  content: string | Buffer,
  options?: FragmentOptions
): Promise<TransformOutput>;

/**
 * Synchronously minifies HTML fragments with parsing context
 * @param content - HTML fragment content as string or Buffer
 * @param options - Fragment minification options with context
 * @returns Minified HTML fragment
 */
function minifyFragmentSync(
  content: string | Buffer,
  options?: FragmentOptions
): TransformOutput;

Usage Examples:

import { minifyFragment, minifyFragmentSync } from "@swc/html";

// Fragment with context element
const listFragment = await minifyFragment(`
  <li class="item">   First item   </li>
  <li class="item">   Second item  </li>
`, {
  collapseWhitespaces: "smart",
  context_element: {
    tagName: "ul",
    namespace: "http://www.w3.org/1999/xhtml",
    attributes: [],
    isSelfClosing: false
  }
});

// Table fragment with form context
const tableFragment = minifyFragmentSync(`
  <tr>
    <td><input type="text" name="username" required /></td>
    <td><input type="email" name="email" /></td>
  </tr>
`, {
  collapseWhitespaces: "all",
  collapseBooleanAttributes: true,
  context_element: {
    tagName: "table", 
    namespace: "http://www.w3.org/1999/xhtml",
    attributes: [],
    isSelfClosing: false
  },
  form_element: {
    tagName: "form",
    namespace: "http://www.w3.org/1999/xhtml", 
    attributes: [],
    isSelfClosing: false
  }
});

Types

/**
 * Minification configuration options for HTML documents
 */
interface Options {
  /** Optional filename for debugging purposes */
  filename?: string;
  /** Whether content is from iframe srcdoc attribute */
  iframeSrcdoc?: boolean;
  /** Enable/disable JavaScript processing during parsing */
  scriptingEnabled?: boolean;
  /** Force HTML5 doctype in output */
  forceSetHtml5Doctype?: boolean;
  /** Whitespace collapse strategy */
  collapseWhitespaces?: 
    | "none" 
    | "all" 
    | "smart" 
    | "conservative" 
    | "advanced-conservative" 
    | "only-metadata";
  /** Remove empty metadata elements (script, style, meta, link without content/attributes) */
  removeEmptyMetadataElements?: boolean;
  /** Remove HTML comments */
  removeComments?: boolean;
  /** Regex patterns for comments to preserve (e.g., license comments) */
  preserveComments?: string[];
  /** Minify conditional IE comments */
  minifyConditionalComments?: boolean;
  /** Remove empty HTML attributes */
  removeEmptyAttributes?: boolean;
  /** Remove redundant HTML attributes */
  removeRedundantAttributes?: "none" | "all" | "smart";
  /** Collapse boolean attributes (e.g., disabled="disabled" -> disabled) */
  collapseBooleanAttributes?: boolean;
  /** Normalize attribute values and names */
  normalizeAttributes?: boolean;
  /** JSON minification configuration */
  minifyJson?: boolean | { pretty?: boolean };
  /** JavaScript minification configuration */
  minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any };
  /** CSS minification configuration */
  minifyCss?: 
    | boolean 
    | { lib: "lightningcss" } 
    | { lib: "swc"; parser?: any; minifier?: any; codegen?: any };
  /** Additional script content patterns to minify */
  minifyAdditionalScriptsContent?: [string, MinifierType][];
  /** Additional attribute patterns to minify */
  minifyAdditionalAttributes?: [string, MinifierType][];
  /** Sort space-separated attribute values alphabetically */
  sortSpaceSeparatedAttributeValues?: boolean;
  /** Sort attributes alphabetically */
  sortAttributes?: boolean;
  /** Enable HTML tag omission optimization */
  tagOmission?: boolean | "keep-head-and-body";
  /** Use self-closing syntax for void elements */
  selfClosingVoidElements?: boolean;
  /** Quote handling for attributes */
  quotes?: boolean;
}

/**
 * Extended options for HTML fragment minification
 */
interface FragmentOptions extends Options {
  /** Document parsing mode for fragment context */
  mode?: "no-quirks" | "limited-quirks" | "quirks";
  /** Context element for fragment parsing (defaults to template element) */
  context_element?: Element;
  /** Form element context for parsing form-related fragments */
  form_element?: Element;
}

/**
 * Supported minifier types for additional content processing
 */
type MinifierType = "js-module" | "js-script" | "json" | "css" | "html";

/**
 * Result of HTML minification operation
 */
interface TransformOutput {
  /** Minified HTML code */
  code: string;
  /** Optional array of parsing/processing errors and warnings */
  errors?: Diagnostic[];
}

/**
 * HTML element representation for parsing context
 */
interface Element {
  /** Element tag name */
  tagName: string;
  /** Element namespace URI */
  namespace: string;
  /** Element attributes */
  attributes: Attribute[];
  /** Whether element uses self-closing syntax */
  isSelfClosing: boolean;
}

/**
 * HTML attribute representation
 */
interface Attribute {
  /** Optional attribute namespace */
  namespace?: string;
  /** Optional attribute prefix */
  prefix?: string;
  /** Attribute name */
  name: string;
  /** Optional attribute value */
  value?: string;
}

/**
 * Diagnostic information for errors and warnings
 */
interface Diagnostic {
  /** Diagnostic level (error, warning, info) */
  level: string;
  /** Human-readable diagnostic message */
  message: string;
  /** Source code location information */
  span: any;
}

Error Handling

The minification functions can encounter various types of errors during HTML parsing and processing:

import { minify } from "@swc/html";

try {
  const result = await minify('<div><p>Unclosed paragraph</div>');
  
  // Check for parsing errors
  if (result.errors && result.errors.length > 0) {
    result.errors.forEach(error => {
      console.warn(`${error.level}: ${error.message}`);
    });
  }
  
  console.log(result.code);
} catch (error) {
  console.error('Minification failed:', error);
}

Common error scenarios:

  • Malformed HTML: Invalid tag structures, mismatched quotes
  • Invalid Options: Unsupported configuration values
  • Memory Issues: Extremely large input files
  • Context Errors: Invalid context_element or form_element in fragment options