Skip to content

Instantly share code, notes, and snippets.

View dsamarin's full-sized avatar

Devin Samarin dsamarin

View GitHub Profile
@dsamarin
dsamarin / utils.js
Created June 29, 2011 05:23
Quote JavaScript strings
function(value) {
// First we need to find which quote character to use by comparing the
// number of times each occurs in the string.
var quotes_dbl = (value.match(/"/g) || []).length;
var quotes_sgl = (value.match(/'/g) || []).length;
var quote = quotes_sgl <= quotes_dbl ? "'" : '"';
var quote_code = quote.charCodeAt(0);