Skip to content

Commit

Permalink
fix: isempty & 1.1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
halldwang committed Jun 29, 2020
1 parent afc26c9 commit 6a5175e
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 32 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ Then a global variable `bbo` is exposed for the entire library:

[jsDelivr](https://www.jsdelivr.com/package/npm/bbo) & [UNPKG](https://unpkg.com/bbo/)

```js
<script src="https://cdn.jsdelivr.net/npm/bbo"></script>
```

## Building

**node is a dependency, use terminal/iTerm to install it with**
Expand Down
4 changes: 0 additions & 4 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ import storage from 'bbo/storage';

[jsDelivr](https://www.jsdelivr.com/package/npm/bbo) & [UNPKG](https://unpkg.com/bbo/)

```js
<script src="https://cdn.jsdelivr.net/npm/bbo"></script>
```

### 开发

**依赖 nodejs, 请使用 terminal/iTerm 安装环境。**
Expand Down
55 changes: 39 additions & 16 deletions dist/bbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* bbo is a utility library of zero dependencies for javascript.
* (c) 2011 - 2020
* https://github.com/tnfe/bbo.git
* version 1.1.17
* version 1.1.18
*/

(function (global, factory) {
Expand Down Expand Up @@ -96,7 +96,7 @@
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}

var version = '1.1.17';
var version = '1.1.18';

var globalObject = null;

Expand Down Expand Up @@ -844,7 +844,42 @@

var isDate = d => d instanceof Date;

var isEmpty = o => Object.keys(o).length === 0;
function isString(str) {
return getTag(str) === '[object String]';
}

function isMap(map) {
return getTag(map) === '[object Map]';
}

function isSet(set) {
return getTag(set) === '[object Set]';
}

function isEmpty(obj) {
if (obj === null) {
return true;
}

if (isArray(obj)) {
return !obj.length;
}

if (isString(obj)) {
return !obj.length;
}

if (isObject(obj)) {
return !Object.keys(obj).length;
}

if (isMap(obj) || isSet(obj)) {
return !obj.size;
} // other primitive || unidentifed object type


return Object(obj) !== obj || !Object.keys(obj).length;
}

// https://github.com/mattphillips/deep-object-diff

Expand Down Expand Up @@ -1105,10 +1140,6 @@
}
};

function isString(str) {
return getTag(str) === '[object String]';
}

/* eslint-disable no-invalid-this */
/**
* load js
Expand Down Expand Up @@ -2493,14 +2524,6 @@
return !val || !isObject(val) && !isFunction(val);
}

function isMap(map) {
return getTag(map) === '[object Map]';
}

function isSet(set) {
return getTag(set) === '[object Set]';
}

/**
* Gets the size of `collection` by returning its length for array-like
* values or the number of own enumerable string keyed properties for objects.
Expand All @@ -2511,7 +2534,7 @@
*/

function size(collection) {
if (collection === null) {
if (collection === null || collection === undefined) {
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions dist/bbo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bbo.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bbo",
"version": "1.1.17",
"version": "1.1.18",
"description": "bbo is a utility library of zero dependencies for javascript.",
"homepage": "https://tnfe.github.io/bbo",
"author": "halldwang",
Expand Down
2 changes: 1 addition & 1 deletion src/collection/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import isSet from '../lodash/is_set';
* @returns {number} Returns the collection size.
*/
export default function size(collection) {
if (collection === null) {
if (collection === null || collection === undefined) {
return 0;
}
if (isArray(collection) || isString(collection)) {
Expand Down
31 changes: 29 additions & 2 deletions src/lodash/is_empty.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
const isEmpty = (o) => Object.keys(o).length === 0;
import isArray from '../lodash/is_array';
import isString from '../lodash/is_string';
import isObject from '../lodash/is_object';
import isMap from '../lodash/is_map';
import isSet from '../lodash/is_set';

export default isEmpty;
export default function isEmpty(obj) {
if (obj === null) {
return true;
}

if (isArray(obj)) {
return !obj.length;
}

if (isString(obj)) {
return !obj.length;
}

if (isObject(obj)) {
return !Object.keys(obj).length;
}

if (isMap(obj) || isSet(obj)) {
return !obj.size;
}

// other primitive || unidentifed object type
return Object(obj) !== obj || !Object.keys(obj).length;
}
2 changes: 1 addition & 1 deletion src/util/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const version = '1.1.17';
const version = '1.1.18';

export default version;

0 comments on commit 6a5175e

Please sign in to comment.