bjnortier / valid8t

Javascript data structure validation
0 stars 0 forks source link

Have a look at https://github.com/hapijs/joi - I really like it #1

Open antony opened 9 years ago

antony commented 9 years ago

... and use it all the time :)

bjnortier commented 9 years ago

Awesome

Didn’t find anything that liked but this looks good.

On Thursday, 10 September 2015 at 12:07, Antony Jones wrote:

... and use it all the time :)

— Reply to this email directly or view it on GitHub (https://github.com/bjnortier/valid8t/issues/1).

bjnortier commented 9 years ago

@antony Doesn't work with webpack https://github.com/hapijs/joi/issues/528

bjnortier commented 9 years ago

Well, email validation doesn't work as it uses some node modules that can't be used with webpack (net, dns), but should be fine as I don't have email fields in the app I'm working on

antony commented 9 years ago

Interesting - It's primarily a node module (used extensively in hapijs) I guess, but it would be useful if it did work client-side. Looks like there are enough people concerned about client side support that it might happen soon :)

Marsup commented 9 years ago

I don't plan on officially supporting client-side but it's easy enough you can do it yourself : https://github.com/hapijs/joi/issues/154#issuecomment-118408471

bjnortier commented 9 years ago

@Marsup Thanks, I used

node: {
  net: 'empty',
  dns: 'empty',
}

in webpack.config.js

pr1ntr commented 8 years ago

While this works normally in webpack there is an issue with building for production. UglifyJsPlugin can't process the Joi lib because its written in ES6 and does not have a build.

I would get this error: Unexpected token: name (Alternatives) [./~/transform-loader?envify!./~/joi/lib/any.js:8,0]

The solution I got to was to add it to my includes in babel transform.

{
      test: /\.js$|\.jsx$/i,
      //exclude: /node_modules/,
      loader: 'babel',
      include: [
        `./src/js/`,
        `./node_modules/joi/`,
        `./node_modules/isemail/`,
        `./node_modules/topo/`,
      ]
},
glrodasz commented 8 years ago

@pr1ntr I have a kind of the same problem but I'm no able to fix it.

ERROR in bundle.js from UglifyJs SyntaxError: Unexpected token: name (newObj) [./~/joi/~/hoek/lib/index.js:33,0]

When I try to fix it including the joi module I get another error.

ERROR in ./src/index.js Module parse failed: /Users/Garethderioth/Code/app/node_modules/eslint-loader/index.js!/Users/Garethderioth/Code/app/src/index.js Unexpected token (11:2) You may need an appropriate loader to handle this file type.

Do you have any idea?

Marsup commented 8 years ago

You may use joi-browser instead of joi if you're not willing to spend time understanding webpack configuration, or you can get inspiration from it as its build might not be perfect for your own use case.

glrodasz commented 8 years ago

@Marsup I had the setup for use joi-browser, but the good news is that I have fixed. As @pr1ntr says the problem is that babel needs to parse the joi/hoek library. I tried a lot of combinations between include and exclude but this one is working for me:

loaders: [
      {
        test: /\.js$/,
        exclude: [/joi-browser/, /react-display-name/, /moment/],
        loader: 'react-hot!babel',
      },

I hope that this information helps somebody else like the comment of @pr1ntr helps me! Thank you!

Marsup commented 8 years ago

joi-browser is a precompiled package, I dont think you should have any trouble with hoek.

pr1ntr commented 8 years ago

@Garethderioth My issue was that the browser couldn't make sense of joi packages since they are for node. what i did was this:

my webpack babel loader:

{
      test: /\.js$|\.jsx$/i,
      //exclude: /node_modules/,
      loader: 'babel',
      include: [
        path.normalize(`${cwd}/src/js/`),
        path.normalize(`${cwd}/node_modules/joi/`),
        path.normalize(`${cwd}/node_modules/isemail/`),
        path.normalize(`${cwd}/node_modules/topo/`),
        path.normalize(`${cwd}/node_modules/hoek/`),
        path.normalize(`${cwd}/node_modules/react-flex-data/`),

      ]
    },

and then i stub some node stuff in my config

node: {
    net: 'empty',
    tls: 'empty',
    dns: 'empty',
    fs: 'empty'
  }

different people use different path strategies but you get the gist.