[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper function to escape text #16

Open
IlyaSemenov opened this issue Sep 1, 2021 · 2 comments
Open

Helper function to escape text #16

IlyaSemenov opened this issue Sep 1, 2021 · 2 comments

Comments

@IlyaSemenov
Copy link

Imagine I have this template:

const doc = `
Item | Qty | Amount
${item} | ${qty} | ${amount}
`

Now what if item has | or any other special symbol inside? The whole document is broken.

I imagined there would be a helper function like receiptline.escape(mytext) but there isn't one.

@IlyaSemenov IlyaSemenov changed the title Help to escape text Helper function to escape text Sep 1, 2021
@IlyaSemenov
Copy link
Author

Something like:

export function escape(text: string) {
	return text.replaceAll(/[\\|{}\-=~_"`^]/g, "\\$&")
}

@receiptline
Copy link
Owner

Thanks. It worked correctly.
Only one line, good!

I think some users might want to escape only some of the special characters.

It might be better to handle it in the user's program.
Then your code will be helpful for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants