style-to-js is a lightweight JavaScript utility library designed to parse CSS inline style strings into a plain JavaScript object. It automatically converts kebab-cased CSS properties (e.g., `background-color`) into their camelCased JavaScript equivalents (e.g., `backgroundColor`), which is particularly useful for dynamically applying styles in environments like React or other component-based UI frameworks. The current stable version is `1.1.21`. The package maintains a relatively active release cadence, primarily focusing on dependency updates and minor bug fixes, with no recent major version changes. It differentiates itself by its straightforward API, handling of standard CSS properties, vendor prefixes (with an optional `reactCompat` flag for capitalized prefixes), and CSS custom properties. It's important to note that it performs minimal validation; it will process most input strings into camelCased properties, but silently removes declarations with missing values. Malformed syntax, such as properties missing colons or unclosed comments, will result in runtime errors.
npm install style-to-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic parsing, camelCasing, vendor prefix handling with `reactCompat`, and how invalid declarations are processed.
Ensure all CSS properties have valid values. The library does not perform strict CSS validation.
Validate input CSS strings for basic syntax correctness, especially ensuring colons are present for properties and comments are properly closed.
If integrating with React or similar frameworks that expect capitalized vendor prefixes, explicitly set `{ reactCompat: true }` in the options.Review the input CSS string for any property declarations that are incomplete. All properties must be followed by a colon and a value (even an empty one like `top: ;`).
Ensure all CSS comments in the input string are properly terminated with `*/`.
No dependency data recorded yet.