Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active March 25, 2021 03:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/9973862 to your computer and use it in GitHub Desktop.
Save cowboy/9973862 to your computer and use it in GitHub Desktop.
JavaScript console helpers: a few functions I use here or there in the console
// simplify testing things like regexes
function eqs() {
var a = [].slice.call(arguments);
var fn = a.pop();
var i, actual;
for (i = 0; i < a.length; i += 2) {
actual = fn(a[i]);
if (actual !== a[i+1]) {
console.error('"%s" !== "%s" (%s)', actual, a[i+1], a[i]);
}
}
}
console.log('console helpers loaded | https://gist.github.com/cowboy/9973862');

get the bookmarklet (this link is not actually the bookmarklet)

eqs

simplify testing things like regexes

eqs(
'http://benalman.com/?aaa=1&bbb=2#ccc?ddd', 'http://benalman.com/#ccc?ddd',
'http://benalman.com/?aaa=1&bbb=2#ccc', 'http://benalman.com/#ccc',
'http://benalman.com/?#ccc', 'http://benalman.com/#ccc',
'http://benalman.com/#ccc', 'http://benalman.com/#ccc',
'http://benalman.com/?aaa=1&bbb=2#', 'http://benalman.com/#1',
'http://benalman.com/?aaa=1&bbb=2', 'http://benalman.com/',
'http://benalman.com/#', 'http://benalman.com/#',
'http://benalman.com/?', 'http://benalman.com/',
'http://benalman.com/', 'http://benalman.com/1',
function(a) {
  return a.replace(/(\?.*?)(?=#|$)/, '');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment