Comparing version 0.0.1 to 0.0.2
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"scripts": { | ||
@@ -16,3 +16,3 @@ "lint": "tslint --project ./tsconfig.json", | ||
"format": "prettier --write './**/*.{ts,tsx,js,json,md}' '.prettierrc'", | ||
"prepublishOnly": "npm run compile" | ||
"prepublishOnly": "npm run test && npm run lint && npm run compile" | ||
}, | ||
@@ -19,0 +19,0 @@ "files": [ |
@@ -6,9 +6,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const funfix_core_1 = require("funfix-core"); | ||
const pickBy_1 = __importDefault(require("lodash/pickBy")); | ||
const isMaybeDefined = (maybeT) => maybeT !== undefined; | ||
exports.catMaybesDictionary = (maybesDictionary) => pickBy_1.default(maybesDictionary, isMaybeDefined); | ||
exports.mapValueIfDefined = (fn) => (maybe) => funfix_core_1.Option.of(maybe) | ||
.map(fn) | ||
.getOrElse(undefined); | ||
var funfix_core_1 = require("funfix-core"); | ||
var pickBy_1 = __importDefault(require("lodash/pickBy")); | ||
var isMaybeDefined = function (maybeT) { return maybeT !== undefined; }; | ||
exports.catMaybesDictionary = function (maybesDictionary) { return pickBy_1.default(maybesDictionary, isMaybeDefined); }; | ||
exports.mapValueIfDefined = function (fn) { return function (maybe) { | ||
return funfix_core_1.Option.of(maybe) | ||
.map(fn) | ||
.getOrElse(undefined); | ||
}; }; | ||
//# sourceMappingURL=maybe.js.map |
@@ -7,6 +7,6 @@ "use strict"; | ||
// tslint:disable-next-line match-default-export-name | ||
const flow_1 = __importDefault(require("lodash/flow")); | ||
const pickBy_1 = __importDefault(require("lodash/pickBy")); | ||
const url_transformers_1 = require("url-transformers"); | ||
const maybe_1 = require("./helpers/maybe"); | ||
var flow_1 = __importDefault(require("lodash/flow")); | ||
var pickBy_1 = __importDefault(require("lodash/pickBy")); | ||
var url_transformers_1 = require("url-transformers"); | ||
var maybe_1 = require("./helpers/maybe"); | ||
// https://docs.imgix.com/apis/url/size/fit | ||
@@ -26,12 +26,12 @@ var ImgixFit; | ||
})(ImgixColorSpace = exports.ImgixColorSpace || (exports.ImgixColorSpace = {})); | ||
const pickTrueInObject = (obj) => pickBy_1.default(obj, value => value === true); | ||
const pickTrueObjectKeys = flow_1.default(pickTrueInObject, | ||
var pickTrueInObject = function (obj) { return pickBy_1.default(obj, function (value) { return value === true; }); }; | ||
var pickTrueObjectKeys = flow_1.default(pickTrueInObject, | ||
// tslint:disable-next-line no-unbound-method | ||
Object.keys); | ||
const undefinedIfEmptyString = (str) => (str === '' ? undefined : str); | ||
const joinWithComma = (strs) => strs.join(','); | ||
const serializeImgixUrlQueryParamListValue = flow_1.default(pickTrueObjectKeys, joinWithComma, undefinedIfEmptyString); | ||
const throwErrorIfNotFinite = (n) => { | ||
if (!Number.isFinite(n)) { | ||
const error = new Error('Expected number to be finite'); | ||
var undefinedIfEmptyString = function (str) { return (str === '' ? undefined : str); }; | ||
var joinWithComma = function (strs) { return strs.join(','); }; | ||
var serializeImgixUrlQueryParamListValue = flow_1.default(pickTrueObjectKeys, joinWithComma, undefinedIfEmptyString); | ||
var throwErrorIfNotFinite = function (n) { | ||
if (!isFinite(n)) { | ||
var error = new Error('Expected number to be finite'); | ||
throw error; | ||
@@ -43,18 +43,22 @@ } | ||
}; | ||
const mapFiniteNumberToStringIfDefined = maybe_1.mapValueIfDefined(flow_1.default(throwErrorIfNotFinite, String)); | ||
const mapToSerializedListValueIfDefined = maybe_1.mapValueIfDefined(serializeImgixUrlQueryParamListValue); | ||
const serializeImgixUrlQueryParamValues = (query) => flow_1.default(() => ({ | ||
dpr: mapFiniteNumberToStringIfDefined(query.dpr), | ||
auto: mapToSerializedListValueIfDefined(query.auto), | ||
fit: query.fit, | ||
w: mapFiniteNumberToStringIfDefined(query.w), | ||
h: mapFiniteNumberToStringIfDefined(query.h), | ||
q: mapFiniteNumberToStringIfDefined(query.q), | ||
cs: query.cs, | ||
crop: mapToSerializedListValueIfDefined(query.crop), | ||
bg: query.bg, | ||
ch: mapToSerializedListValueIfDefined(query.ch), | ||
blur: mapFiniteNumberToStringIfDefined(query.blur), | ||
}), maybe_1.catMaybesDictionary)(); | ||
exports.buildImgixUrl = (url) => flow_1.default(serializeImgixUrlQueryParamValues, query => url_transformers_1.addQueryToUrl({ url })({ queryToAppend: query })); | ||
var mapFiniteNumberToStringIfDefined = maybe_1.mapValueIfDefined(flow_1.default(throwErrorIfNotFinite, String)); | ||
var mapToSerializedListValueIfDefined = maybe_1.mapValueIfDefined(serializeImgixUrlQueryParamListValue); | ||
var serializeImgixUrlQueryParamValues = function (query) { | ||
return flow_1.default(function () { return ({ | ||
dpr: mapFiniteNumberToStringIfDefined(query.dpr), | ||
auto: mapToSerializedListValueIfDefined(query.auto), | ||
fit: query.fit, | ||
w: mapFiniteNumberToStringIfDefined(query.w), | ||
h: mapFiniteNumberToStringIfDefined(query.h), | ||
q: mapFiniteNumberToStringIfDefined(query.q), | ||
cs: query.cs, | ||
crop: mapToSerializedListValueIfDefined(query.crop), | ||
bg: query.bg, | ||
ch: mapToSerializedListValueIfDefined(query.ch), | ||
blur: mapFiniteNumberToStringIfDefined(query.blur), | ||
}); }, maybe_1.catMaybesDictionary)(); | ||
}; | ||
exports.buildImgixUrl = function (url) { | ||
return flow_1.default(serializeImgixUrlQueryParamValues, function (query) { return url_transformers_1.addQueryToUrl({ url: url })({ queryToAppend: query }); }); | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -10,4 +10,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = __importStar(require("assert")); | ||
const index_1 = require("./index"); | ||
var assert = __importStar(require("assert")); | ||
var index_1 = require("./index"); | ||
assert.strictEqual(index_1.buildImgixUrl('https://foo.com')({ | ||
@@ -14,0 +14,0 @@ auto: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9792
127