Skip to content

Commit

Permalink
feat: add a public method hashids.isValidId(id) that validates the ID
Browse files Browse the repository at this point in the history
  • Loading branch information
niieani committed Nov 9, 2019
1 parent a3075a4 commit 7be1bda
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/hashids.ts
Expand Up @@ -218,6 +218,15 @@ export default class Hashids {
return ret
}

public isValidId(id: string): boolean {
return [...id].every(
(char) =>
this.alphabet.includes(char) ||
this.guards.includes(char) ||
this.seps.includes(char),
)
}

private _decode(id: string, alphabet: string): NumberLike[] {
const idGuardsArray = splitAtMatch(id, (char) => this.guards.includes(char))
const splitIndex =
Expand Down

0 comments on commit 7be1bda

Please sign in to comment.