utils.ts 500 B

123456789101112131415161718192021
  1. import { type BodyPayload, BodyPayloadValueType } from './types'
  2. export const transformToBodyPayload = (old: string, hasKey: boolean): BodyPayload => {
  3. if (!hasKey) {
  4. return [
  5. {
  6. type: BodyPayloadValueType.text,
  7. value: old,
  8. },
  9. ]
  10. }
  11. const bodyPayload = old.split('\n').map((item) => {
  12. const [key, value] = item.split(':')
  13. return {
  14. key: key || '',
  15. type: BodyPayloadValueType.text,
  16. value: value || '',
  17. }
  18. })
  19. return bodyPayload
  20. }