Closed magicmark closed 1 year ago
fwiw this hack does what I want:
console.log(
dedent`
Foo
${JSON.stringify(JSON.stringify({ a: 'b' }, null, 2))
.replace(/\\"/g, '"')
.replace(/^"/, '')
.replace(/"$/, '')}
Bar
Baz
Qux
`,
);
outputs:
$ node test.js
Foo
{
"a": "b"
}
Bar
Baz
Qux
Interesting! The way template literal string work is by passing an array of strings and then the interpolated values to go in-between them:
const logArgs = (...args) => console.log(args);
logArgs`
Foo
${JSON.stringify({ a: "b" }, null, 2)}
Bar
`;
[
[ '\n Foo\n ', '\n Bar\n' ],
'{\n "a": "b"\n}'
]
I think this is a dup of #12, generally asking to dedent nested strings? Closing as such but please post back if I'm wrong. Thanks!
not sure if this is a bug or somehow expected behaviour that i don't understand yet, but here's a lil repro:
Observations:
Bar
line is not at the same level of indentation as Foo.thanks!