UNPKG

@cloudinary/url-gen

Version:

Cloudinary URL-Gen SDK ========================= [![Build Status](https://api.travis-ci.com/cloudinary/js-url-gen.svg?branch=master)](https://app.travis-ci.com/github/cloudinary/js-url-gen) ## About The Cloudinary URL-Gen SDK allows you to quickly and eas

44 lines (40 loc) 1.77 kB
'use strict'; var Action = require('./Action-34aa7481.cjs'); var QualifierValue = require('./QualifierValue-e770d619.cjs'); var Qualifier = require('./Qualifier-6633a22f.cjs'); var internalConstants = require('./internalConstants-4e8f184f.cjs'); /** * @description A class that defines a simple effect of the type e_{effectName} * @extends SDK.Action * @memberOf Actions.Effect * @see Visit {@link Actions.Effect|Effect} for an example */ class SimpleEffectAction extends Action.Action { constructor(effectType, level) { super(); this._actionModel = {}; this._actionModel.actionType = internalConstants.EFFECT_MODE_TO_ACTION_TYPE_MAP[effectType] || effectType; const qualifierEffect = this.createEffectQualifier(effectType, level); this.addQualifier(qualifierEffect); } createEffectQualifier(effectType, level) { let qualifierValue; if (level) { qualifierValue = new QualifierValue.QualifierValue([effectType, `${level}`]).setDelimiter(':'); } else { qualifierValue = new QualifierValue.QualifierValue(effectType); } return new Qualifier.Qualifier('e', qualifierValue); } static fromJson(actionModel) { const { actionType, level, strength } = actionModel; const effectType = internalConstants.ACTION_TYPE_TO_EFFECT_MODE_MAP[actionType] || actionType; // We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel]) // This allows the inheriting classes to determine the class to be created // @ts-ignore const result = new this(effectType, level ? level : strength); return result; } } exports.SimpleEffectAction = SimpleEffectAction;