"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toSlug = toSlug;
exports.buildNamespacedQueueName = buildNamespacedQueueName;
function toSlug(value, joinChar = '-') {
    if (!value) {
        return '';
    }
    const slugChars = [];
    let lastJoin = true;
    for (let i = 0; i < value.length; i += 1) {
        const code = value.charCodeAt(i);
        if (code >= 65 && code <= 90) {
            slugChars.push(String.fromCharCode(code + 32));
            lastJoin = false;
            continue;
        }
        if ((code >= 97 && code <= 122) || (code >= 48 && code <= 57)) {
            slugChars.push(value[i]);
            lastJoin = false;
            continue;
        }
        if (!lastJoin && slugChars.length > 0) {
            slugChars.push(joinChar);
            lastJoin = true;
        }
    }
    if (slugChars.length && slugChars[slugChars.length - 1] === joinChar) {
        slugChars.pop();
    }
    return slugChars.join('');
}
function buildNamespacedQueueName(queueName, appName = process.env.SOLID_APP_NAME, env = process.env.ENV) {
    const appNameSlug = toSlug(appName, '_');
    const envValue = env && env.length > 0 ? env : (process.env.ENV && process.env.ENV.length > 0 ? process.env.ENV : 'dev');
    const envSlug = toSlug(envValue, '_');
    return `${appNameSlug}_${envSlug}_${queueName}`;
}
//# sourceMappingURL=common.js.map