Return numeric pattern with function parameter as its length

I need to return numeric pattern using a function and function has parameter length.

This is what i tried,

export const numericPattern = (length: number) => /[d]{length}/;

I just want to return the pattern with given length and if length is not given as parameter, i need to return only /[d]/.

Thanks