Registry / serialization / babel-plugin-optimize-objstr

babel-plugin-optimize-objstr

JSON →
library1.0.0jsnpmunverified

Babel plugin that optimizes calls to `obj-str` by replacing them with equivalent unrolled string concatenation, resulting in ~1.8x performance improvement. Version 1.1.0 includes TypeScript definitions. Maintained by the same author as the `obj-str` library. Key differentiator: unlike other classname utilities, this plugin performs static analysis to inline only optimizable calls, preserving others by default. Released under MIT license.

npm install babel-plugin-optimize-objstr
INSTALL
IMPORT
SIG · BABEL-PLUGIN-OPTIM
B
babel-plugin-optimize-objstr
serializationjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

plugin
plugins: ['optimize-obj-str']
plugins: ['babel-plugin-optimize-obj-str']
The plugin name in Babel config omits the 'babel-plugin-' prefix.
options
plugins: [['optimize-obj-str', { strict: true }]]
plugins: ['optimize-obj-str', { strict: true }]
Options must be wrapped in an array with the plugin name as the first element.

Configures Babel to replace obj-str calls with optimized string concatenation for performance gains.

// babel.config.js module.exports = { plugins: ['optimize-obj-str'] }; // input.js import objstr from 'obj-str'; const classes = objstr({ 'btn': true, 'btn-primary': isPrimary, 'disabled': isDisabled }); // output.js const classes = 'btn' + (isPrimary ? ' btn-primary' : '') + (isDisabled ? ' disabled' : '');
Debug
Known issues
gotchaTransformed output includes a leading space for truthy values, unlike raw objstr() which omits leading spaces. Ensure consumers handle leading spaces.
fix
The leading space is intentional; most consumers like className work fine with it.
affects: *
gotchaDuplicate property names with identical keys are resolved by the last value, but the plugin uses the first key's literal string. If duplicate keys have different conditions, the behavior may be unexpected.
fix
Avoid duplicate keys in obj-str calls, or use a consistent condition for duplicate keys.
affects: <1.1.0
gotchaThe plugin may slightly increase bundle size if many (e.g., >100) conditional properties are used. It is intended for performance, not size reduction.
fix
Consider the trade-off; for large number of properties, using obj-str directly may be smaller.
affects: *
deprecatedThe option 'strict' defaults to false. Setting strict: true makes the plugin throw errors for non-optimizable calls, which may break builds.
fix
Use strict mode only if you have full control over all obj-str calls and want to enforce optimization.
affects: *
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'babel-plugin-optimize-obj-str'
Forgot to install the plugin.
fix
npm install --save-dev babel-plugin-optimize-obj-str
TypeError: Cannot read property 'replace' of undefined
Passing an argument that is not an object literal (e.g., identifier, spread).
fix
Ensure the first argument to objstr() is an object literal with string literal keys. Non-optimizable calls are preserved by default.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
babel-plugin-optimize-objstr — npm install babel-plugin-optimize-objstr · libregistry