Skip to content

Commit

Permalink
perf(base32): remove unnecessary string manipulation in `crockfordDec…
Browse files Browse the repository at this point in the history
…ode` function
  • Loading branch information
TheEdoRan committed Feb 27, 2023
1 parent ea0083f commit 7992944
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/base32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ export const crockfordEncode = (input: Buffer): string => {
};

export const crockfordDecode = (input: string): Buffer => {
// 1. Translate input to all uppercase
// 2. Translate I, L, and O to valid base 32 characters
// 3. Remove all hyphens
let sanitizedInput = input
.toUpperCase()
.replace(/O/g, "0")
.replace(/[IL]/g, "1")
.replace(/-+/g, "");
let sanitizedInput = input.toUpperCase();

// Work from the end
sanitizedInput = sanitizedInput.split("").reverse().join("");
Expand Down

0 comments on commit 7992944

Please sign in to comment.