租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
991 B

3 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.formatObjKey = void 0;
  4. function formatObjKey(obj, type, options) {
  5. if (obj === null || typeof obj !== 'object') {
  6. return obj;
  7. }
  8. let o;
  9. if (Array.isArray(obj)) {
  10. o = [];
  11. for (let i = 0; i < obj.length; i++) {
  12. o.push(formatObjKey(obj[i], type, options));
  13. }
  14. }
  15. else {
  16. o = {};
  17. Object.keys(obj).forEach(key => {
  18. o[handelFormat(key, type, options)] = formatObjKey(obj[key], type, options);
  19. });
  20. }
  21. return o;
  22. }
  23. exports.formatObjKey = formatObjKey;
  24. function handelFormat(key, type, options) {
  25. if (options && options.exclude && options.exclude.includes(key))
  26. return key;
  27. if (type === 'firstUpperCase') {
  28. key = key.replace(/^./, (_) => _.toUpperCase());
  29. }
  30. else if (type === 'firstLowerCase') {
  31. key = key.replace(/^./, (_) => _.toLowerCase());
  32. }
  33. return key;
  34. }