Home > Back-end >  What is the image:// prefix?
What is the image:// prefix?

Time:10-30

Quote from the Luckysheet source code:

image://css/loading.gif

Is this an image protocol? I've never seen this prefix before, could anyone explain what it is?

CodePudding user response:

No, it's just a prefix used later to differentiate between two types of values:

const luckysheetloadingImage = function (config) {
    if(typeof config.image==="function"){
        return config.image()
    }
    const regE = new RegExp("^(image|path)://");
    const regResult = regE.exec(config.image);
    let imageHtml = '';
    if (regResult !== null) {
        const prefix = regResult[0];
        const type = regResult[1];
        const imageStr = regResult.input.substring(prefix.length);
        switch (type) {
            case "image":
                imageHtml = `<div  style="background-image: url(${imageStr});"></div>`;
                break;

I would probably have used two different attributes instead of encoding information in the string.

  • Related