Skip to content

Commit

Permalink
docs: Update the params table for the constructor
Browse files Browse the repository at this point in the history
Be more clear about parameter types and add tests to verify the docs.
Also reformat the markdown to it more readable.
  • Loading branch information
nwoltman committed Oct 23, 2017
1 parent cf021da commit 327d506
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ uidgen.generateSync(); // -> '8Vw3bgbMMzeYfrQHQ8p3Jr'

Creates a new `UIDGenerator` instance that generates `bitSize`-bit or `uidLength`-sized UIDs encoded using the characters in `baseEncoding`.

| Param | Default | Type | Description |
|-------|---------|------|-------------|
| [bitSize] | `128` | number | The size of the UID to generate in bits. Must be a multiple of `8`. |
| [baseEncoding] | `UIDGenerator.BASE58` | string | One of the `UIDGenerator.BASE##` constants or a custom string of characters to use to encode the UID. If a custom string is used, it must made of unique characters. |
| [uidLength] | `null` | number | The length of the UID string to generate. An error is thrown if `uidLength` is specified and `bitSize` is specified and not `null`. |
| Param | Type | Default | Description
|----------------|--------------------|-----------------------|-------------
| [bitSize] | `number` \| `null` | `128` | The size of the UID to generate in bits. Must be a multiple of `8`.
| [baseEncoding] | `string` | `UIDGenerator.BASE58` | One of the `UIDGenerator.BASE##` constants or a custom string of characters to use to encode the UID. If a custom string is used, it must made of unique characters.
| [uidLength] | `number` | `undefined` | The length of the UID string to generate. An error is thrown if `uidLength` is specified and `bitSize` is specified and not `null`.

**Note:** If you use a custom `baseEncoding` that has URL-unsafe characters, it is up to you to URL-encode the resulting UID.

Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ describe('UIDGenerator', () => {

it('accepts the baseEncoding and uidLength parameters', () => {
const uidgen = new UIDGenerator(UIDGenerator.BASE62, 22);

uidgen.bitSize.should.be.exactly(131);
uidgen.baseEncoding.should.be.exactly(UIDGenerator.BASE62);
uidgen.uidLength.should.be.exactly(22);
uidgen.base.should.be.exactly(62);

new UIDGenerator(null, UIDGenerator.BASE62, 22).should.deepEqual(uidgen);
new UIDGenerator(undefined, UIDGenerator.BASE62, 22).should.deepEqual(uidgen);
});

it('accepts a custom baseEncoding', () => {
Expand Down

0 comments on commit 327d506

Please sign in to comment.