Skip to content

Commit 724b610

Browse files
committed
Fix Base32 chars
Unlike hex versions, decimals are at the end
1 parent 21790df commit 724b610

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/lib/chars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export enum Chars {
1010
AlphaNum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
1111
AlphaNumLower = 'abcdefghijklmnopqrstuvwxyz0123456789',
1212
AlphaNumUpper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
13-
Base32 = '234567ABCDEFGHIJKLMNOPQRSTUVWXYZ',
13+
Base32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
1414
Base32Hex = '0123456789abcdefghijklmnopqrstuv',
1515
Base32HexUpper = '0123456789ABCDEFGHIJKLMNOPQRSTUV',
1616
Decimal = '0123456789',

src/lib/encoder/base32.ts

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

33
export default (): PuidEncoder => {
4-
const decimal = '2'.charCodeAt(0)
5-
const alpha = 'A'.charCodeAt(0) - 6
4+
const alpha = 'A'.charCodeAt(0)
5+
const decimal = '2'.charCodeAt(0) - 26
66

7-
return (n: number) => n + (n < 6 ? decimal : alpha)
7+
return (n: number) => n + (n < 26 ? alpha : decimal)
88
}

0 commit comments

Comments
 (0)