@nitrogenbuilder/client-core
Version:
Nitrogen Builder Core Client
45 lines (39 loc) • 976 B
text/typescript
import type { Prop } from '@nitrogenbuilder/types';
export function getDefault(prop: any, propV: Prop) {
const def = propV.default ?? '';
if (def === undefined || def === null || def === '') {
return prop;
}
if (prop === undefined || prop === null) {
return def;
}
if (typeof prop === 'object') {
if (typeof def === 'object') {
if (propV.responsive) {
if ('mobile' in prop) {
return { ...prop };
}
let returnObject: any = {};
if ('mobile' in def) {
returnObject.mobile = def.mobile;
}
if ('tablet' in prop) {
return { ...returnObject, ...prop };
}
if ('tablet' in def) {
returnObject.tablet = def.tablet;
}
if ('laptop' in prop) {
return { ...returnObject, ...prop };
}
}
return { ...def, ...prop };
}
throw new Error(
"Default value should be responsive, but it ain't bruh. " +
JSON.stringify(prop, null, 2) +
JSON.stringify(propV, null, 2)
);
}
return prop;
}