HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers95/rentman.io/resources/assets/js/createPlan/mixins.js
module.exports = {
    methods: {

        isset(obj) {
            return typeof obj !== 'undefined' && obj !== null;
        },

        displayCorrectCurrency(euro, dollar) {
            return this.getCurrencyIcon() + this.getPrice(euro, dollar);
        },

        getPrice(euro, dollar) {
            let price = (this.$root.currencyEuro) ? euro : dollar;

            if(typeof price === 'string' && price.substr(price.length -3) === '.00') {
                price = price.substr(0, price.length -3)
            }

            return price;
        },

        getCurrencyIcon() {
            return (this.$root.currencyEuro) ? '€' : '$'
        },

        slugify(str) {
            str = str.replace(/^\s+|\s+$/g, ''); // trim
            str = str.toLowerCase();

            // remove accents, swap ñ for n, etc
            var from = "àáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
            var to   = "aaaaaeeeeiiiioooouuuunc------";

            for (var i=0, l=from.length ; i<l ; i++) {
                str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
            }

            str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
                .replace(/\s+/g, '-') // collapse whitespace and replace by -
                .replace(/-+/g, '-'); // collapse dashes

            return str;
        },


        trans(key, replace, returnKey = true) {

            if(!this.isset(this.$root.translations)) {
                console.warn('Create the translation on the window');
                if(returnKey) return key;
                else return '';
            }

            let translation;
            const keys = key.split('.');

            let resolvedKeyCounter = 0;
            while (resolvedKeyCounter < keys.length) {

                // Break if first key isn't resolved
                if(resolvedKeyCounter !== 0 && translation === null) break;

                if(resolvedKeyCounter === 0) translation = this.$root.translations[keys[resolvedKeyCounter]] || null
                else translation = translation[keys[resolvedKeyCounter]] || null;

                resolvedKeyCounter++;
            }

            if (translation === null) {
                if(returnKey) {
                    console.warn('No translation for ' + key + '. Try clearing your session storage.');
                    return key;
                }
                else return '';
            }

            // If we don't need to replace placeholders, return the translation
            if(replace === undefined) return translation;

            const replaceKeys = Object.keys(replace);
            replaceKeys.forEach((key) => {
                translation = translation.replace('%' + key, replace[key]);
            });

            return translation
        },

        log(data) {
            console.log(data);
        }


    },
};