photon
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,2 +0,2 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.photon=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.photon=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
@@ -7,6 +7,6 @@ /** | ||
var url = _dereq_('url'); | ||
var crc32 = _dereq_('crc32'); | ||
var seed = _dereq_('seed-random'); | ||
var debug = _dereq_('debug')('photon'); | ||
var url = require('url'); | ||
var crc32 = require('crc32'); | ||
var seed = require('seed-random'); | ||
var debug = require('debug')('photon'); | ||
@@ -46,8 +46,4 @@ /** | ||
if (/^https\:/i.test(imageUrl)) { | ||
debug('WARN: `https://` URLs are not supported, standard port 80 access will be attempted'); | ||
} | ||
// strip any leading `http(s)://` | ||
imageUrl = imageUrl.replace(/^https?\:\/\//i, ''); | ||
imageUrl = imageUrl.replace(/^https?\:\/\/(i\d.wp.com\/)?/i, ''); | ||
@@ -103,3 +99,3 @@ // determine which Photon server to connect to: `i0`, `i1`, or `i2`. | ||
},{"crc32":7,"debug":8,"seed-random":9,"url":6}],2:[function(_dereq_,module,exports){ | ||
},{"crc32":7,"debug":8,"seed-random":11,"url":6}],2:[function(require,module,exports){ | ||
(function (global){ | ||
@@ -614,4 +610,4 @@ /*! http://mths.be/punycode v1.2.4 by @mathias */ | ||
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],3:[function(_dereq_,module,exports){ | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}],3:[function(require,module,exports){ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
@@ -702,3 +698,3 @@ // | ||
},{}],4:[function(_dereq_,module,exports){ | ||
},{}],4:[function(require,module,exports){ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
@@ -790,9 +786,9 @@ // | ||
},{}],5:[function(_dereq_,module,exports){ | ||
},{}],5:[function(require,module,exports){ | ||
'use strict'; | ||
exports.decode = exports.parse = _dereq_('./decode'); | ||
exports.encode = exports.stringify = _dereq_('./encode'); | ||
exports.decode = exports.parse = require('./decode'); | ||
exports.encode = exports.stringify = require('./encode'); | ||
},{"./decode":3,"./encode":4}],6:[function(_dereq_,module,exports){ | ||
},{"./decode":3,"./encode":4}],6:[function(require,module,exports){ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
@@ -819,3 +815,3 @@ // | ||
var punycode = _dereq_('punycode'); | ||
var punycode = require('punycode'); | ||
@@ -892,3 +888,3 @@ exports.parse = urlParse; | ||
}, | ||
querystring = _dereq_('querystring'); | ||
querystring = require('querystring'); | ||
@@ -1508,3 +1504,3 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { | ||
},{"punycode":2,"querystring":5}],7:[function(_dereq_,module,exports){ | ||
},{"punycode":2,"querystring":5}],7:[function(require,module,exports){ | ||
(function () { | ||
@@ -1612,104 +1608,314 @@ 'use strict'; | ||
},{}],8:[function(_dereq_,module,exports){ | ||
},{}],8:[function(require,module,exports){ | ||
/** | ||
* This is the web browser implementation of `debug()`. | ||
* | ||
* Expose `debug()` as the module. | ||
*/ | ||
module.exports = debug; | ||
exports = module.exports = require('./debug'); | ||
exports.log = log; | ||
exports.formatArgs = formatArgs; | ||
exports.save = save; | ||
exports.load = load; | ||
exports.useColors = useColors; | ||
/** | ||
* Create a debugger with the given `name`. | ||
* Colors. | ||
*/ | ||
exports.colors = [ | ||
'lightseagreen', | ||
'forestgreen', | ||
'goldenrod', | ||
'dodgerblue', | ||
'darkorchid', | ||
'crimson' | ||
]; | ||
/** | ||
* Currently only WebKit-based Web Inspectors, Firefox >= v31, | ||
* and the Firebug extension (any Firefox version) are known | ||
* to support "%c" CSS customizations. | ||
* | ||
* @param {String} name | ||
* @return {Type} | ||
* TODO: add a `localStorage` variable to explicitly enable/disable colors | ||
*/ | ||
function useColors() { | ||
// is webkit? http://stackoverflow.com/a/16459606/376773 | ||
return ('WebkitAppearance' in document.documentElement.style) || | ||
// is firebug? http://stackoverflow.com/a/398120/376773 | ||
(window.console && (console.firebug || (console.exception && console.table))) || | ||
// is firefox >= v31? | ||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages | ||
(navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31); | ||
} | ||
/** | ||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. | ||
*/ | ||
exports.formatters.j = function(v) { | ||
return JSON.stringify(v); | ||
}; | ||
/** | ||
* Colorize log arguments if enabled. | ||
* | ||
* @api public | ||
*/ | ||
function debug(name) { | ||
if (!debug.enabled(name)) return function(){}; | ||
function formatArgs() { | ||
var args = arguments; | ||
var useColors = this.useColors; | ||
return function(fmt){ | ||
fmt = coerce(fmt); | ||
args[0] = (useColors ? '%c' : '') | ||
+ this.namespace | ||
+ (useColors ? ' %c' : ' ') | ||
+ args[0] | ||
+ (useColors ? '%c ' : ' ') | ||
+ '+' + exports.humanize(this.diff); | ||
var curr = new Date; | ||
var ms = curr - (debug[name] || curr); | ||
debug[name] = curr; | ||
if (!useColors) return args; | ||
fmt = name | ||
+ ' ' | ||
+ fmt | ||
+ ' +' + debug.humanize(ms); | ||
var c = 'color: ' + this.color; | ||
args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1)); | ||
// This hackery is required for IE8 | ||
// where `console.log` doesn't have 'apply' | ||
window.console | ||
&& console.log | ||
&& Function.prototype.apply.call(console.log, console, arguments); | ||
} | ||
// the final "%c" is somewhat tricky, because there could be other | ||
// arguments passed either before or after the %c, so we need to | ||
// figure out the correct index to insert the CSS into | ||
var index = 0; | ||
var lastC = 0; | ||
args[0].replace(/%[a-z%]/g, function(match) { | ||
if ('%%' === match) return; | ||
index++; | ||
if ('%c' === match) { | ||
// we only are interested in the *last* %c | ||
// (the user may have provided their own) | ||
lastC = index; | ||
} | ||
}); | ||
args.splice(lastC, 0, c); | ||
return args; | ||
} | ||
/** | ||
* The currently active debug mode names. | ||
* Invokes `console.log()` when available. | ||
* No-op when `console.log` is not a "function". | ||
* | ||
* @api public | ||
*/ | ||
debug.names = []; | ||
debug.skips = []; | ||
function log() { | ||
// This hackery is required for IE8, | ||
// where the `console.log` function doesn't have 'apply' | ||
return 'object' == typeof console | ||
&& 'function' == typeof console.log | ||
&& Function.prototype.apply.call(console.log, console, arguments); | ||
} | ||
/** | ||
* Enables a debug mode by name. This can include modes | ||
* separated by a colon and wildcards. | ||
* Save `namespaces`. | ||
* | ||
* @param {String} name | ||
* @api public | ||
* @param {String} namespaces | ||
* @api private | ||
*/ | ||
debug.enable = function(name) { | ||
function save(namespaces) { | ||
try { | ||
localStorage.debug = name; | ||
} catch(e){} | ||
if (null == namespaces) { | ||
localStorage.removeItem('debug'); | ||
} else { | ||
localStorage.debug = namespaces; | ||
} | ||
} catch(e) {} | ||
} | ||
var split = (name || '').split(/[\s,]+/) | ||
, len = split.length; | ||
/** | ||
* Load `namespaces`. | ||
* | ||
* @return {String} returns the previously persisted debug modes | ||
* @api private | ||
*/ | ||
for (var i = 0; i < len; i++) { | ||
name = split[i].replace('*', '.*?'); | ||
if (name[0] === '-') { | ||
debug.skips.push(new RegExp('^' + name.substr(1) + '$')); | ||
function load() { | ||
var r; | ||
try { | ||
r = localStorage.debug; | ||
} catch(e) {} | ||
return r; | ||
} | ||
/** | ||
* Enable namespaces listed in `localStorage.debug` initially. | ||
*/ | ||
exports.enable(load()); | ||
},{"./debug":9}],9:[function(require,module,exports){ | ||
/** | ||
* This is the common logic for both the Node.js and web browser | ||
* implementations of `debug()`. | ||
* | ||
* Expose `debug()` as the module. | ||
*/ | ||
exports = module.exports = debug; | ||
exports.coerce = coerce; | ||
exports.disable = disable; | ||
exports.enable = enable; | ||
exports.enabled = enabled; | ||
exports.humanize = require('ms'); | ||
/** | ||
* The currently active debug mode names, and names to skip. | ||
*/ | ||
exports.names = []; | ||
exports.skips = []; | ||
/** | ||
* Map of special "%n" handling functions, for the debug "format" argument. | ||
* | ||
* Valid key names are a single, lowercased letter, i.e. "n". | ||
*/ | ||
exports.formatters = {}; | ||
/** | ||
* Previously assigned color. | ||
*/ | ||
var prevColor = 0; | ||
/** | ||
* Previous log timestamp. | ||
*/ | ||
var prevTime; | ||
/** | ||
* Select a color. | ||
* | ||
* @return {Number} | ||
* @api private | ||
*/ | ||
function selectColor() { | ||
return exports.colors[prevColor++ % exports.colors.length]; | ||
} | ||
/** | ||
* Create a debugger with the given `namespace`. | ||
* | ||
* @param {String} namespace | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
function debug(namespace) { | ||
// define the `disabled` version | ||
function disabled() { | ||
} | ||
disabled.enabled = false; | ||
// define the `enabled` version | ||
function enabled() { | ||
var self = enabled; | ||
// set `diff` timestamp | ||
var curr = +new Date(); | ||
var ms = curr - (prevTime || curr); | ||
self.diff = ms; | ||
self.prev = prevTime; | ||
self.curr = curr; | ||
prevTime = curr; | ||
// add the `color` if not set | ||
if (null == self.useColors) self.useColors = exports.useColors(); | ||
if (null == self.color && self.useColors) self.color = selectColor(); | ||
var args = Array.prototype.slice.call(arguments); | ||
args[0] = exports.coerce(args[0]); | ||
if ('string' !== typeof args[0]) { | ||
// anything else let's inspect with %o | ||
args = ['%o'].concat(args); | ||
} | ||
else { | ||
debug.names.push(new RegExp('^' + name + '$')); | ||
// apply any `formatters` transformations | ||
var index = 0; | ||
args[0] = args[0].replace(/%([a-z%])/g, function(match, format) { | ||
// if we encounter an escaped % then don't increase the array index | ||
if (match === '%%') return match; | ||
index++; | ||
var formatter = exports.formatters[format]; | ||
if ('function' === typeof formatter) { | ||
var val = args[index]; | ||
match = formatter.call(self, val); | ||
// now we need to remove `args[index]` since it's inlined in the `format` | ||
args.splice(index, 1); | ||
index--; | ||
} | ||
return match; | ||
}); | ||
if ('function' === typeof exports.formatArgs) { | ||
args = exports.formatArgs.apply(self, args); | ||
} | ||
var logFn = enabled.log || exports.log || console.log.bind(console); | ||
logFn.apply(self, args); | ||
} | ||
}; | ||
enabled.enabled = true; | ||
var fn = exports.enabled(namespace) ? enabled : disabled; | ||
fn.namespace = namespace; | ||
return fn; | ||
} | ||
/** | ||
* Disable debug output. | ||
* Enables a debug mode by namespaces. This can include modes | ||
* separated by a colon and wildcards. | ||
* | ||
* @param {String} namespaces | ||
* @api public | ||
*/ | ||
debug.disable = function(){ | ||
debug.enable(''); | ||
}; | ||
function enable(namespaces) { | ||
exports.save(namespaces); | ||
var split = (namespaces || '').split(/[\s,]+/); | ||
var len = split.length; | ||
for (var i = 0; i < len; i++) { | ||
if (!split[i]) continue; // ignore empty strings | ||
namespaces = split[i].replace(/\*/g, '.*?'); | ||
if (namespaces[0] === '-') { | ||
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); | ||
} else { | ||
exports.names.push(new RegExp('^' + namespaces + '$')); | ||
} | ||
} | ||
} | ||
/** | ||
* Humanize the given `ms`. | ||
* Disable debug output. | ||
* | ||
* @param {Number} m | ||
* @return {String} | ||
* @api private | ||
* @api public | ||
*/ | ||
debug.humanize = function(ms) { | ||
var sec = 1000 | ||
, min = 60 * 1000 | ||
, hour = 60 * min; | ||
function disable() { | ||
exports.enable(''); | ||
} | ||
if (ms >= hour) return (ms / hour).toFixed(1) + 'h'; | ||
if (ms >= min) return (ms / min).toFixed(1) + 'm'; | ||
if (ms >= sec) return (ms / sec | 0) + 's'; | ||
return ms + 'ms'; | ||
}; | ||
/** | ||
@@ -1723,10 +1929,11 @@ * Returns true if the given mode name is enabled, false otherwise. | ||
debug.enabled = function(name) { | ||
for (var i = 0, len = debug.skips.length; i < len; i++) { | ||
if (debug.skips[i].test(name)) { | ||
function enabled(name) { | ||
var i, len; | ||
for (i = 0, len = exports.skips.length; i < len; i++) { | ||
if (exports.skips[i].test(name)) { | ||
return false; | ||
} | ||
} | ||
for (var i = 0, len = debug.names.length; i < len; i++) { | ||
if (debug.names[i].test(name)) { | ||
for (i = 0, len = exports.names.length; i < len; i++) { | ||
if (exports.names[i].test(name)) { | ||
return true; | ||
@@ -1736,6 +1943,10 @@ } | ||
return false; | ||
}; | ||
} | ||
/** | ||
* Coerce `val`. | ||
* | ||
* @param {Mixed} val | ||
* @return {Mixed} | ||
* @api private | ||
*/ | ||
@@ -1748,9 +1959,116 @@ | ||
// persist | ||
},{"ms":10}],10:[function(require,module,exports){ | ||
/** | ||
* Helpers. | ||
*/ | ||
try { | ||
if (window.localStorage) debug.enable(localStorage.debug); | ||
} catch(e){} | ||
var s = 1000; | ||
var m = s * 60; | ||
var h = m * 60; | ||
var d = h * 24; | ||
var y = d * 365.25; | ||
},{}],9:[function(_dereq_,module,exports){ | ||
/** | ||
* Parse or format the given `val`. | ||
* | ||
* Options: | ||
* | ||
* - `long` verbose formatting [false] | ||
* | ||
* @param {String|Number} val | ||
* @param {Object} options | ||
* @return {String|Number} | ||
* @api public | ||
*/ | ||
module.exports = function(val, options){ | ||
options = options || {}; | ||
if ('string' == typeof val) return parse(val); | ||
return options.long | ||
? long(val) | ||
: short(val); | ||
}; | ||
/** | ||
* Parse the given `str` and return milliseconds. | ||
* | ||
* @param {String} str | ||
* @return {Number} | ||
* @api private | ||
*/ | ||
function parse(str) { | ||
var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str); | ||
if (!match) return; | ||
var n = parseFloat(match[1]); | ||
var type = (match[2] || 'ms').toLowerCase(); | ||
switch (type) { | ||
case 'years': | ||
case 'year': | ||
case 'y': | ||
return n * y; | ||
case 'days': | ||
case 'day': | ||
case 'd': | ||
return n * d; | ||
case 'hours': | ||
case 'hour': | ||
case 'h': | ||
return n * h; | ||
case 'minutes': | ||
case 'minute': | ||
case 'm': | ||
return n * m; | ||
case 'seconds': | ||
case 'second': | ||
case 's': | ||
return n * s; | ||
case 'ms': | ||
return n; | ||
} | ||
} | ||
/** | ||
* Short format for `ms`. | ||
* | ||
* @param {Number} ms | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function short(ms) { | ||
if (ms >= d) return Math.round(ms / d) + 'd'; | ||
if (ms >= h) return Math.round(ms / h) + 'h'; | ||
if (ms >= m) return Math.round(ms / m) + 'm'; | ||
if (ms >= s) return Math.round(ms / s) + 's'; | ||
return ms + 'ms'; | ||
} | ||
/** | ||
* Long format for `ms`. | ||
* | ||
* @param {Number} ms | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function long(ms) { | ||
return plural(ms, d, 'day') | ||
|| plural(ms, h, 'hour') | ||
|| plural(ms, m, 'minute') | ||
|| plural(ms, s, 'second') | ||
|| ms + ' ms'; | ||
} | ||
/** | ||
* Pluralization helper. | ||
*/ | ||
function plural(ms, n, name) { | ||
if (ms < n) return; | ||
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name; | ||
return Math.ceil(ms / n) + ' ' + name + 's'; | ||
} | ||
},{}],11:[function(require,module,exports){ | ||
(function (global){ | ||
@@ -1931,5 +2249,4 @@ 'use strict'; | ||
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}]},{},[1]) | ||
(1) | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}]},{},[1])(1) | ||
}); |
1.0.3 / 2014-12-20 | ||
================== | ||
* fixes photonception issue (#2) | ||
* package: update "browserify" to v6.1.0 | ||
* dist: recompile | ||
1.0.2 / 2014-06-13 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -45,3 +45,3 @@ | ||
// strip any leading `http(s)://` | ||
imageUrl = imageUrl.replace(/^https?\:\/\//i, ''); | ||
imageUrl = imageUrl.replace(/^https?\:\/\/(i\d.wp.com\/)?/i, ''); | ||
@@ -48,0 +48,0 @@ // determine which Photon server to connect to: `i0`, `i1`, or `i2`. |
{ | ||
"name": "photon", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "JavaScript library for the WordPress.com Photon image manipulation service", | ||
@@ -39,5 +39,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"browserify": "4.1.6", | ||
"browserify": "6.1.0", | ||
"mocha": "1.20.0" | ||
} | ||
} |
@@ -21,5 +21,5 @@ | ||
it('should not Photon-ify a Photon URL', function () { | ||
var url = 'https://i1.wp.com/www.gravatar.com/avatar/693307b4e0cb9366f34862c9dfacd7fc'; | ||
var url = 'https://i0.wp.com/www.gravatar.com/avatar/693307b4e0cb9366f34862c9dfacd7fc'; | ||
assert(photon(url) === url); | ||
}); | ||
}); |
71051
2025