Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[6a3a178] | 1 |
|
---|
| 2 | # delegates
|
---|
| 3 |
|
---|
| 4 | Node method and accessor delegation utilty.
|
---|
| 5 |
|
---|
| 6 | ## Installation
|
---|
| 7 |
|
---|
| 8 | ```
|
---|
| 9 | $ npm install delegates
|
---|
| 10 | ```
|
---|
| 11 |
|
---|
| 12 | ## Example
|
---|
| 13 |
|
---|
| 14 | ```js
|
---|
| 15 | var delegate = require('delegates');
|
---|
| 16 |
|
---|
| 17 | ...
|
---|
| 18 |
|
---|
| 19 | delegate(proto, 'request')
|
---|
| 20 | .method('acceptsLanguages')
|
---|
| 21 | .method('acceptsEncodings')
|
---|
| 22 | .method('acceptsCharsets')
|
---|
| 23 | .method('accepts')
|
---|
| 24 | .method('is')
|
---|
| 25 | .access('querystring')
|
---|
| 26 | .access('idempotent')
|
---|
| 27 | .access('socket')
|
---|
| 28 | .access('length')
|
---|
| 29 | .access('query')
|
---|
| 30 | .access('search')
|
---|
| 31 | .access('status')
|
---|
| 32 | .access('method')
|
---|
| 33 | .access('path')
|
---|
| 34 | .access('body')
|
---|
| 35 | .access('host')
|
---|
| 36 | .access('url')
|
---|
| 37 | .getter('subdomains')
|
---|
| 38 | .getter('protocol')
|
---|
| 39 | .getter('header')
|
---|
| 40 | .getter('stale')
|
---|
| 41 | .getter('fresh')
|
---|
| 42 | .getter('secure')
|
---|
| 43 | .getter('ips')
|
---|
| 44 | .getter('ip')
|
---|
| 45 | ```
|
---|
| 46 |
|
---|
| 47 | # API
|
---|
| 48 |
|
---|
| 49 | ## Delegate(proto, prop)
|
---|
| 50 |
|
---|
| 51 | Creates a delegator instance used to configure using the `prop` on the given
|
---|
| 52 | `proto` object. (which is usually a prototype)
|
---|
| 53 |
|
---|
| 54 | ## Delegate#method(name)
|
---|
| 55 |
|
---|
| 56 | Allows the given method `name` to be accessed on the host.
|
---|
| 57 |
|
---|
| 58 | ## Delegate#getter(name)
|
---|
| 59 |
|
---|
| 60 | Creates a "getter" for the property with the given `name` on the delegated
|
---|
| 61 | object.
|
---|
| 62 |
|
---|
| 63 | ## Delegate#setter(name)
|
---|
| 64 |
|
---|
| 65 | Creates a "setter" for the property with the given `name` on the delegated
|
---|
| 66 | object.
|
---|
| 67 |
|
---|
| 68 | ## Delegate#access(name)
|
---|
| 69 |
|
---|
| 70 | Creates an "accessor" (ie: both getter *and* setter) for the property with the
|
---|
| 71 | given `name` on the delegated object.
|
---|
| 72 |
|
---|
| 73 | ## Delegate#fluent(name)
|
---|
| 74 |
|
---|
| 75 | A unique type of "accessor" that works for a "fluent" API. When called as a
|
---|
| 76 | getter, the method returns the expected value. However, if the method is called
|
---|
| 77 | with a value, it will return itself so it can be chained. For example:
|
---|
| 78 |
|
---|
| 79 | ```js
|
---|
| 80 | delegate(proto, 'request')
|
---|
| 81 | .fluent('query')
|
---|
| 82 |
|
---|
| 83 | // getter
|
---|
| 84 | var q = request.query();
|
---|
| 85 |
|
---|
| 86 | // setter (chainable)
|
---|
| 87 | request
|
---|
| 88 | .query({ a: 1 })
|
---|
| 89 | .query({ b: 2 });
|
---|
| 90 | ```
|
---|
| 91 |
|
---|
| 92 | # License
|
---|
| 93 |
|
---|
| 94 | MIT
|
---|
Note:
See
TracBrowser
for help on using the repository browser.