initial: bootstrap from BukidBountyApp base
This commit is contained in:
32
resources/js/utils/object.js
Normal file
32
resources/js/utils/object.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Checks whether an object has only empty values.
|
||||
*
|
||||
* Empty values:
|
||||
* - undefined
|
||||
* - null
|
||||
* - empty string
|
||||
* - empty array
|
||||
* - empty object
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @returns {boolean}
|
||||
*
|
||||
* @example
|
||||
* isObjectEmpty({}) // true
|
||||
* isObjectEmpty({ a: '' }) // true
|
||||
* isObjectEmpty({ a: [] }) // true
|
||||
* isObjectEmpty({ a: {} }) // true
|
||||
* isObjectEmpty({ a: 1 }) // false
|
||||
*/
|
||||
export function isObjectEmpty(obj) {
|
||||
if (obj === null || typeof obj !== 'object' || Array.isArray(obj)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return Object.values(obj).every(value => {
|
||||
if (value === undefined || value === null || value === '') return true
|
||||
if (Array.isArray(value)) return value.length === 0
|
||||
if (typeof value === 'object') return Object.keys(value).length === 0
|
||||
return false
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user