Sha256: 33bd0aa76a436a95f3c9258482d0ac37b4cecd9c7f12c258dec2574d2b0809c8
Contents?: true
Size: 1.62 KB
Versions: 3
Compression:
Stored size: 1.62 KB
Contents
import { get } from './property_get'; /** @module @ember/utils */ /** Verifies that a value is `null` or `undefined`, an empty string, or an empty array. Constrains the rules on `isNone` by returning true for empty strings and empty arrays. If the value is an object with a `size` property of type number, it is used to check emptiness. ```javascript isEmpty(); // true isEmpty(null); // true isEmpty(undefined); // true isEmpty(''); // true isEmpty([]); // true isEmpty({ size: 0}); // true isEmpty({}); // false isEmpty('Adam Hawkins'); // false isEmpty([0,1,2]); // false isEmpty('\n\t'); // false isEmpty(' '); // false isEmpty({ size: 1 }) // false isEmpty({ size: () => 0 }) // false ``` @method isEmpty @static @for @ember/utils @param {Object} obj Value to test @return {Boolean} @public */ export default function isEmpty(obj) { let none = obj === null || obj === undefined; 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; }
Version data entries
3 entries across 3 versions & 1 rubygems