letter.ts 805 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * 将字符串的首字母大写
  3. * @param string
  4. */
  5. function capitalizeFirstLetter(string: string): string {
  6. return string.charAt(0).toUpperCase() + string.slice(1);
  7. }
  8. /**
  9. * 将字符串的首字母转换为小写。
  10. *
  11. * @param str 要转换的字符串
  12. * @returns 首字母小写的字符串
  13. */
  14. function toLowerCaseFirstLetter(str: string): string {
  15. if (!str) return str; // 如果字符串为空,直接返回
  16. return str.charAt(0).toLowerCase() + str.slice(1);
  17. }
  18. /**
  19. * 生成驼峰命名法的键名
  20. * @param key
  21. * @param parentKey
  22. */
  23. function toCamelCase(key: string, parentKey: string): string {
  24. if (!parentKey) {
  25. return key;
  26. }
  27. return parentKey + key.charAt(0).toUpperCase() + key.slice(1);
  28. }
  29. export { capitalizeFirstLetter, toCamelCase, toLowerCaseFirstLetter };