2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 18:08:51 +00:00
the-guard-bot/utils/cmd/stringify.js

22 lines
563 B
JavaScript
Raw Normal View History

'use strict';
2023-03-08 14:08:57 +01:00
const camelToSnake = (s) => s.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase());
exports.stringify = ({ command = '', flags = {}, reason = '' }) => {
const flagS = Object.entries(flags)
2023-03-08 14:08:57 +01:00
.flatMap(([key, value]) => {
switch (value) {
2023-03-08 14:08:57 +01:00
case null:
case false:
case undefined: // eslint-disable-line no-undefined
return [];
case true:
return ['-' + camelToSnake(key)];
default:
return [`-${camelToSnake(key)}=${value}`];
}
2023-03-08 14:08:57 +01:00
})
.join(' ');
return ['/' + command, flagS, reason].filter(Boolean).join(' ');
};