utils.js 984 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. export function createValueSpan( id = null ) {
  2. const span = document.createElement( 'span' );
  3. span.className = 'value';
  4. if ( id !== null ) span.id = id;
  5. return span;
  6. }
  7. export function setText( element, text ) {
  8. const el = element instanceof HTMLElement ? element : document.getElementById( element );
  9. if ( el && el.textContent !== text ) {
  10. el.textContent = text;
  11. }
  12. }
  13. export function getText( element ) {
  14. const el = element instanceof HTMLElement ? element : document.getElementById( element );
  15. return el ? el.textContent : null;
  16. }
  17. export function splitPath( fullPath ) {
  18. const lastSlash = fullPath.lastIndexOf( '/' );
  19. if ( lastSlash === - 1 ) {
  20. return {
  21. path: '',
  22. name: fullPath.trim()
  23. };
  24. }
  25. const path = fullPath.substring( 0, lastSlash ).trim();
  26. const name = fullPath.substring( lastSlash + 1 ).trim();
  27. return { path, name };
  28. }
  29. export function splitCamelCase( str ) {
  30. return str.replace( /([a-z0-9])([A-Z])/g, '$1 $2' ).trim();
  31. }
粤ICP备19079148号