Add: Search snippet

This commit is contained in:
surunzi
2017-01-01 13:42:26 +08:00
parent dbccb62173
commit a5066f20f7
5 changed files with 593 additions and 80 deletions

View File

@@ -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.