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

Change double quotes to single quotes #8

Open
piranna opened this issue Jun 28, 2014 · 6 comments
Open

Change double quotes to single quotes #8

piranna opened this issue Jun 28, 2014 · 6 comments

Comments

@piranna
Copy link

piranna commented Jun 28, 2014

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.

@rus0000
Copy link

rus0000 commented Apr 27, 2015

+1

@marcello3d
Copy link
Owner

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.

@jamesmorgan
Copy link

+1 😄

@banyudu
Copy link

banyudu commented Oct 25, 2017

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'" 

@piranna
Copy link
Author

piranna commented Oct 25, 2017

I love 'unicorns' 'and' 'ponies'

I don't like the change that does inside the string of the double quotes...

@banyudu
Copy link

banyudu commented Oct 25, 2017

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:

{ key:"str value with \"double quotes\"" }
---------------
{ key:'str value with "double quotes"' }

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

5 participants