0

I have a function like this:

export default ({ subDomain }) => `
{
    mutation ${upperCase(subDomain)} {
        ${lowerCase(subDomain)} {
            ok
        }
    }
}
`

However it returns a string that starts with a new line.

I don't want to write it like this:

export default ({ subDomain }) => `{
    mutation ${upperCase(subDomain)} {
        ${lowerCase(subDomain)} {
            ok
        }
    }
}
`

Is there a way to use a tag this template, to get rid of this new line?

Something like:

export default ({ subDomain }) => trim`
{
    mutation ${upperCase(subDomain)} {
        ${lowerCase(subDomain)} {
            ok
        }
    }
}
`
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424

1 Answers1

2

Why not just put .trim() after the template literal?

const fn = (arg) => `
{
    mutation ${arg} {
      ...
    }
}
`.trim();

console.log(fn('abc'));
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320