File "convertInlineStyleStringToObject.js"

Full path: /home/webcknlt/admissiontell.com/wp-content/plugins/generateblocks/src/utils/convertInlineStyleStringToObject.js
File size: 691 B (691 B bytes)
MIME-type: text/plain
Charset: utf-8

Download   Open   Edit   Advanced Editor &nnbsp; Back

export function convertInlineStyleStringToObject( styleString ) {
	return styleString.split( ';' ).reduce( ( acc, style ) => {
		const colonIndex = style.indexOf( ':' );
		if ( colonIndex === -1 ) {
			return acc;
		} // Skip if there's no colon

		let key = style.slice( 0, colonIndex ).trim();
		const value = style.slice( colonIndex + 1 ).trim();

		if ( key && value ) {
			if ( key.startsWith( '--' ) ) {
				// It's a CSS custom property, keep the original format
				acc[ key ] = value;
			} else {
				// For regular CSS properties, convert to camelCase
				key = key.replace( /-([a-z])/g, ( g ) => g[ 1 ].toUpperCase() );
				acc[ key ] = value;
			}
		}

		return acc;
	}, {} );
}