@swc/html
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -6,2 +6,23 @@ /* tslint:disable */ | ||
export interface Diagnostic { | ||
level: string; | ||
message: string; | ||
span: any; | ||
} | ||
export interface TransformOutput { | ||
code: string; | ||
errors?: Array<Diagnostic>; | ||
} | ||
export interface Attribute { | ||
namespace?: string; | ||
prefix?: string; | ||
name: string; | ||
value?: string; | ||
} | ||
export interface Element { | ||
tagName: string; | ||
namespace: string; | ||
attributes: Array<Attribute>; | ||
isSelfClosing: boolean; | ||
} | ||
export function minify( | ||
@@ -11,3 +32,9 @@ code: Buffer, | ||
signal?: AbortSignal | undefined | null | ||
): Promise<string>; | ||
export function minifySync(code: Buffer, opts: Buffer): string; | ||
): Promise<TransformOutput>; | ||
export function minifyFragment( | ||
code: Buffer, | ||
opts: Buffer, | ||
signal?: AbortSignal | undefined | null | ||
): Promise<TransformOutput>; | ||
export function minifySync(code: Buffer, opts: Buffer): TransformOutput; | ||
export function minifyFragmentSync(code: Buffer, opts: Buffer): TransformOutput; |
@@ -243,5 +243,8 @@ const { existsSync, readFileSync } = require("fs"); | ||
const { minify, minifySync } = nativeBinding; | ||
const { minify, minifyFragment, minifySync, minifyFragmentSync } = | ||
nativeBinding; | ||
module.exports.minify = minify; | ||
module.exports.minifyFragment = minifyFragment; | ||
module.exports.minifySync = minifySync; | ||
module.exports.minifyFragmentSync = minifyFragmentSync; |
10
index.js
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.minifySync = exports.minify = void 0; | ||
exports.minifyFragmentSync = exports.minifySync = exports.minifyFragment = exports.minify = void 0; | ||
const binding = __importStar(require("./binding")); | ||
@@ -33,2 +33,6 @@ async function minify(content, options) { | ||
exports.minify = minify; | ||
async function minifyFragment(content, options) { | ||
return binding.minifyFragment(content, toBuffer(options !== null && options !== void 0 ? options : {})); | ||
} | ||
exports.minifyFragment = minifyFragment; | ||
function minifySync(content, options) { | ||
@@ -38,4 +42,8 @@ return binding.minifySync(content, toBuffer(options !== null && options !== void 0 ? options : {})); | ||
exports.minifySync = minifySync; | ||
async function minifyFragmentSync(content, options) { | ||
return binding.minifyFragmentSync(content, toBuffer(options !== null && options !== void 0 ? options : {})); | ||
} | ||
exports.minifyFragmentSync = minifyFragmentSync; | ||
function toBuffer(t) { | ||
return Buffer.from(JSON.stringify(t)); | ||
} |
65
index.ts
import * as binding from "./binding"; | ||
export async function minify(content: Buffer, options?: any): Promise<string> { | ||
type MinifierType = "js-module" | "js-script" | "json" | "css" | "html"; | ||
type Options = { | ||
filename?: string; | ||
iframeSrcdoc?: boolean; | ||
scriptingEnabled?: boolean; | ||
forceSetHtml5Doctype?: boolean; | ||
collapseWhitespaces?: | ||
| "none" | ||
| "all" | ||
| "smart" | ||
| "conservative" | ||
| "advanced-conservative" | ||
| "only-metadata"; | ||
removeEmptyMetadataElements?: boolean; | ||
removeComments?: boolean; | ||
preserveComments: string[]; | ||
minifyConditionalComments?: boolean; | ||
removeEmptyAttributes?: boolean; | ||
removeRedundantAttributes?: boolean; | ||
collapseBooleanAttributes?: boolean; | ||
normalizeAttributes?: boolean; | ||
minifyJson?: boolean | { pretty?: boolean }; | ||
// TODO improve me after typing `@swc/css` | ||
minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any }; | ||
minifyCss?: boolean | { parser?: any; minifier?: any; codegen?: any }; | ||
minifyAdditionalScriptsContent?: [string, MinifierType][]; | ||
minifyAdditionalAttributes?: [string, MinifierType][]; | ||
sortSpaceSeparatedAttributeValues?: boolean; | ||
sortAttributes?: boolean; | ||
tagOmission?: boolean; | ||
selfClosingVoidElements?: boolean; | ||
quotes?: boolean; | ||
}; | ||
type FragmentOptions = Options & { | ||
mode?: "no-quirks" | "limited-quirks" | "quirks"; | ||
context_element?: binding.Element; | ||
form_element?: binding.Element; | ||
}; | ||
export async function minify( | ||
content: Buffer, | ||
options?: Options | ||
): Promise<binding.TransformOutput> { | ||
return binding.minify(content, toBuffer(options ?? {})); | ||
} | ||
export function minifySync(content: Buffer, options?: any) { | ||
export async function minifyFragment( | ||
content: Buffer, | ||
options?: FragmentOptions | ||
): Promise<binding.TransformOutput> { | ||
return binding.minifyFragment(content, toBuffer(options ?? {})); | ||
} | ||
export function minifySync( | ||
content: Buffer, | ||
options?: Options | ||
): binding.TransformOutput { | ||
return binding.minifySync(content, toBuffer(options ?? {})); | ||
} | ||
export async function minifyFragmentSync( | ||
content: Buffer, | ||
options?: FragmentOptions | ||
): Promise<binding.TransformOutput> { | ||
return binding.minifyFragmentSync(content, toBuffer(options ?? {})); | ||
} | ||
function toBuffer(t: any): Buffer { | ||
return Buffer.from(JSON.stringify(t)); | ||
} |
{ | ||
"name": "@swc/html", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "Super-fast alternative for posthtml", | ||
@@ -57,16 +57,16 @@ "homepage": "https://swc.rs", | ||
"optionalDependencies": { | ||
"@swc/html-win32-x64-msvc": "0.0.16", | ||
"@swc/html-darwin-x64": "0.0.16", | ||
"@swc/html-linux-x64-gnu": "0.0.16", | ||
"@swc/html-linux-x64-musl": "0.0.16", | ||
"@swc/html-freebsd-x64": "0.0.16", | ||
"@swc/html-win32-ia32-msvc": "0.0.16", | ||
"@swc/html-linux-arm64-gnu": "0.0.16", | ||
"@swc/html-linux-arm-gnueabihf": "0.0.16", | ||
"@swc/html-darwin-arm64": "0.0.16", | ||
"@swc/html-android-arm64": "0.0.16", | ||
"@swc/html-linux-arm64-musl": "0.0.16", | ||
"@swc/html-win32-arm64-msvc": "0.0.16", | ||
"@swc/html-android-arm-eabi": "0.0.16" | ||
"@swc/html-win32-x64-msvc": "0.0.17", | ||
"@swc/html-darwin-x64": "0.0.17", | ||
"@swc/html-linux-x64-gnu": "0.0.17", | ||
"@swc/html-linux-x64-musl": "0.0.17", | ||
"@swc/html-freebsd-x64": "0.0.17", | ||
"@swc/html-win32-ia32-msvc": "0.0.17", | ||
"@swc/html-linux-arm64-gnu": "0.0.17", | ||
"@swc/html-linux-arm-gnueabihf": "0.0.17", | ||
"@swc/html-darwin-arm64": "0.0.17", | ||
"@swc/html-android-arm64": "0.0.17", | ||
"@swc/html-linux-arm64-musl": "0.0.17", | ||
"@swc/html-win32-arm64-msvc": "0.0.17", | ||
"@swc/html-android-arm-eabi": "0.0.17" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14463
390
0