url-assembler
Advanced tools
Comparing version
{ | ||
"name": "url-assembler", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Assemble urls from route-like templates (/path/:param)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,2 +18,4 @@ [![Build Status][travis-image]][travis-url] [![Coverage][coveralls-image]][coveralls-url] | ||
#### Basic | ||
```javascript | ||
@@ -31,2 +33,4 @@ UrlAssembler() | ||
#### With base URL | ||
Since you more often than not need a hostname and a protocol to go with this | ||
@@ -44,2 +48,4 @@ | ||
#### Incremental assembling | ||
You can also incrementally build your URL. | ||
@@ -60,2 +66,5 @@ | ||
Design | ||
------ | ||
Every method (except `toString()`) returns a new instance of `UrlAssembler`. You can | ||
@@ -65,5 +74,49 @@ consider that `UrlAssembler` instances are immutable. | ||
In addition, an instance of `UrlAssembler` is a valid object to pass | ||
to `url.format` or any function accepting this kind of object as | ||
to `url.format()` or any function accepting this kind of object as | ||
parameter. | ||
API Reference | ||
------------- | ||
###### `new UrlAssembler([baseUrl])` | ||
- `baseUrl`: will be used for protocol, hostname, port and other base url kind of stuff. | ||
- **returns** an instance of a URL assembler. | ||
###### `.template(template)` | ||
- `template` a *string* with dynamic part noted as `:myparam` . For example `'/hello/:param/world'` | ||
- **returns** a new instance of `UrlAssembler` with this template configured | ||
###### `.prefix(subPath)` | ||
- `subPath` : this *string* will be added at the beginning of the path part of the URL | ||
- if called several times, the subPath will be added after the previous prefix but before the rest of the path | ||
- **returns** a new instance of `UrlAssembler` | ||
###### `.segment(subPathTemplate)` | ||
- `subPathTemplate` is a *string* of a segment to add to the path of the URL. It can have a templatized parameter eg. `'/user/:user'` | ||
- if called several times, the segment will be added at the end of the URL. | ||
- **returns** a new instance of `UrlAssembler` | ||
###### `.param(key, value[, strict])` | ||
- `key`: a *string* of the dynamic part to replace | ||
- `value`: a *string* to replace the dynamic part with | ||
- **returns** a new instance of `UrlAssembler` with the parameter `key` replaced with `value`. If strict is falsy, the key will be added as query parameter. | ||
###### `.param(params[, strict])` | ||
- `params`: a *hash* of key/value to give to the method above | ||
- `strict` a flag passed to the method above | ||
- **returns** a new instance of `UrlAssembler` with all the parameters replaced | ||
###### `.query(key, value)` | ||
- `key`: the name of the parameter to configure | ||
- `value`: the value of the parameter to configure | ||
- **returns** a new instance of `UrlAssembler` with the key=value pair added as query parameter with the `qs` module. | ||
###### `.query(params)` | ||
shortcut for the previous method with a hash of key/value. | ||
###### `.toString()` | ||
- **returns** a *string* of the current state of the `UrlAssembler` instance. Path parameters not yet replaced will appear as `:param_name`. | ||
Test | ||
@@ -70,0 +123,0 @@ ---- |
16723
14.13%149
55.21%