gitsu-cli
Version:
Interactive command line util for quickly & easily switching git users
18 lines (17 loc) • 769 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultChoice = exports.parseChoice = exports.formatChoice = void 0;
const formatChoice = (user) => `${user.name} <${user.email}>`;
exports.formatChoice = formatChoice;
const parseChoice = (choice) => {
const [name, email] = choice.split('<');
return { name: name.trim(), email: email.slice(0, -1).trim() };
};
exports.parseChoice = parseChoice;
const defaultChoice = (users, currentChoice) => {
const firstNotCurrentUser = users.find((user) => (0, exports.formatChoice)(user) !== currentChoice);
if (!firstNotCurrentUser)
return currentChoice;
return `${firstNotCurrentUser.name} <${firstNotCurrentUser.email}>`;
};
exports.defaultChoice = defaultChoice;