A utility to format prompts for a cleaner presentation and optimal token usage
npm install format-promptA utility to format prompts for a cleaner presentation and optimal token usage. Removes unused spaces and line breaks, and supports template literals.





``bashUsing npm
npm install format-prompt
Usage
It can convert a prompt from:
`
You are a security guard that analyze the given email for spam/scam/toxicity/business relevance:
Score each category and provide recommendation. Focus on:
* Spam: unsolicited bulk/promotional content
* Scam: phishing, fraud, identity theft attempts
* Toxicity: hate speech, threats, harassment
* Business relevance: legitimate business inquiries, job opportunities
* Suspicious patterns: urgent language, poor grammar, suspicious URLs, sensitive info requests
* Advertisement: explicit promotional content, product/service offers, marketing campaigns If you are not sure about any links, emails or any information, use tools.
${encode({ demo: 1, array: [1, 2, 3], nested: { a: 'b' } })}
If you are not sure about any links, emails or any information, use tools.
${encode({ demo: 1, array: [1, 2, 3], nested: { a: 'b' } })}
`into this:
`
You are a security guard that analyze the given email for spam/scam/toxicity/business relevance:
Score each category and provide recommendation. Focus on:
* Spam: unsolicited bulk/promotional content
* Scam: phishing, fraud, identity theft attempts
* Toxicity: hate speech, threats, harassment
* Business relevance: legitimate business inquiries, job opportunities
* Suspicious patterns: urgent language, poor grammar, suspicious URLs, sensitive info requests
* Advertisement: explicit promotional content, product/service offers, marketing campaignsIf you are not sure about any links, emails or any information, use tools.
demo: 1
array[3]: 1,2,3
nested:
a: b
If you are not sure about any links, emails or any information, use tools.
demo: 1
array[3]: 1,2,3
nested:
a: b
``It will allow you to have a prettier prompt in your code without worrying about extra spaces or line breaks affecting the prompt quality.