Skip to content

Commit

Permalink
Bump to v1.2.0 and check in dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
hashknot committed Aug 8, 2018
1 parent 6370dc9 commit 9794860
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imgix-core-js",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "https://github.com/imgix/imgix-core-js",
"authors": [
"Kelly Sutton <michael.k.sutton@gmail.com>",
Expand Down
53 changes: 44 additions & 9 deletions dist/imgix-core-js.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define('Imgix', ['exports', 'md5', 'js-base64'], factory);
define('Imgix', ['exports', 'md5', 'js-base64', 'crc'], factory);
} else if (typeof exports !== 'undefined') {
module.exports = factory(exports, require('md5'), require('js-base64').Base64);
module.exports = factory(exports, require('md5'), require('js-base64').Base64, require('crc'));
} else {
var mod = {
exports: {}
};
global.ImgixClient = factory(mod.exports, global.md5, global.Base64);
global.ImgixClient = factory(mod.exports, global.md5, global.Base64, global.crc);
}
})(this, function (exports, _md5, _jsBase64) {
})(this, function (exports, _md5, _jsBase64, _crc) {
var md5 = _md5;
var Base64 = _jsBase64.Base64 || _jsBase64;
var crc = _crc;

var VERSION = '1.1.1';
var VERSION = '1.2.0';
var SHARD_STRATEGY_CRC = 'crc';
var SHARD_STRATEGY_CYCLE = 'cycle';
var DEFAULTS = {
host: null,
domains: [],
useHTTPS: true,
includeLibraryParam: true
includeLibraryParam: true,
shard_strategy: SHARD_STRATEGY_CRC
};

var ImgixClient = (function() {
function ImgixClient(opts) {
var key, val;

this.settings = {};
this._shard_next_index = 0;

for (key in DEFAULTS) {
val = DEFAULTS[key];
Expand All @@ -36,8 +42,24 @@
this.settings[key] = val;
}

if (!this.settings.host) {
throw new Error('ImgixClient must be passed a valid host');
if (!Array.isArray(this.settings.domains)) {
this.settings.domains = [this.settings.domains];
}

if (!this.settings.host && this.settings.domains.length === 0) {
throw new Error('ImgixClient must be passed valid domain(s)');
}

if (this.settings.shard_strategy !== SHARD_STRATEGY_CRC
&& this.settings.shard_strategy !== SHARD_STRATEGY_CYCLE) {
throw new Error('Shard strategy must be one of ' +
SHARD_STRATEGY_CRC + ' or ' + SHARD_STRATEGY_CYCLE);
}

if (this.settings.host) {
console.warn("'host' argument is deprecated; use 'domains' instead.");
if (this.settings.domains.length == 0)
this.settings.domains[0] = this.settings.host;
}

if (this.settings.includeLibraryParam) {
Expand All @@ -59,9 +81,20 @@
queryParams = this._signParams(path, queryParams);
}

return this.settings.urlPrefix + this.settings.host + path + queryParams;
return this.settings.urlPrefix + this._getDomain(path) + path + queryParams;
};

ImgixClient.prototype._getDomain = function(path) {
if (this.settings.shard_strategy === SHARD_STRATEGY_CYCLE) {
var domain = this.settings.domains[this._shard_next_index];
this._shard_next_index = (this._shard_next_index + 1) % this.settings.domains.length;
return domain;
}
else if (this.settings.shard_strategy === SHARD_STRATEGY_CRC) {
return this.settings.domains[crc.crc32(path) % this.settings.domains.length];
}
}

ImgixClient.prototype._sanitizePath = function(path) {
// Strip leading slash first (we'll re-add after encoding)
path = path.replace(/^\//, '');
Expand Down Expand Up @@ -117,6 +150,8 @@
};

ImgixClient.VERSION = VERSION;
ImgixClient.SHARD_STRATEGY_CRC = SHARD_STRATEGY_CRC;
ImgixClient.SHARD_STRATEGY_CYCLE = SHARD_STRATEGY_CYCLE;

return ImgixClient;
})();
Expand Down
2 changes: 1 addition & 1 deletion dist/imgix-core-js.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "imgix-core-js",
"description": "Common boilerplate for all imgix JavaScript-based functionality.",
"version": "1.1.1",
"version": "1.2.0",
"repository": "https://github.com/imgix/imgix-core-js",
"scripts": {
"assert_version": "node assert_version.js",
Expand Down
2 changes: 1 addition & 1 deletion src/imgix-core-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var Base64 = _jsBase64.Base64 || _jsBase64;
var crc = _crc;

var VERSION = '1.1.1';
var VERSION = '1.2.0';
var SHARD_STRATEGY_CRC = 'crc';
var SHARD_STRATEGY_CYCLE = 'cycle';
var DEFAULTS = {
Expand Down

0 comments on commit 9794860

Please sign in to comment.