Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e4b72cd

Browse files
committed
docs: update code
1 parent 2ee04b1 commit e4b72cd

File tree

8 files changed

+1243
-1061
lines changed

8 files changed

+1243
-1061
lines changed

docs/client.md

Lines changed: 157 additions & 127 deletions
Large diffs are not rendered by default.

docs/dn.md

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ The `parseDN` API converts a string representation of a DN into an ldapjs DN
2626
object; in most cases this will be handled for you under the covers of the
2727
ldapjs framework, but if you need it, it's there.
2828

29-
var parseDN = require('ldapjs').parseDN;
29+
```js
30+
const parseDN = require('ldapjs').parseDN;
3031

31-
var dn = parseDN('cn=foo+sn=bar, ou=people, o=example');
32-
console.log(dn.toString());
32+
const dn = parseDN('cn=foo+sn=bar, ou=people, o=example');
33+
console.log(dn.toString());
34+
```
3335

3436
# DN
3537

@@ -41,40 +43,46 @@ APIs are setup to give you a DN object.
4143
Returns a boolean indicating whether 'this' is a child of the passed in dn. The
4244
`dn` argument can be either a string or a DN.
4345

44-
server.add('o=example', function(req, res, next) {
45-
if (req.dn.childOf('ou=people, o=example')) {
46-
...
47-
} else {
48-
...
49-
}
50-
});
46+
```js
47+
server.add('o=example', (req, res, next) => {
48+
if (req.dn.childOf('ou=people, o=example')) {
49+
...
50+
} else {
51+
...
52+
}
53+
});
54+
```
5155

5256
## parentOf(dn)
5357

5458
The inverse of `childOf`; returns a boolean on whether or not `this` is a parent
5559
of the passed in dn. Like `childOf`, can take either a string or a DN.
5660

57-
server.add('o=example', function(req, res, next) {
58-
var dn = parseDN('ou=people, o=example');
59-
if (dn.parentOf(req.dn)) {
60-
...
61-
} else {
62-
...
63-
}
64-
});
61+
```js
62+
server.add('o=example', (req, res, next) => {
63+
const dn = parseDN('ou=people, o=example');
64+
if (dn.parentOf(req.dn)) {
65+
...
66+
} else {
67+
...
68+
}
69+
});
70+
```
6571

6672
## equals(dn)
6773

6874
Returns a boolean indicating whether `this` is equivalent to the passed in `dn`
6975
argument. `dn` can be a string or a DN.
7076

71-
server.add('o=example', function(req, res, next) {
72-
if (req.dn.equals('cn=foo, ou=people, o=example')) {
73-
...
74-
} else {
75-
...
76-
}
77-
});
77+
```js
78+
server.add('o=example', (req, res, next) => {
79+
if (req.dn.equals('cn=foo, ou=people, o=example')) {
80+
...
81+
} else {
82+
...
83+
}
84+
});
85+
```
7886

7987
## parent()
8088

@@ -112,6 +120,8 @@ It accepts the same parameters as `format`.
112120

113121
Returns the string representation of `this`.
114122

115-
server.add('o=example', function(req, res, next) {
116-
console.log(req.dn.toString());
117-
});
123+
```js
124+
server.add('o=example', (req, res, next) => {
125+
console.log(req.dn.toString());
126+
});
127+
```

docs/errors.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ a `stack` property correctly set.
1717

1818
In general, you'll be using the errors in ldapjs like:
1919

20-
var ldap = require('ldapjs');
21-
22-
var db = {};
23-
24-
server.add('o=example', function(req, res, next) {
25-
var parent = req.dn.parent();
26-
if (parent) {
27-
if (!db[parent.toString()])
28-
return next(new ldap.NoSuchObjectError(parent.toString()));
29-
}
30-
if (db[req.dn.toString()])
31-
return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
32-
33-
...
34-
});
20+
```js
21+
const ldap = require('ldapjs');
22+
23+
const db = {};
24+
25+
server.add('o=example', (req, res, next) => {
26+
const parent = req.dn.parent();
27+
if (parent) {
28+
if (!db[parent.toString()])
29+
return next(new ldap.NoSuchObjectError(parent.toString()));
30+
}
31+
if (db[req.dn.toString()])
32+
return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
33+
34+
...
35+
});
36+
```
3537

3638
I.e., if you just pass them into the `next()` handler, ldapjs will automatically
3739
return the appropriate LDAP error message, and stop the handler chain.

0 commit comments

Comments
 (0)