File "variables.js"

Full Path: /home/fresvfqn/waterdamagerestorationandrepairsmithtown.com/wp-content/plugins/surerank/src/functions/variables.js
File size: 678 bytes
MIME-type: text/plain
Charset: utf-8

export const flat = ( variables, type = '' ) => {
	if ( ! variables ) {
		return;
	}

	let newVariables = {};
	if ( type === 'richSelect' ) {
		newVariables = [];
	}

	Object.values( variables ).forEach( ( variable ) => {
		Object.keys( variable ).forEach( ( key ) => {
			switch ( type ) {
				case 'richSelect':
					newVariables.push( {
						value: key,
						label: variable[ key ].label,
						title: '%' + key + '%',
						description: variable[ key ].description,
					} );
					break;
				case 'detailed':
					newVariables[ key ] = variable[ key ];
					break;
				default:
					newVariables[ key ] = variable[ key ].value;
			}
		} );
	} );

	return newVariables;
};