diff --git a/lib-es5/utils/consts.js b/lib-es5/utils/consts.js index 110bc99e..f56ffaa1 100644 --- a/lib-es5/utils/consts.js +++ b/lib-es5/utils/consts.js @@ -24,7 +24,8 @@ var CONDITIONAL_OPERATORS = { "*": "mul", "/": "div", "+": "add", - "-": "sub" + "-": "sub", + "^": "pow" }; var SIMPLE_PARAMS = [["audio_codec", "ac"], ["audio_frequency", "af"], ["bit_rate", 'br'], ["color_space", "cs"], ["default_image", "d"], ["delay", "dl"], ["density", "dn"], ["duration", "du"], ["end_offset", "eo"], ["fetch_format", "f"], ["gravity", "g"], ["page", "pg"], ["prefix", "p"], ["start_offset", "so"], ["streaming_profile", "sp"], ["video_codec", "vc"], ["video_sampling", "vs"]]; diff --git a/lib-es5/utils/index.js b/lib-es5/utils/index.js index 30093fc3..f8f5d1e2 100644 --- a/lib-es5/utils/index.js +++ b/lib-es5/utils/index.js @@ -138,7 +138,7 @@ function normalize_expression(expression) { return expression; } - var operators = "\\|\\||>=|<=|&&|!=|>|=|<|/|-|\\+|\\*"; + var operators = "\\|\\||>=|<=|&&|!=|>|=|<|/|-|\\^|\\+|\\*"; var operatorsPattern = "((" + operators + ")(?=[ _]))"; var operatorsReplaceRE = new RegExp(operatorsPattern, "g"); expression = expression.replace(operatorsReplaceRE, function (match) { diff --git a/lib/utils/consts.js b/lib/utils/consts.js index af95ca7c..b76bf565 100644 --- a/lib/utils/consts.js +++ b/lib/utils/consts.js @@ -23,6 +23,7 @@ const CONDITIONAL_OPERATORS = { "/": "div", "+": "add", "-": "sub", + "^": "pow", }; let SIMPLE_PARAMS = [ diff --git a/lib/utils/index.js b/lib/utils/index.js index 0d0f6daa..8cdab4a3 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -128,7 +128,7 @@ function normalize_expression(expression) { return expression; } - const operators = "\\|\\||>=|<=|&&|!=|>|=|<|/|-|\\+|\\*"; + const operators = "\\|\\||>=|<=|&&|!=|>|=|<|/|-|\\^|\\+|\\*"; const operatorsPattern = "((" + operators + ")(?=[ _]))"; const operatorsReplaceRE = new RegExp(operatorsPattern, "g"); expression = expression.replace(operatorsReplaceRE, match => CONDITIONAL_OPERATORS[match]); diff --git a/test/utils_spec.js b/test/utils_spec.js index 2b38de7f..d59c7c18 100644 --- a/test/utils_spec.js +++ b/test/utils_spec.js @@ -1084,6 +1084,19 @@ describe("utils", function () { }, }, `http://res.cloudinary.com/${cloud_name}/image/upload/c_scale,l_text:Arial_18:$(start)Hello%20$(name)$(ext)%252C%20%24%28no%20%29%20%24%28%20no%29$(end)/sample`, {}); }); + it("should support power operator", function () { + var options, t; + options = { + transformation: [ + { + $small: 150, + $big: "$small ^ 1.5", + }, + ], + }; + t = cloudinary.utils.generate_transformation_string(options); + expect(t).to.eql("$big_$small_pow_1.5,$small_150"); + }); }); describe("text", function () { var text_encoded, text_layer;