HATEOAS-first backend framework.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

serializers.ts 643 B

1234567891011121314151617181920212223242526272829
  1. export const TEXT_SERIALIZER_PAIR = {
  2. name: 'text/plain',
  3. serialize(obj: unknown, level = 0): string {
  4. if (Array.isArray(obj)) {
  5. return obj.map((o) => this.serialize(o)).join('\n\n');
  6. }
  7. if (typeof obj === 'object') {
  8. if (obj !== null) {
  9. return Object.entries(obj)
  10. .map(([key, value]) => `${Array(level * 2).fill(' ').join('')}${key}: ${this.serialize(value, level + 1)}`)
  11. .join('\n');
  12. }
  13. return '';
  14. }
  15. if (typeof obj === 'number' && Number.isFinite(obj)) {
  16. return obj.toString();
  17. }
  18. if (typeof obj === 'string') {
  19. return obj;
  20. }
  21. return '';
  22. },
  23. deserialize: <T>(str: string) => str as T
  24. };