mirror of
https://github.com/liriliri/eruda.git
synced 2026-04-01 10:18:35 +08:00
Add: Search snippet
This commit is contained in:
118
doc/UTIL_API.md
118
doc/UTIL_API.md
@@ -407,6 +407,79 @@ $test.find('.test').each(function (idx, element)
|
||||
});
|
||||
```
|
||||
|
||||
## Url
|
||||
|
||||
Simple url manipulator.
|
||||
|
||||
### constructor
|
||||
|
||||
|Name |Type |Desc |
|
||||
|---------------------|------|----------|
|
||||
|[url=window.location]|string|Url string|
|
||||
|
||||
### setQuery
|
||||
|
||||
Set query value.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------|-----------|
|
||||
|name |string|Query name |
|
||||
|value |string|Query value|
|
||||
|return|Url |this |
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------|------------|
|
||||
|names |object|query object|
|
||||
|return|Url |this |
|
||||
|
||||
### rmQuery
|
||||
|
||||
Remove query value.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------------|----------|
|
||||
|name |string array|Query name|
|
||||
|return|Url |this |
|
||||
|
||||
### parse
|
||||
|
||||
[static] Parse url into an object.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------|----------|
|
||||
|url |string|Url string|
|
||||
|return|object|Url object|
|
||||
|
||||
### stringify
|
||||
|
||||
[static] Stringify url object into a string.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------|----------|
|
||||
|url |object|Url object|
|
||||
|return|string|Url string|
|
||||
|
||||
An url object contains the following properties:
|
||||
|
||||
|Name |Desc |
|
||||
|--------|--------------------------------------------------------------------------------------|
|
||||
|protocol|The protocol scheme of the URL (e.g. http:) |
|
||||
|slashes |A boolean which indicates whether the protocol is followed by two forward slashes (//)|
|
||||
|auth |Authentication information portion (e.g. username:password) |
|
||||
|hostname|Host name without port number |
|
||||
|port |Optional port number |
|
||||
|pathname|URL path |
|
||||
|query |Parsed object containing query string |
|
||||
|hash |The "fragment" portion of the URL including the pound-sign (#) |
|
||||
|
||||
```javascript
|
||||
var url = new Url('http://example.com:8080?eruda=true');
|
||||
console.log(url.port); // -> '8080'
|
||||
url.query.foo = 'bar';
|
||||
url.rmQuery('eruda');
|
||||
utl.toString(); // -> 'http://example.com:8080/?foo=bar'
|
||||
```
|
||||
|
||||
## allKeys
|
||||
|
||||
Retrieve all the names of object's own and inherited properties.
|
||||
@@ -1174,6 +1247,34 @@ sub(20); // -> 15
|
||||
|
||||
No documentation.
|
||||
|
||||
## query
|
||||
|
||||
Parse and stringify url query strings.
|
||||
|
||||
### parse
|
||||
|
||||
Parse a query string into an object.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------|------------|
|
||||
|str |string|Query string|
|
||||
|return|object|Query object|
|
||||
|
||||
### stringify
|
||||
|
||||
Stringify an object into a query string.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------|------------|
|
||||
|obj |object|Query object|
|
||||
|return|string|Query string|
|
||||
|
||||
```javascript
|
||||
query.parse('foo=bar&eruda=true'); // -> {foo: 'bar', eruda: 'true'}
|
||||
query.stringify({foo: 'bar', eruda: 'true'}); // -> 'foo=bar&eruda=true'
|
||||
query.parse('name=eruda&name=eustia'); // -> {name: ['eruda', 'eustia']}
|
||||
```
|
||||
|
||||
## repeat
|
||||
|
||||
Repeat string n-times.
|
||||
@@ -1225,6 +1326,23 @@ rtrim('_abc_', ['c', '_']); // -> '_ab'
|
||||
|
||||
Create callback based on input value.
|
||||
|
||||
## safeGet
|
||||
|
||||
Get object property, don't throw undefined error.
|
||||
|
||||
|Name |Type |Desc |
|
||||
|------|------------|-------------------------|
|
||||
|obj |object |Object to query |
|
||||
|path |array string|Path of property to get |
|
||||
|return|* |Target value or undefined|
|
||||
|
||||
```javascript
|
||||
var obj = {a: {aa: {aaa: 1}}};
|
||||
safeGet(obj, 'a.aa.aaa'); // -> 1
|
||||
safeGet(obj, ['a', 'aa']); // -> {aaa: 1}
|
||||
safeGet(obj, 'a.b'); // -> undefined
|
||||
```
|
||||
|
||||
## safeStorage
|
||||
|
||||
No documentation.
|
||||
|
||||
Reference in New Issue
Block a user