esformatter plugin for single/double quotes normalization.
install it:
npm install esformatter-quotes
and add to your esformatter config file:
{
"plugins": [
"esformatter-quotes"
],
"quotes": {
"type": "single",
"avoidEscape": false,
"normalizeObjectKeys": false
}
}
- type:String
- if code should use "single" or "double" quotes.
- avoidEscape:Boolean
true
if you want to avoid escaping quotes when possible.
- normalizeObjectKeys:Boolean
true
if you want to enforce quotes on object keys, too.
// register plugin
esformatter.register(require('esformatter-quotes'));
// pass options as second argument
var output = esformatter.format(str, {
"quotes": {
"type": "single",
"avoidEscape": false,
"normalizeObjectKeys": false
}
});
Given this input program:
var singleQuote = 'single';
var doubleQuote = "double";
var avoidSingle = 'single "quote"';
var avoidDouble = "double 'quote'";
var lorem = "ipsum \"dolor\" sit 'amet'";
var maecennas = 'ipsum \'dolor\' sit "amet"';
Will you get the following output based on the config options:
var singleQuote = 'single';
var doubleQuote = 'double';
var avoidSingle = 'single "quote"';
var avoidDouble = 'double \'quote\'';
var lorem = 'ipsum "dolor" sit \'amet\'';
var maecennas = 'ipsum \'dolor\' sit "amet"';
var singleQuote = 'single';
var doubleQuote = 'double';
var avoidSingle = 'single "quote"';
var avoidDouble = "double 'quote'";
var lorem = 'ipsum "dolor" sit \'amet\'';
var maecennas = 'ipsum \'dolor\' sit "amet"';
var singleQuote = "single";
var doubleQuote = "double";
var avoidSingle = "single \"quote\"";
var avoidDouble = "double 'quote'";
var lorem = "ipsum \"dolor\" sit 'amet'";
var maecennas = "ipsum 'dolor' sit \"amet\"";
var singleQuote = "single";
var doubleQuote = "double";
var avoidSingle = 'single "quote"';
var avoidDouble = "double 'quote'";
var lorem = "ipsum \"dolor\" sit 'amet'";
var maecennas = "ipsum 'dolor' sit \"amet\"";
Given this input program:
var famousQuoteBy = {
'Princess Leia': 'I love you!',
'Han "Shot first" Solo': 'I know!',
Spock: 'Fascinating.',
"Dr. Emmett 'Doc' Brown": '1.21 gigawatts???'
};
var famousQuoteBy = {
'Princess Leia': 'I love you!',
'Han "Shot first" Solo': 'I know!',
'Spock': 'Fascinating.',
'Dr. Emmett \'Doc\' Brown': '1.21 gigawatts???'
};
var famousQuoteBy = {
'Princess Leia': 'I love you!',
'Han "Shot first" Solo': 'I know!',
'Spock': 'Fascinating.',
"Dr. Emmett 'Doc' Brown": '1.21 gigawatts???'
};
var famousQuoteBy = {
"Princess Leia": "I love you!",
"Han \"Shot first\" Solo": "I know!",
"Spock": "Fascinating.",
"Dr. Emmett 'Doc' Brown": "1.21 gigawatts???"
};
var famousQuoteBy = {
"Princess Leia": "I love you!",
'Han "Shot first" Solo': "I know!",
"Spock": "Fascinating.",
"Dr. Emmett 'Doc' Brown": "1.21 gigawatts???"
};
Released under the MIT License.