mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-22 09:57:50 +00:00
22 lines
563 B
JavaScript
22 lines
563 B
JavaScript
'use strict';
|
|
|
|
const camelToSnake = (s) => s.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase());
|
|
|
|
exports.stringify = ({ command = '', flags = {}, reason = '' }) => {
|
|
const flagS = Object.entries(flags)
|
|
.flatMap(([key, value]) => {
|
|
switch (value) {
|
|
case null:
|
|
case false:
|
|
case undefined: // eslint-disable-line no-undefined
|
|
return [];
|
|
case true:
|
|
return ['-' + camelToSnake(key)];
|
|
default:
|
|
return [`-${camelToSnake(key)}=${value}`];
|
|
}
|
|
})
|
|
.join(' ');
|
|
return ['/' + command, flagS, reason].filter(Boolean).join(' ');
|
|
};
|