* Parse layer options * @private * @param {object|*} layer The layer to parse. * @return {string} layer transformation string
(layer)
| 207 | * @return {string} layer transformation string |
| 208 | */ |
| 209 | function 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); |
no test coverage detected