Giter VIP home page Giter VIP logo

Comments (8)

lucono avatar lucono commented on May 22, 2024

Are your enums simple strings or implemented as an actual "type"? Do you have some sample code to illustrate? If your enums are implemented as just strings, then they wouldn't appear as a proper type other than the "string" type.

xtypejs supports Instance Types, which would allow you to validate your enum, as long as it's implemented as a proper type (for instance, a WeekDay type representing the days of the week).

If you can provide some sample code of your current implementation, I could try to provide some code examples of an Instance Type based solution.

from xtypejs.

codebreach avatar codebreach commented on May 22, 2024

We have both instance types and string types.
The instance types are obviously supported as you mentioned. My request was for string types:

var STATES = {
  ACCEPTED: 'ACCEPTED',
  REJECTED: 'REJECTED'
};

var objectToBeValidated = {
  state: STATES.ACCEPTED
};

Now I want to do something like:

xtypejs.isEnum(objectToBeValidated.state, STATES)

I am not sure how this would work with .type since it really is a string as you pointed out.

from xtypejs.

bjmiller avatar bjmiller commented on May 22, 2024

Can registerTypes handle this? It looks close, but you'd probably need for it to accept a custom function that can test for whether an arbitrary thing passed in meets the criteria for the new type.

Also, you would probably need to allocate a higher-number space for custom-type ID numbers to live in.

from xtypejs.

lucono avatar lucono commented on May 22, 2024

A registerTypes approach would have to be implemented in a way that keeps the new type completely compatible with any other built-in or previously registered types, which might be possible. Definitely worth exploring ..will look into it.

from xtypejs.

lucono avatar lucono commented on May 22, 2024

After exploring the registerTypes approach to this, I'm going to go ahead and implement it, after which you can give it a try for your use case and provide feedback based on that.

from xtypejs.

codebreach avatar codebreach commented on May 22, 2024

Woohoo. Thanks for the quick turnaround. Looking forward to using this.

On Thu, Jul 2, 2015, 4:45 PM lucono [email protected] wrote:

After exploring the registerTypes approach to this, I'm going to go ahead
and implement it, after which you can give it a try for your use case and
provide feedback based on that.


Reply to this email directly or view it on GitHub
#1 (comment).

from xtypejs.

lucono avatar lucono commented on May 22, 2024

Created #2 for the implementation of the custom validation feature.

from xtypejs.

lucono avatar lucono commented on May 22, 2024

Regarding enums:
xtypejs supports Instance Types, which are able to validate Enums implemented as actual enum types. More in this comment.

Regarding arbitrary custom validation:
This would support arbitrary string and/or any other type of arbitrary validation logic, completely integrated and compatible with all other xtypejs custom and non-custom (built-in) types.

See: Arbitrary Custom Validation Support (issue #2) - available in next release of xtypejs.

from xtypejs.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.