stringFun.js 646 B

1234567891011121314151617181920212223242526272829
  1. /* eslint-disable */
  2. export const toUpperCase = (str) => {
  3. if (str[0]) {
  4. return str.replace(str[0], str[0].toUpperCase())
  5. } else {
  6. return ''
  7. }
  8. }
  9. export const toLowerCase = (str) => {
  10. if (str[0]) {
  11. return str.replace(str[0], str[0].toLowerCase())
  12. } else {
  13. return ''
  14. }
  15. }
  16. // 驼峰转换下划线
  17. export const toSQLLine = (str) => {
  18. if (str === 'ID') return 'ID'
  19. return str.replace(/([A-Z])/g, "_$1").toLowerCase();
  20. }
  21. // 下划线转换驼峰
  22. export const toHump = (name) => {
  23. return name.replace(/\_(\w)/g, function(all, letter) {
  24. return letter.toUpperCase();
  25. });
  26. }