"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("uuid");
class CommUtils {
    /**
     * 是否Node客户端
     */
    static isNodeClient() {
        return typeof window === 'undefined';
    }
    /**
     * 是否K8S客户端
     */
    static isK8SClient() {
        return this.isNotEmpty(process.env.KT_K8S_ID);
    }
    /**
    * K8S环境变量中的网关地址，注册中心部署中台服务时写入该环境变量
    */
    static getGatewayUrl() {
        return this.isK8SClient() ? process.env.KT_K8S_GATEWAY_URL : "";
    }
    /**
     * 获取IP地址
     */
    static getLocalIP() {
        if (!this.isNodeClient()) {
            return '127.0.0.1';
        }
        const interfaces = require('os').networkInterfaces();
        for (const devName in interfaces) {
            const iface = interfaces[devName];
            for (let i = 0; i < iface.length; i++) {
                const alias = iface[i];
                if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                    return alias.address;
                }
            }
        }
        return "127.0.0.1";
    }
    /**
     * 判断字符串是否为空
     * @param str
     */
    static isEmpty(str) {
        return !str || str.toString().trim() == 0;
    }
    static isNotEmpty(str) {
        return !this.isEmpty(str);
    }
    static leftStrEx(text, splitStr) {
        const iPos = text.lastIndexOf(splitStr);
        if (iPos >= 0)
            return text.substring(0, iPos);
        else
            return text;
    }
    static rightStr(text, splitStr) {
        const iPos = text.lastIndexOf(splitStr);
        if (iPos >= 0) {
            return text.substring(iPos + splitStr.length);
        }
        else {
            return text;
        }
    }
    static uuid() {
        return uuid_1.v4().replace(/-/g, '');
    }
}
exports.CommUtils = CommUtils;
