Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Alphanumeric field #41

Open
jade290 opened this issue Jun 2, 2021 · 1 comment
Open

Feature Request - Alphanumeric field #41

jade290 opened this issue Jun 2, 2021 · 1 comment

Comments

@jade290
Copy link

jade290 commented Jun 2, 2021

Hello,

Will there be an alphanumeric field in the future?

{{ alphanumeric 10 }}
KLK893KLE0

@webroo
Copy link
Owner

webroo commented Jun 2, 2021

Yes I've thought about this! I'd like to do something using regex syntax so users can define an alphanumeric pattern, eg: [A-Z]{2}[0-9]{3}[A-Z]{2} but I need to set aside some time to investigate it.

In the meantime I've thrown together a customer helper you can use that'll generate a completely random pattern of characters:

const customHelpers = {
  alphanumeric(count) {
    let string = '';
    for (let i = 0; i < count; i++) {
      string += dummyjson.utils.random() > 0.5
        ? dummyjson.utils.randomChar()
        : dummyjson.utils.randomInt(0, 9)
    }
    return string;
  }
}

const template = `{{alphanumeric 10}}`
const result = dummyjson.parse(template, { helpers: customHelpers });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants