Readme.md
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
15var delegate = require('delegates');
16
17...
18
19delegate(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
51Creates 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
56Allows the given method `name` to be accessed on the host.
57
58## Delegate#getter(name)
59
60Creates a "getter" for the property with the given `name` on the delegated
61object.
62
63## Delegate#setter(name)
64
65Creates a "setter" for the property with the given `name` on the delegated
66object.
67
68## Delegate#access(name)
69
70Creates an "accessor" (ie: both getter *and* setter) for the property with the
71given `name` on the delegated object.
72
73## Delegate#fluent(name)
74
75A unique type of "accessor" that works for a "fluent" API. When called as a
76getter, the method returns the expected value. However, if the method is called
77with a value, it will return itself so it can be chained. For example:
78
79```js
80delegate(proto, 'request')
81 .fluent('query')
82
83// getter
84var q = request.query();
85
86// setter (chainable)
87request
88 .query({ a: 1 })
89 .query({ b: 2 });
90```
91
92# License
93
94 MIT
95