mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-20 09:38:37 +08:00
Add: Resources observer
This commit is contained in:
132
doc/UTIL_API.md
132
doc/UTIL_API.md
@@ -450,6 +450,19 @@ logger.on('debug', function (argList)
|
||||
});
|
||||
```
|
||||
|
||||
## SafeMutationObserver
|
||||
|
||||
Safe MutationObserver, does nothing if MutationObserver is not supported.
|
||||
|
||||
```javascript
|
||||
var observer = new DomObserver(function (mutations)
|
||||
{
|
||||
// Do something.
|
||||
});
|
||||
observer.observe(document.htmlElement);
|
||||
observer.disconnect();
|
||||
```
|
||||
|
||||
## Select
|
||||
|
||||
Simple wrapper of querySelectorAll to make dom selection easier.
|
||||
@@ -711,6 +724,19 @@ Any nested objects or arrays will be copied by reference, not duplicated.
|
||||
clone({name: 'eustia'}); // -> {name: 'eustia'}
|
||||
```
|
||||
|
||||
## concat
|
||||
|
||||
Concat multiple arrays into a single array.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|-----|------------------|
|
||||
|...arr|array|Arrays to concat |
|
||||
|return|array|Concatenated array|
|
||||
|
||||
```javascript
|
||||
concat([1, 2], [3], [4, 5]); // -> [1, 2, 3, 4, 5]
|
||||
```
|
||||
|
||||
## contain
|
||||
|
||||
Check if the value is present in the list.
|
||||
@@ -887,7 +913,7 @@ if (browser.name === 'ie' && browser.version < 9)
|
||||
|
||||
## each
|
||||
|
||||
Iterates over elements of collection and invokes iteratee for each element.
|
||||
Iterate over elements of collection and invokes iteratee for each element.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|--------|------------|------------------------------|
|
||||
@@ -993,6 +1019,24 @@ fileSize(1500000000); // -> '1.4G'
|
||||
fileSize(1500000000000); // -> '1.36T'
|
||||
```
|
||||
|
||||
## filter
|
||||
|
||||
Iterates over elements of collection, returning an array of all the values that pass a truth test.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|---------|--------|---------------------------------------|
|
||||
|obj |array |Collection to iterate over |
|
||||
|predicate|function|Function invoked per iteration |
|
||||
|[ctx] |* |Predicate context |
|
||||
|return |array |Array of all values that pass predicate|
|
||||
|
||||
```javascript
|
||||
filter([1, 2, 3, 4, 5], function (val)
|
||||
{
|
||||
return val % 2 === 0;
|
||||
}); // -> [2, 4]
|
||||
```
|
||||
|
||||
## freeze
|
||||
|
||||
Shortcut for Object.freeze.
|
||||
@@ -1106,6 +1150,20 @@ Check if value is classified as an arguments object.
|
||||
})();
|
||||
```
|
||||
|
||||
## isArr
|
||||
|
||||
Check if value is an `Array` object.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|-------|----------------------------------|
|
||||
|val |* |The value to check |
|
||||
|return|boolean|True if value is an `Array` object|
|
||||
|
||||
```javascript
|
||||
isArr([]); // -> true
|
||||
isArr({}); // -> false
|
||||
```
|
||||
|
||||
## isArrLike
|
||||
|
||||
Check if value is array-like.
|
||||
@@ -1239,6 +1297,19 @@ Check if keys and values in src are contained in obj.
|
||||
isMatch({a: 1, b: 2}, {a: 1}); // -> true
|
||||
```
|
||||
|
||||
## isMobile
|
||||
|
||||
Check whether client is using a mobile browser using ua.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------------------------|-------|-------------------------------------|
|
||||
|[ua=navigator.userAgent]|string |User agent |
|
||||
|return |boolean|True if ua belongs to mobile browsers|
|
||||
|
||||
```javascript
|
||||
isMobile(navigator.userAgent);
|
||||
```
|
||||
|
||||
## isNull
|
||||
|
||||
Check if value is an Null.
|
||||
@@ -1252,6 +1323,21 @@ Check if value is an Null.
|
||||
isNull(null); // -> true
|
||||
```
|
||||
|
||||
## isNum
|
||||
|
||||
Checks if value is classified as a Number primitive or object.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|-------|-------------------------------------|
|
||||
|value |* |Value to check |
|
||||
|return|boolean|True if value is correctly classified|
|
||||
|
||||
```javascript
|
||||
isNum(5); // -> true
|
||||
isNum(5.1); // -> true
|
||||
isNum({}); // -> false
|
||||
```
|
||||
|
||||
## isObj
|
||||
|
||||
Check if value is the language type of Object.
|
||||
@@ -1268,6 +1354,19 @@ isObj({}); // -> true
|
||||
isObj([]); // -> true
|
||||
```
|
||||
|
||||
## isRegExp
|
||||
|
||||
Check if value is a regular expression.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|-------|-------------------------------------|
|
||||
|val |* |Value to check |
|
||||
|return|boolean|True if value is a regular expression|
|
||||
|
||||
```javascript
|
||||
isRegExp(/a/); // -> true
|
||||
```
|
||||
|
||||
## isStr
|
||||
|
||||
Check if value is a string primitive.
|
||||
@@ -1281,6 +1380,20 @@ Check if value is a string primitive.
|
||||
isStr('eris'); // -> true
|
||||
```
|
||||
|
||||
## isUndef
|
||||
|
||||
Check if value is undefined.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|-------|--------------------------|
|
||||
|val |* |Value to check |
|
||||
|return|boolean|True if value is undefined|
|
||||
|
||||
```javascript
|
||||
isUndef(void 0); // -> true
|
||||
isUndef(null); // -> false
|
||||
```
|
||||
|
||||
## kebabCase
|
||||
|
||||
Convert string to "kebabCase".
|
||||
@@ -1416,6 +1529,23 @@ var localStorage = window.localStorage || memStorage;
|
||||
localStorage.setItem('test', 'eris');
|
||||
```
|
||||
|
||||
## memoize
|
||||
|
||||
Memoize a given function by caching the computed result.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|--------|--------|------------------------------------|
|
||||
|fn |function|Function to have its output memoized|
|
||||
|[hashFn]|function|Function to create cache key |
|
||||
|return |function|New memoized function |
|
||||
|
||||
```javascript
|
||||
var fibonacci = memoize(function(n)
|
||||
{
|
||||
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
|
||||
});
|
||||
```
|
||||
|
||||
## meta
|
||||
|
||||
Document meta manipulation, turn name and content into key value pairs.
|
||||
|
||||
Reference in New Issue
Block a user