UNPKG

537 BJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow strict
8 * @format
9 */
10
11'use strict';
12
13/**
14 * Mimics empty from PHP.
15 */
16function isEmpty(obj: mixed): boolean {
17 if (Array.isArray(obj)) {
18 return obj.length === 0;
19 } else if (typeof obj === 'object') {
20 for (const i in obj) {
21 return false;
22 }
23 return true;
24 } else {
25 return !obj;
26 }
27}
28
29module.exports = isEmpty;