WILDAN_IZZUDIN

[JS] SIZE LIMITATION FROM STRING

Jul 27th, 2021 (edited)
153
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**    
  2.     * @param {String} size
  3.     * @param {Array} ignore [2, 3, ..., 9] (from 2 until 9)
  4. **/
  5.  
  6. const overSize = (str, ignore = []) => {
  7.     if(str.match('GB') || str.match('TB')) return data = { oversize: true }
  8.     if(str.match('MB')) {
  9.         let first = (str.split('.')[0].replace(/MB/g, '')).trim()
  10.         let max = ignore.some(v => first.startsWith(v))
  11.         if(isNaN(first)) return data = { oversize: true }
  12.         if(first.length > 1 && max) return data = { oversize: true }
  13.         if(first.length > 2) return data = { oversize: true }
  14.             return data = { oversize: false }
  15.     } else {
  16.             return data = { oversize: false }
  17.     }
  18. }
  19.  
  20. // Example :
  21. let size = '50 MB' // size
  22. let v = overSize(size, [6, 7, 8, 9]) // max size less than 60mb and allow 59mb
  23. console.log(v) // { oversize: false }
RAW Paste Data