MCPcopy Create free account
hub / github.com/cloudinary/cloudinary_npm / process_layer

Function process_layer

lib/utils/index.js:209–311  ·  view source on GitHub ↗

* Parse layer options * @private * @param {object|*} layer The layer to parse. * @return {string} layer transformation string

(layer)

Source from the content-addressed store, hash-verified

207 * @return {string} layer transformation string
208 */
209function process_layer(layer) {
210 if (isString(layer)) {
211 let resourceType = null;
212 let layerUrl = '';
213
214 let fetchLayerBegin = 'fetch:';
215 if (layer.startsWith(fetchLayerBegin)) {
216 layerUrl = layer.substring(fetchLayerBegin.length);
217 } else if (layer.indexOf(':fetch:', 0) !== -1) {
218 const parts = layer.split(':', 3);
219 resourceType = parts[0];
220 layerUrl = parts[2];
221 } else {
222 return layer;
223 }
224
225 layer = {
226 url: layerUrl,
227 type: 'fetch'
228 };
229
230 if (resourceType) {
231 layer.resource_type = resourceType;
232 }
233 }
234
235 if (typeof layer !== 'object') {
236 return layer;
237 }
238
239 let {
240 resource_type,
241 text,
242 type,
243 public_id,
244 format,
245 url: fetchUrl
246 } = layer;
247 const components = [];
248
249 if (!isEmpty(text) && isEmpty(resource_type)) {
250 resource_type = 'text';
251 }
252
253 if (!isEmpty(fetchUrl) && isEmpty(type)) {
254 type = 'fetch';
255 }
256
257 if (!isEmpty(public_id) && !isEmpty(format)) {
258 public_id = `${public_id}.${format}`;
259 }
260
261 if (isEmpty(public_id) && resource_type !== 'text' && type !== 'fetch') {
262 throw new Error('Must supply public_id for non-text overlay');
263 }
264
265 if (!isEmpty(resource_type) && resource_type !== 'image') {
266 components.push(resource_type);

Callers 2

Calls 4

textStyleFunction · 0.85
encodeCurlyBracesFunction · 0.85
smart_escapeFunction · 0.85
base64EncodeURLFunction · 0.85

Tested by

no test coverage detected