@node-minify/utils
v11.1.0
Published
utils for @node-minify
Readme
@node-minify/utils
Shared utilities for node-minify compressor packages.
This package provides common file operations, argument building, and helper functions used internally by node-minify compressors.
Installation
npm install @node-minify/utilsExported Functions
File Operations
| Function | Description |
|----------|-------------|
| readFileAsync(filePath) | Read file contents as a string |
| writeFileAsync({ file, content, index }) | Write content to a file |
| isValidFileAsync(filePath) | Check if a file exists and is readable |
| getContentFromFilesAsync(input) | Read and concatenate content from multiple files |
File Size Utilities
| Function | Description |
|----------|-------------|
| getFilesizeInBytes(filePath) | Get human-readable file size (e.g., "1.5 kB") |
| getFilesizeGzippedInBytes(content) | Get human-readable gzipped size |
| prettyBytes(bytes) | Format bytes as human-readable string |
Compression Helpers
| Function | Description |
|----------|-------------|
| compressSingleFile(settings) | Compress a single file using the configured compressor |
| run(settings) | Execute compression with the provided settings |
| setFileNameMin(file, output, publicFolder, replaceInPlace) | Generate output filename from input |
Deprecated (removed in v12)
These exports still work in v11, and none of them emits a new deprecation warning. Your editor shows them as deprecated.
| Export | Use instead |
|--------|-------------|
| readFile | readFileAsync |
| writeFile | writeFileAsync |
| getContentFromFiles | getContentFromFilesAsync |
| isValidFile | isValidFileAsync |
| deleteFile | fs.promises.unlink |
| getSourceMapBoolean | extractSourceMapOption |
| tryResolveBuiltIn, tryResolveNpmPackage, tryResolveLocalFile | resolveCompressor |
| getKnownExportName | getCompressorEntry(name)?.exportName, with the canonical name (it does not resolve aliases: use "google-closure-compiler", not "gcc") |
| isLocalPath | none (resolveCompressor accepts local paths) |
| validateMinifyResult | none (run already validates every compressor's result) |
| buildArgs, toBuildArgsOptions, BuildArgsOptions | none |
| warnDeprecation, resetDeprecationWarnings | none |
| WildcardOptions.publicFolder (the object form of wildcards options) | pass the public folder as a string: wildcards(input, publicFolder) |
| WildcardOptions.ignore | none |
Usage Example
import { readFileAsync, writeFileAsync, getFilesizeInBytes } from '@node-minify/utils';
// Read a file
const content = await readFileAsync('src/app.js');
// Write minified content
await writeFileAsync({
file: 'dist/app.min.js',
content: minifiedContent,
index: 0
});
// Get file size
const size = await getFilesizeInBytes('dist/app.min.js');
console.log(`Output size: ${size}`); // "Output size: 2.3 kB"