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

Improve custom style syntax #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 49 additions & 18 deletions log.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
(function() {
var exportedLog, ffSupport, formats, getOrderedMatches, hasMatches, isFF, isIE, isOpera, isSafari, log, makeArray, operaSupport, safariSupport, stringToArgs, _log;
var exportedLog,
ffSupport,
formats,
getOrderedMatches,
hasMatches,
isFF,
isIE,
isOpera,
isSafari,
log,
makeArray,
operaSupport,
safariSupport,
stringToArgs,
_log;

if (!(window.console && window.console.log)) {
return;
Expand All @@ -10,7 +24,7 @@
args = [];
makeArray(arguments).forEach(function(arg) {
if (typeof arg === 'string') {
return args = args.concat(stringToArgs(arg));
return (args = args.concat(stringToArgs(arg)));
} else {
return args.push(arg);
}
Expand All @@ -19,7 +33,11 @@
};

_log = function() {
return Function.prototype.apply.call(console.log, console, makeArray(arguments));
return Function.prototype.apply.call(
console.log,
console,
makeArray(arguments)
);
};

makeArray = function(arrayLikeThing) {
Expand All @@ -30,31 +48,37 @@
{
regex: /\*([^\*]+)\*/,
replacer: function(m, p1) {
return "%c" + p1 + "%c";
return '%c' + p1 + '%c';
},
styles: function() {
return ['font-style: italic', ''];
}
}, {
},
{
regex: /\_([^\_]+)\_/,
replacer: function(m, p1) {
return "%c" + p1 + "%c";
return '%c' + p1 + '%c';
},
styles: function() {
return ['font-weight: bold', ''];
}
}, {
},
{
regex: /\`([^\`]+)\`/,
replacer: function(m, p1) {
return "%c" + p1 + "%c";
return '%c' + p1 + '%c';
},
styles: function() {
return ['background: rgb(255, 255, 219); padding: 1px 5px; border: 1px solid rgba(0, 0, 0, 0.1)', ''];
return [
'background: rgb(255, 255, 219); padding: 1px 5px; border: 1px solid rgba(0, 0, 0, 0.1)',
''
];
}
}, {
regex: /\[c\=(?:\"|\')?((?:(?!(?:\"|\')\]).)*)(?:\"|\')?\]((?:(?!\[c\]).)*)\[c\]/,
},
{
regex: /<style\=(?:\"|\')?((?:(?!(?:\"|\')>).)*)(?:\"|\')?>((?:(?!<\/style>).)*)<\/style>/,
replacer: function(m, p1, p2) {
return "%c" + p2 + "%c";
return '%c' + p2 + '%c';
},
styles: function(match) {
return [match[1], ''];
Expand All @@ -67,7 +91,7 @@
_hasMatches = false;
formats.forEach(function(format) {
if (format.regex.test(str)) {
return _hasMatches = true;
return (_hasMatches = true);
}
});
return _hasMatches;
Expand Down Expand Up @@ -104,7 +128,10 @@
};

isSafari = function() {
return /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
return (
/Safari/.test(navigator.userAgent) &&
/Apple Computer/.test(navigator.vendor)
);
};

isOpera = function() {
Expand All @@ -125,7 +152,7 @@
if (!m) {
return false;
}
return 537.38 <= parseInt(m[1], 10) + (parseInt(m[2], 10) / 100);
return 537.38 <= parseInt(m[1], 10) + parseInt(m[2], 10) / 100;
};

operaSupport = function() {
Expand All @@ -141,7 +168,12 @@
return window.console.firebug || window.console.exception;
};

if (isIE() || (isFF() && !ffSupport()) || (isOpera() && !operaSupport()) || (isSafari() && !safariSupport())) {
if (
isIE() ||
(isFF() && !ffSupport()) ||
(isOpera() && !operaSupport()) ||
(isSafari() && !safariSupport())
) {
exportedLog = _log;
} else {
exportedLog = log;
Expand All @@ -158,5 +190,4 @@
} else {
window.log = exportedLog;
}

}).call(this);
}.call(this));