refactor: console stringify

This commit is contained in:
redhoodsu
2019-08-04 15:32:05 +08:00
parent ebf0c2adf8
commit d5f2b5d303
12 changed files with 1802 additions and 666 deletions

View File

@@ -1076,6 +1076,20 @@ if (detectOs() === 'ios') {
}
```
## difference
Create an array of unique array values not included in the other given array.
|Name |Type |Desc |
|---------|-----|----------------------------|
|arr |array|Array to inspect |
|[...rest]|array|Values to exclude |
|return |array|New array of filtered values|
```javascript
difference([3, 2, 1], [4, 2]); // -> [3, 1]
```
## each
Iterate over elements of collection and invokes iterator for each element.
@@ -1215,6 +1229,19 @@ filter([1, 2, 3, 4, 5], function (val) {
}); // -> [2, 4]
```
## flatten
Recursively flatten an array.
|Name |Type |Desc |
|------|-----|-------------------|
|arr |array|Array to flatten |
|return|array|New flattened array|
```javascript
flatten(['a', ['b', ['c']], 'd', ['e']]); // -> ['a', 'b', 'c', 'd', 'e']
```
## freeze
Shortcut for Object.freeze.
@@ -1602,6 +1629,20 @@ isObj({}); // -> true
isObj([]); // -> true
```
## isPromise
Check if value looks like a promise.
|Name |Type |Desc |
|------|-------|----------------------------------|
|val |* |Value to check |
|return|boolean|True if value looks like a promise|
```javascript
isPromise(new Promise(function () {})); // -> true
isPromise({}); // -> false
```
## isRegExp
Check if value is a regular expression.
@@ -2219,6 +2260,32 @@ obj.b = obj;
stringify(obj); // -> '{"a":1,"b":"[Circular ~]"}'
```
## stringifyAll
Stringify object into json with types.
|Name |Type |Desc |
|---------|------|-------------------|
|obj |* |Object to stringify|
|[options]|object|Stringify options |
|return |string|Stringified object |
Available options:
|Name |Type |Desc |
|------------------|-------|-------------------------|
|unenumerable=false|boolean|Include unenumerable keys|
|symbol=false |boolean|Include symbol keys |
|accessGetter=false|boolean|Access getter value |
|timeout=0 |number |Timeout of stringify |
|depth=0 |number |Max depth of recursion |
When time is out, all remaining values will all be "Timeout".
```javascript
stringifyAll(function test() {}); // -> '{"value":"function test() {}","type":"Function",...}'
```
## stripHtmlTag
Strip html tags from a string.