Skip to content

Feature Request: Allow Selective Import of Validators #128

@danielxbauer

Description

@danielxbauer

Hi!

First of all, I just want to say this is an awesome library! It does exactly what I need and has made my work so much easier. Thank you for your hard work and for sharing this with the open-source community.

I do have one small feature request or question: Currently, all validators are exposed in a single large record, which is great for dynamically applying them. However, I find that it could be a bit limiting when I know exactly which validator I need. Specifically:

  1. Strict typing: When all validators are exposed together, it becomes difficult to work with them in a strictly-typed manner, given you know at compile time which validators you need.
import { stdnum } from 'stdnum';

// stdnum is typed as Record<string, Record<string, Validator>>
// this means that a potential typo like e.g. 'jmgb' (instead of jmbg) is only visible on runtime and not compile time
const jmbg = stdnum['RS']['jmbg']; // This may fail if I provide false strings
// If an import like this would be supported I could be sure that 
// the validator is available on compile time :)
import { jmbg } from 'stdnum/RS';
  1. Import optimization: I would like to only bundle the validators I actually use, rather than importing the entire set.

Would it be possible to add an option in the future that allows users to selectively import just the validators they need?
Or am I missing something here? This would make the library even more efficient and tailored to individual use cases.

Thank you again for creating such a fantastic tool!

Best regards,
Daniel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions