2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-22 09:57:50 +00:00
the-guard-bot/utils/cmd/stringify.js
Thomas Rory Gummerson 37974a3d92 Updates
2023-03-08 14:08:57 +01:00

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(' ');
};