@enonic/react4xp
Version:
Build tools for React4xp
27 lines (26 loc) • 551 B
text/typescript
export function cleanAnyDoublequotes(
label :string,
val :string
) {
if (typeof val !== 'string') {
return val;
}
if (val.startsWith('"')) {
if (!val.endsWith('"')) {
throw Error(
`Inconsistent double-quote-wrapping on '${label}' value: ${JSON.stringify(
val
)}`
);
}
return val.substring(1, val.length - 1);
}
if (val.endsWith('"')) {
throw Error(
`Inconsistent double-quote-wrapping on '${label}' value: ${JSON.stringify(
val
)}`
);
}
return val;
}