Skip to content

Commit a649de2

Browse files
committed
Docs changes for predefined chars
1 parent 22701cc commit a649de2

File tree

17 files changed

+100
-46
lines changed

17 files changed

+100
-46
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -211,45 +211,45 @@ Example:
211211

212212
There are 19 pre-defined character sets:
213213

214-
| Name | Characters |
215-
| :---------------- | :-------------------------------------------------------------------------------------------- |
216-
| :alpha | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz |
217-
| :alpha_lower | abcdefghijklmnopqrstuvwxyz |
218-
| :alpha_upper | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
219-
| :alphanum | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 |
220-
| :alphanum_lower | abcdefghijklmnopqrstuvwxyz0123456789 |
221-
| :alphanum_upper | ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 |
222-
| :base16 | 0123456789ABCDEF |
223-
| :base32 | ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 |
224-
| :base32_hex | 0123456789abcdefghijklmnopqrstuv |
225-
| :base32_hex_upper | 0123456789ABCDEFGHIJKLMNOPQRSTUV |
226-
| :crockford32 | 0123456789ABCDEFGHJKMNPQRSTVWXYZ |
227-
| :decimal | 0123456789 |
228-
| :hex | 0123456789abcdef |
229-
| :hex_upper | 0123456789ABCDEF |
230-
| :safe_ascii | !#$%&()\*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^\_abcdefghijklmnopqrstuvwxyz{\|}~ |
231-
| :safe32 | 2346789bdfghjmnpqrtBDFGHJLMNPQRT |
232-
| :safe64 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-\_ |
233-
| :symbol | !#$%&()\*+,-./:;<=>?@[]^\_{\|}~ |
234-
| :wordSafe32 | 23456789CFGHJMPQRVWXcfghjmpqrvwx |
214+
| Name | Characters |
215+
| :------------- | :-------------------------------------------------------------------------------------------- |
216+
| ALpha | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz |
217+
| AlphaLower | abcdefghijklmnopqrstuvwxyz |
218+
| AlphaUpper | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
219+
| AlphaNum | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 |
220+
| AlphaNumLower | abcdefghijklmnopqrstuvwxyz0123456789 |
221+
| AlphaNumUpper | ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 |
222+
| Base16 | 0123456789ABCDEF |
223+
| Base32 | ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 |
224+
| Base32Hex | 0123456789abcdefghijklmnopqrstuv |
225+
| Base32HexUpper | 0123456789ABCDEFGHIJKLMNOPQRSTUV |
226+
| Crockford32 | 0123456789ABCDEFGHJKMNPQRSTVWXYZ |
227+
| Decimal | 0123456789 |
228+
| Hex | 0123456789abcdef |
229+
| HexUpper | 0123456789ABCDEF |
230+
| SafeAscii | !#$%&()\*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^\_abcdefghijklmnopqrstuvwxyz{\|}~ |
231+
| Safe32 | 2346789bdfghjmnpqrtBDFGHJLMNPQRT |
232+
| Safe64 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-\_ |
233+
| Symbol | !#$%&()\*+,-./:;<=>?@[]^\_{\|}~ |
234+
| WordSafe32 | 23456789CFGHJMPQRVWXcfghjmpqrvwx |
235235

236236
Any string of up to 256 unique characters, including unicode, can be used for **`puid`** generation.
237237

238238
#### Description of non-obvious character sets
239239

240-
| Name | Description |
241-
| :---------------- | :--------------------------------------------------------- |
242-
| :base16 | https://datatracker.ietf.org/doc/html/rfc4648#section-8 |
243-
| :base32 | https://datatracker.ietf.org/doc/html/rfc4648#section-6 |
244-
| :base32_hex | Lowercase of :base32_hex_upper |
245-
| :base32_hex_upper | https://datatracker.ietf.org/doc/html/rfc4648#section-7 |
246-
| :crockford32 | https://www.crockford.com/base32.html |
247-
| :safe_ascii | Printable ascii that does not require escape in String |
248-
| :safe32 | Alpha and numbers picked to reduce chance of English words |
249-
| :safe64 | https://datatracker.ietf.org/doc/html/rfc4648#section-5 |
250-
| :wordSafe32 | Alpha and numbers picked to reduce chance of English words |
251-
252-
Note: :safe32 and :wordSafe32 are two different strategies for the same goal.
240+
| Name | Description |
241+
| :------------- | :--------------------------------------------------------- |
242+
| Base16 | https://datatracker.ietf.org/doc/html/rfc4648#section-8 |
243+
| Base32 | https://datatracker.ietf.org/doc/html/rfc4648#section-6 |
244+
| Base32Hex | Lowercase of Base32HexUpper |
245+
| Base32HexUpper | https://datatracker.ietf.org/doc/html/rfc4648#section-7 |
246+
| Crockford32 | https://www.crockford.com/base32.html |
247+
| SafeAscii | Printable ascii that does not require escape in String |
248+
| Safe32 | Alpha and numbers picked to reduce chance of English words |
249+
| Safe64 | https://datatracker.ietf.org/doc/html/rfc4648#section-5 |
250+
| WordSafe32 | Alpha and numbers picked to reduce chance of English words |
251+
252+
Note: Safe32 and WordSafe32 are two different strategies for the same goal.
253253

254254
[TOC](#TOC)
255255

src/lib/encoder/alpha.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
6+
57
export default (): PuidEncoder => {
68
const upper = 'A'.charCodeAt(0)
79
const lower = 'a'.charCodeAt(0)

src/lib/encoder/alphaCase.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars:
6+
// lower: abcdefghijklmnopqrstuvwxyz
7+
// upper: ABCDEFGHIJKLMNOPQRSTUVWXYZ
8+
59
export default (uppercase = false): PuidEncoder => {
610
const alpha = (uppercase ? 'A' : 'a').charCodeAt(0)
711

src/lib/encoder/alphaNum.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
6+
57
export default (): PuidEncoder => {
68
const upper = 'A'.charCodeAt(0)
79
const lower = 'a'.charCodeAt(0)

src/lib/encoder/alphaNumCase.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars:
6+
// lower: abcdefghijklmnopqrstuvwxyz0123456789
7+
// upper: ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
8+
59
export default (uppercase = false): PuidEncoder => {
610
const decimal = '0'.charCodeAt(0)
711
const alpha = (uppercase ? 'A' : 'a').charCodeAt(0)

src/lib/encoder/base16.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars: 0123456789ABCDEF
6+
// ref: https://datatracker.ietf.org/doc/html/rfc4648#section-8
7+
58
export default (): PuidEncoder => {
69
const decimal = '0'.charCodeAt(0)
710
const alpha = 'A'.charCodeAt(0)

src/lib/encoder/base32.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars: ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
6+
// ref: https://datatracker.ietf.org/doc/html/rfc4648#section-6
7+
58
export default (): PuidEncoder => {
69
const alpha = 'A'.charCodeAt(0)
710
const decimal = '2'.charCodeAt(0)

src/lib/encoder/base32HexCase.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5+
// chars: ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
6+
// lower: 0123456789abcdefghijklmnopqrstuv
7+
// upper: 0123456789ABCDEFGHIJKLMNOPQRSTUV
8+
// ref: https://datatracker.ietf.org/doc/html/rfc4648#section-7
9+
510
export default (uppercase = false): PuidEncoder => {
611
const decimal = '0'.charCodeAt(0)
712
const alpha = (uppercase ? 'A' : 'a').charCodeAt(0)

src/lib/encoder/boundEncoder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { PuidEncoder } from '../../types/puid'
22

3+
// Decorate encoder to return NaN for negative and out-of-bounds indexes
4+
35
export default (puidEncoder: PuidEncoder, oob: number): PuidEncoder =>
46
(n: number) => {
57
if (n < 0) return NaN

src/lib/encoder/crockford32.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { PuidEncoder } from '../../types/puid'
22

33
import boundEncoder from './boundEncoder'
44

5-
// n: 0123456789 01234567 89 01 23456 78901
6-
// c: 0123456789 ABCDEFGH JK MN PQRST VWXYZ
5+
// chars: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
6+
// ref: https://www.crockford.com/base32.html
7+
//
8+
// Mapping
9+
// n: 0123456789 01234567 89 01 23456 78901
10+
// c: 0123456789 ABCDEFGH JK MN PQRST VWXYZ
711

812
export default (): PuidEncoder => {
913
const zero = '0'.charCodeAt(0)

0 commit comments

Comments
 (0)