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

Support for env variable arrays #399

Open
cupcakearmy opened this issue Dec 8, 2021 · 1 comment
Open

Support for env variable arrays #399

cupcakearmy opened this issue Dec 8, 2021 · 1 comment

Comments

@cupcakearmy
Copy link

Sry if there is already a ticket, I could not find it.

Is there any way to use arrays in a ENV variable? something like FOO=1,2,3?
I understand that comma might be a valid char, so maybe have it opt in?

@petertriho
Copy link

This should work

convict.addFormat({
  name: "comma-separated-string",
  validate: function (val) {
    const emptyStringRegex = /^$/;
    const commaSeparatedStringRegex = /^[\w\d]+(,[\w\d]+)*$/;

    if (!emptyStringRegex.test(val) && !commaSeparatedStringRegex.test(val)) {
      throw new Error("must be a comma separated string");
    }
  },
  coerce: function (val) {
    if (!val) return [];

    return val.split(",");
  },
});

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