UNPKG

gmail-mbox-stats

Version:
53 lines (52 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mboxFilePath = exports.myEmail = exports.isMaybeCorrectNotationOfAddress = exports.getEnvItemValue = void 0; const getEnvItemValue = (name) => { const allEnvItems = process.argv; for (const item of allEnvItems) { const nameAndVal = item.split("="); const theKey = nameAndVal[0]; if (theKey === name) { // we have the key. now let's find value. if (nameAndVal.length === 1) { return true; } if (nameAndVal.length !== 2) { throw new Error(`argument notation probably is not correct >>>${item}<<<`); } // now, nameAndVal.length is exactly 2 const theValue = nameAndVal[1]; if (theValue && typeof theValue === "string") { return theValue; } else { throw new Error(`argument notation probably is not correct >>>${item}<<<`); } } } return undefined; }; exports.getEnvItemValue = getEnvItemValue; const isMaybeCorrectNotationOfAddress = (notation) => { const indexOfTheAtSymbol = notation.indexOf("@"); const theAtSymbolIsAtCorrectIndex = indexOfTheAtSymbol >= 1 && indexOfTheAtSymbol <= notation.length - 3; if (!theAtSymbolIsAtCorrectIndex) { return false; } return true; }; exports.isMaybeCorrectNotationOfAddress = isMaybeCorrectNotationOfAddress; const argNameForMyEmailAddress = "mymail"; // main input !!! const argNameForMboxFilePath = "mboxpath"; // main input !!! // export const myEmail = "leodevbro@gmail.com"; const myEmailRaw = (0, exports.getEnvItemValue)(argNameForMyEmailAddress); if (!myEmailRaw || typeof myEmailRaw !== "string" || !(0, exports.isMaybeCorrectNotationOfAddress)(myEmailRaw)) { throw new Error(`mymail notation is not valid --- ${myEmailRaw}`); } exports.myEmail = myEmailRaw.toLowerCase(); exports.mboxFilePath = (0, exports.getEnvItemValue)(argNameForMboxFilePath); if (!exports.mboxFilePath || typeof exports.mboxFilePath !== "string") { throw new Error("mboxpath notation is not valid"); }