slash-command-parser.ts 560 B

1234567891011121314151617
  1. import { GrowiCommand } from '../interfaces/growi-command';
  2. import { InvalidGrowiCommandError } from '../models/errors';
  3. export const parseSlashCommand = (slashCommand:{[key:string]:string}): GrowiCommand => {
  4. const trimmedText = slashCommand.text.trim();
  5. const splitted = trimmedText.split(' ');
  6. if (splitted[0] === '') {
  7. throw new InvalidGrowiCommandError('The SlashCommand.text does not specify GrowiCommand type');
  8. }
  9. return {
  10. text: slashCommand.text,
  11. growiCommandType: splitted[0],
  12. growiCommandArgs: splitted.slice(1),
  13. };
  14. };