WILDAN_IZZUDIN

[JS] SIZE LIMITATION FROM STRING (FIT AND PROPER)

Jul 27th, 2021 (edited)
1,335
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**    
  2.     * @param {String} size
  3.     * @param {Integer} max
  4. **/
  5.  
  6. const overSize = (str, max) => {
  7.     if(str.match('GB') || str.match('TB')) return data = { oversize: true }
  8.     if(str.match('MB')) {
  9.         let first = str.replace(/MB/g, '').trim()
  10.         if(isNaN(first)) return data = { oversize: true }
  11.         if(first > max) return data = { oversize: true }
  12.             return data = { oversize: false }
  13.     } else {
  14.             return data = { oversize: false }
  15.     }
  16. }
  17.  
  18. // Example :
  19. let size = '50.4 MB' // size
  20. let v = overSize(size, 40) // max size is 40mb (fit and proper)
  21. console.log(v) // { oversize: true }
RAW Paste Data