-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): move base to separate file with no eslint validation
- Loading branch information
1 parent
8a52d8a
commit 17a9ce9
Showing
4 changed files
with
36 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
apps/api/src/app/shared/helpers/base62/base62-alphabet.const.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Base62 alphabet | ||
* Modifying this alphabet is prohibited as it would invalidate existing encoded data | ||
*/ | ||
const BASE62_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { encode, decode } = base(BASE62_ALPHABET); | ||
const ENCODING = 'hex' satisfies BufferEncoding; | ||
|
||
export function encodeBase62(value: string): string { | ||
const buffer = Buffer.from(value, ENCODING); | ||
|
||
return encode(buffer); | ||
} | ||
|
||
export function decodeBase62(encoded: string): string { | ||
const uint8Array = decode(encoded); | ||
|
||
return Buffer.from(uint8Array).toString(ENCODING); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './base62'; |