Skip to content

Instantly share code, notes, and snippets.

var isValidUrl = (function() {
var protocols = ["http", "https", "ftp"];
var requireProtocol = false;
var requireTLD = true;
var pattern = new RegExp('^(?!mailto:)(?:(?:' + protocols.join('|') + ')://)' + (requireProtocol ? '' : '?') + '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + (requireTLD ? '' : '?') + ')|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i');
return function(str) {
return (typeof str === "string") && str.length < 2083 && pattern.test(str);
}
}());
location.search.substr(1).split("&").reduce(function(o, pair) {
pair = pair.split("=");
o[pair[0]] = pair[1] && decodeURIComponent(pair[1]);
return o;
}, {});
var require = (function() {
var rComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s))/mg;
var rArguments = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var getArguments = function(fn) {
// https://gist.github.com/thebyrd/6924190
var argNames = fn.toString().replace(rComments,'').match(rArguments)[1];
return argNames ? argNames.split(/,/) : [];
};
return function(dependencies, fn) {
var path = require('path');
var fs = require('fs');
var cheerio = require('cheerio');
var createTemplate = function(id, markup) {
var $ = cheerio.load('<script type="text/ng-template"></script>');
$('script').attr('id', id).html(markup).html();
return $.html();
};
@robozevel
robozevel / generateLink.middleware.js
Created April 2, 2015 09:06
Express middleware method to generate a link
function create(proto, obj) {
var descriptor = {};
Object.keys(Object(obj)).forEach(function(prop) {
descriptor[prop] = Object.getOwnPropertyDescriptor(obj, prop);
});
return Object.create(proto || null, descriptor);
}
var exec = require('child_process').exec;
var rForbidden = /(["'#&;`\|\*\?~<>\^\(\)\[\]\{\}\$\\\x0A\xFF])/g;
var isWindows = process.platform === 'win32';
module.exports = function(cmd, options, callback) {
cmd = cmd.replace(rForbidden, isWindows ? '^$1': '\\$1');
return exec(cmd, options, callback);
};
var Promise = require('bluebird');
var fs = require('fs');
var noop = function(){};
var DEFAULT_TIMEOUT = 60 * 2 * 1000;
module.exports = function watch(fileName, until, timeout) {
var watcher;
if (typeof until !== 'function') until = noop;
timeout = Number(timeout) || DEFAULT_TIMEOUT;
(function() {
let props = $$('*')
.filter(x => Object.keys(x.dataset).length)
.reduce((o,x) => {
Object.keys(x.dataset).forEach(key => {
o[key] = key.replace(/[A-Z]/g, y => '-' + y.toLowerCase());
});
return o;
}, {});
module.exports = {
name: 'StarRating',
functional: true,
props: {
stars: {
type: Number,
default: 0
},
tag: {
type: String,