-
Notifications
You must be signed in to change notification settings - Fork 16
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
Change double quotes to single quotes #8
Comments
+1 |
PRs welcome! :-) It'd be even better to switch between single/double based on the string contents to minimize output length, but there are perf considerations to all of this. |
+1 😄 |
Maybe to-single-quotes is a better choice than modifying this module. const toSingleQuotes = require('to-single-quotes');
toSingleQuotes('I love "unicorns" \'and\' "ponies"');
//=> "I love 'unicorns' 'and' 'ponies'" |
I don't like the change that does inside the string of the double quotes... |
It seems to-single-quotes won't modify double quotes inside quotes. So it won't produce a change of the string value. Sample code: const tosource = require('tosource')
const singlequote = require('to-single-quotes')
const obj = {
key: 'str value with "double quotes"',
}
const source = tosource(obj);
console.log(source)
console.log('---------------')
console.log(singlequote(source)) Output is:
|
Standard on Javascript for source code are the single quotes (') instead of the double quote (") to distingish from HTML attributes, and in fact Node.js use single quotes when showing an object on the console. Double quoted strings has the advantage that they can be easily generated with JSON.stringify(), but it should be better to use single quotes and the encode() function or another similar one.
The text was updated successfully, but these errors were encountered: