Registry / devops / js-shrink

js-shrink

JSON →
library1.0.19jsnpmunverified

js-shrink is a supplemental JavaScript minifier that shortens string literals, property names, variable names, and built-in values by replacing frequently used strings with short variable declarations. It preserves property names (no mangling) for safety, making it less effective than full mangling but safe for all property names. This package is typically used alongside a standard minifier like Terser for additional size reduction. It is released on npm under MIT license and receives occasional updates. Key differentiators: focuses on string and property name shortening without mangling, supports source maps, and allows fine-grained control through many options.

npm install js-shrink
INSTALL
IMPORT
SIG · JS-SHRINK
J
js-shrink
devopsjavascriptv1.0.19
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import shrink from 'js-shrink'
const shrink = require('js-shrink').default
The default export is a function. In ESM, use default import; in CJS, use require('js-shrink') which returns the function directly (not a module).
shrink (CJS)
const shrink = require('js-shrink')
const { shrink } = require('js-shrink')
The package exports a single function as the module.exports. There is no named export 'shrink'.
TypeScript types
import shrink from 'js-shrink'
import * as shrink from 'js-shrink'
This package does not ship TypeScript types. You may need to use @types/js-shrink or declare types manually.
Options interface
import shrink from 'js-shrink'; const options: Options = { literals: true }
No public type exports; object literal type is inferred from usage.

Demonstrates basic usage of js-shrink to minify a simple function by shortening literals and variable names.

import shrink from 'js-shrink'; const code = `function greet(name) { return "Hello, " + name; }`; const minified = shrink(code, { literals: true, properties: false, variables: true, undeclared: true, values: true, this: false }); console.log(minified); // Might output: function greet(a){return"Hello, "+a}
Debug
Known issues
gotchaDefault options do not include 'all': you must explicitly enable each feature (literals, properties, variables, etc.) or set all: true.
fix
Set 'all: true' to shrink everything except numbers, classObjects, and functions, or explicitly enable desired features.
affects: >=1.0.0
gotchaProperty names are not mangled but are shortened in the same way as strings. This is safer but less effective than mangling. Do not expect property renaming like Terser.
fix
Understand that property names are replaced with short variables (not renamed) – they remain the same but are assigned to shorter identifiers.
affects: >=1.0.0
deprecatedOption 'declarationsPlaceholder', 'declarationsPlaceholderConst', 'declarationsPlaceholderVar' use underscore style; may be renamed in future.
fix
Check latest docs for any alternative; currently still supported.
affects: >=1.0.0
gotchaSource map generation generates a map object only if 'generateSourceMapObject' is true; otherwise no map is produced. Inline source map requires 'generateSourceMapInline'.
fix
Enable both options to get an inline source map.
affects: >=1.0.0
Errors
Common errors & fixes
shrink is not a function
Using named import 'shrink' instead of default import.
fix
Use import shrink from 'js-shrink' (ESM) or const shrink = require('js-shrink') (CJS).
Unexpected token 'export'
Using ESM import syntax in a Node.js environment that expects CommonJS without type:module.
fix
Add type:module to package.json or use require('js-shrink') instead.
Cannot find module 'js-shrink'
Package not installed or path incorrect.
fix
Run npm install js-shrink, then check node_modules directory.
Upgrade
Version history
1.0.19latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
js-shrink — npm install js-shrink · libregistry