Skip to content

Commit

Permalink
fix: make noConsecutive digits option optional
Browse files Browse the repository at this point in the history
  • Loading branch information
TimMikeladze committed Aug 11, 2023
1 parent 3b46f02 commit c410b8b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,25 @@ export const animal = word('animals');

export const cosmos = word('cosmos');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const digits = (count?: number) => (options: SpaceSlugOptions) => {
const set = new Set<string>();

while (set.size < (count || 4)) {
const index = Math.floor(Math.random() * 10);
set.add(index.toString());
}
export const digits =
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(count?: number, noConsecutive?: boolean) => (options: SpaceSlugOptions) => {
const c = count || 4;

const list: string[] = [];

while (list.length < c) {
const value = Math.floor(Math.random() * 10).toString();
const latest = list.length ? list[list.length - 1] : null;
if (noConsecutive && latest !== null && latest === value) {
// eslint-disable-next-line no-continue
continue;
}
list.push(value);
}

return Array.from(set).join('');
};
return list.map((x) => x.toString()).join('');
};

export const cleanString = (inputString: string, separator: string) =>
inputString
Expand Down

0 comments on commit c410b8b

Please sign in to comment.