class NewJquery {
    constructor(obj = '') {
        this['obj'] = obj;
        this['allNode'] = [];
        switch (this['obj'].charAt(0)) {
            case '#':
                this['allNode'].push(document.getElementById(this['obj'].substring(1)));
                break;
            case '.':
                this['myObj'] = document.getElementsByClassName(this['obj'].substring(1));
                for (let i = 0; i < this['myObj'].length; i++) {
                    this['allNode'].push(this['myObj'][i]);
                }
                break;
        }
    }

    addClass(myClass) {
        for (let i = 0; i < this['allNode'].length; i++) {
            this['allNode'][i].classList.add(myClass);
        }
    }

    removeClass(myClass) {
        for (let i = 0; i < this['allNode'].length; i++) {
            this['allNode'][i].classList.remove(myClass);
        }
    }

    css(json) {
        for (let i = 0; i < this['allNode'].length; i++) {
            for (let j in json) {
                this['allNode'][i]['style'][j] = json[j];
            }
        }
    }

    width() {
        return this['allNode'][0].clientWidth;
    }

    height() {
        return this['allNode'][0].clientWidth;
    }

    parent() {
        return this['allNode'][0].parentNode;
    }
}

function isJsonString(str) {
    try {
        if (typeof JSON.parse(str) == "object") {
            return true;
        }
    } catch (e) {

    }
    return false;
}

function $(obj) {
    return new NewJquery(obj);
}

export default $;