#

API Docs for: v2.11.1
Show: Inherited Protected Private Deprecated

# File: packages/ember-metal/lib/is_empty.js

    import { get } from './property_get';
    import isNone from './is_none';

    /**
      Verifies that a value is `null` or an empty string, empty array,
      or empty function.

      Constrains the rules on `Ember.isNone` by returning true for empty
      string and empty arrays.

      ```javascript
      Ember.isEmpty();                // true
      Ember.isEmpty(null);            // true
      Ember.isEmpty(undefined);       // true
      Ember.isEmpty('');              // true
      Ember.isEmpty([]);              // true
      Ember.isEmpty({});              // false
      Ember.isEmpty('Adam Hawkins');  // false
      Ember.isEmpty([0,1,2]);         // false
      Ember.isEmpty('\n\t');          // false
      Ember.isEmpty('  ');            // false
      ```

      @method isEmpty
      @for Ember
      @param {Object} obj Value to test
      @return {Boolean}
      @public
    */
    export default function isEmpty(obj) {
      let none = isNone(obj);
      if (none) {
        return none;
      }

      if (typeof obj.size === 'number') {
        return !obj.size;
      }

      let objectType = typeof obj;

      if (objectType === 'object') {
        let size = get(obj, 'size');
        if (typeof size === 'number') {
          return !size;
        }
      }

      if (typeof obj.length === 'number' && objectType !== 'function') {
        return !obj.length;
      }

      if (objectType === 'object') {
        let length = get(obj, 'length');
        if (typeof length === 'number') {
          return !length;
        }
      }

      return false;
    }