common.js 401 B

12345678910111213141516171819202122
  1. export function trim (str) {
  2. if (!str) return str
  3. return str.replace(/^\s+|\s+$/g, '')
  4. }
  5. export function toCommaList (arr, key = 'name') {
  6. if (!arr) return
  7. return arr.map(item => item[key]).join(', ')
  8. }
  9. export function shuffle (a) {
  10. let j, x, i
  11. for (i = a.length - 1; i > 0; i--) {
  12. j = Math.floor(Math.random() * (i + 1))
  13. x = a[i]
  14. a[i] = a[j]
  15. a[j] = x
  16. }
  17. return a
  18. }