26 lines
725 B
TypeScript
26 lines
725 B
TypeScript
|
|
import { getDynamicBindings } from "../../utils/DynamicBindingUtils";
|
||
|
|
|
||
|
|
export const stringToJS = (string: string): string => {
|
||
|
|
const { jsSnippets, stringSegments } = getDynamicBindings(string);
|
||
|
|
return stringSegments
|
||
|
|
.map((segment, index) => {
|
||
|
|
if (jsSnippets[index] && jsSnippets[index].length > 0) {
|
||
|
|
return jsSnippets[index];
|
||
|
|
} else {
|
||
|
|
return `'${segment}'`;
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.join(" + ");
|
||
|
|
};
|
||
|
|
|
||
|
|
export const JSToString = (js: string): string => {
|
||
|
|
const segments = js.split(" + ");
|
||
|
|
return segments
|
||
|
|
.map((segment) => {
|
||
|
|
if (segment.charAt(0) === "'") {
|
||
|
|
return segment.substring(1, segment.length - 1);
|
||
|
|
} else return "{{" + segment + "}}";
|
||
|
|
})
|
||
|
|
.join("");
|
||
|
|
};
|