lucono / xtypejs Goto Github PK
View Code? Open in Web Editor NEWElegant, highly efficient data validation for JavaScript.
Home Page: https://xtype.js.org
License: MIT License
Elegant, highly efficient data validation for JavaScript.
Home Page: https://xtype.js.org
License: MIT License
The default
name scheme is very readable and easily understood, but is verbose to type. On the other hand, the compact
name scheme is short and easy to type but is not easily understandable to someone reading it in code without prior knowledge of the scheme's name convention.
For instance, default
name scheme example:
xtype.which(value, 'multi_char_string, positive_integer, single_prop_object, number, nothing');
And compact
name scheme equivalent:
xtype.which(value, 'str2+ int+ obj1 num nil');
It would be valuable to have available with the library, an additional set of alternative name schemes, which should be intuitive, have broad appeal, and provide a reasonable and practical balance of readability and conciseness falling somewhere between the two current default
and compact
name schemes.
We have a bunch of code that looks like the 'before' in your examples.
However we also need to validate enums, ensuring that the value is one of a list of strings or objects.
I am pretty sure I checked all the docs and didn't find this, any chance of getting some isEnum type functionality that basically does arr1 && indexOf type checks?
Add support for arbitrary custom-validated types, based on the discussion started in issue #1. Should include ability to define and register custom types, with arbitrary custom validation logic.
I can't make xtype
work when I compare values with the compact representation.
If I do this (from the docs):
switch (xtype.which(req.params.testid, 'str2+ int+ nil')) {
case 'str2+':
res.send('str2+');
break;
case 'int+':
res.send('int+');
break;
case 'nil':
res.send('nil');
break;
default:
res.send('type not recognized');
break;
}
This always sends type not recognized
.
Maybe I have to set xtype
to use the compact representation by default? I can't find how I do this, if that is the case.
Thanks
Extract the following functionality which will be needed only by a subset of library users, into separate, optional, add-on modules:
util
API methods (xtype.util.*) - These can be very useful when needed, but likely only needed by a few users.compact
name scheme.Extracting these into separate optional add-ons will reduce the size of the main library while still allowing the various extracted add-ons to be used when required, to re-introduce the various functionality only for library users who need them.
As much as possible, this change should maintain backward compatibility.
as someone who doesn't know too much about your library, but am interested, i believe it would be nice to see the 'descriptive names' tab by default in the code examples. don't worry this won't make me think the library is too verbose or inefficient, it will just help me understand your nice examples a bit faster :).
Thanks for the 0.6 modularity update!
I think it would be helpful to have an isNot method for readability. Instead of something like this:
!xtype.is(data, 'obj')
I'd like to be able to write xtype.isNot(data, 'obj')
Also, xtype.not.is() throws an error (but I don't like that form anyway).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.