|
| 1 | +import Expression from './expression'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Represents a transformation condition. |
| 5 | + * @param {string} conditionStr - a condition in string format |
| 6 | + * @class Condition |
| 7 | + * @example |
| 8 | + * // normally this class is not instantiated directly |
| 9 | + * var tr = cloudinary.Transformation.new() |
| 10 | + * .if().width( ">", 1000).and().aspectRatio("<", "3:4").then() |
| 11 | + * .width(1000) |
| 12 | + * .crop("scale") |
| 13 | + * .else() |
| 14 | + * .width(500) |
| 15 | + * .crop("scale") |
| 16 | + * |
| 17 | + * var tr = cloudinary.Transformation.new() |
| 18 | + * .if("w > 1000 and aspectRatio < 3:4") |
| 19 | + * .width(1000) |
| 20 | + * .crop("scale") |
| 21 | + * .else() |
| 22 | + * .width(500) |
| 23 | + * .crop("scale") |
| 24 | + * |
| 25 | + */ |
| 26 | +class Condition extends Expression { |
| 27 | + constructor(conditionStr:string) { |
| 28 | + super(conditionStr); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @function Condition#height |
| 33 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 34 | + * @param {string|number} value the right hand side value |
| 35 | + * @return {Condition} this condition |
| 36 | + */ |
| 37 | + height(operator: string, value: string|number) { |
| 38 | + return this.predicate("h", operator, value); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @function Condition#width |
| 43 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 44 | + * @param {string|number} value the right hand side value |
| 45 | + * @return {Condition} this condition |
| 46 | + */ |
| 47 | + width(operator: string, value: string|number) { |
| 48 | + return this.predicate("w", operator, value); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @function Condition#aspectRatio |
| 53 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 54 | + * @param {string|number} value the right hand side value |
| 55 | + * @return {Condition} this condition |
| 56 | + */ |
| 57 | + aspectRatio(operator: string, value: string|number) { |
| 58 | + return this.predicate("ar", operator, value); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @function Condition#pages |
| 63 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 64 | + * @param {string|number} value the right hand side value |
| 65 | + * @return {Condition} this condition |
| 66 | + */ |
| 67 | + pageCount(operator: string, value: string|number) { |
| 68 | + return this.predicate("pc", operator, value); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @function Condition#faces |
| 73 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 74 | + * @param {string|number} value the right hand side value |
| 75 | + * @return {Condition} this condition |
| 76 | + */ |
| 77 | + faceCount(operator: string, value: string|number) { |
| 78 | + return this.predicate("fc", operator, value); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @function Condition#duration |
| 83 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 84 | + * @param {string|number} value the right hand side value |
| 85 | + * @return {Condition} this condition |
| 86 | + */ |
| 87 | + duration(operator: string, value: string|number) { |
| 88 | + return this.predicate("du", operator, value); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * @function Condition#initialDuration |
| 93 | + * @param {string} operator the comparison operator (e.g. "<", "lt") |
| 94 | + * @param {string|number} value the right hand side value |
| 95 | + * @return {Condition} this condition |
| 96 | + */ |
| 97 | + initialDuration(operator: string, value: string|number) { |
| 98 | + return this.predicate("idu", operator, value); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +export default Condition; |
0 commit comments