Node

Node library for performing different image operations.

class GumletURLBuilder {
    constructor() {
        this.scheme = '';
        this.host = '';
        this.port = -1;
        this.path = '';
        this.queryParams = new URLSearchParams();
    }

    setScheme(scheme) {
        this.scheme = scheme;
        return this;
    }

    setHost(host) {
        this.host = host;
        return this;
    }

    setPort(port) {
        this.port = port;
        return this;
    }

    setPath(path) {
        this.path = path;
        return this;
    }

    addQueryParameter(name, value) {
        this.queryParams.append(name, value);
        return this;
    }

    build() {
        let hostString = this.host;
        if (this.port !== -1) {
            hostString += `:${this.port}`;
        }
        const url = new URL(`${this.scheme}://${hostString}${this.path}`);
        url.search = this.queryParams.toString();
        return url.toString();
    }
}

A sample code:

import 'GumletURLBuilder';


const builder = new GumletURLBuilder()
    .setScheme('https')
    .setHost("demo.gumlet.io")
    .setPath("/flower.jpeg")
    .addQueryParameter("width", "250")
    .addQueryParameter("dpr", "2.0")
    .addQueryParameter("overlay", "https://demo.gumlet.io/logo.png");

const url = builder.build();
console.log('Built URL:', url); //output - Built URL: https://demo.gumlet.io/flower.jpeg?overlay=https%3A%2F%2Fdemo.gumlet.io%2Flogo.png&dpr=2.0&width=250