小编Shi*_*ain的帖子

如何在@hapi/joi 中设置自定义错误消息?

我已经使用 Joi 创建了以下用于验证的架构:

const createProfileSchema = Joi.object().keys({
  username: Joi.string()
    .required()
    .message("username is required")
    .empty()
    .message("username is not allowed to be empty")
    .min(5)
    .message("username must be greater than 5 characters")
    .max(20)
    .message("username must be less than 5 characters")
});
Run Code Online (Sandbox Code Playgroud)

但它引发了流动错误:

 Cannot apply rules to empty ruleset or the last rule added does not support rule properties

      4 |   username: Joi.string()
      5 |     .required()
    > 6 |     .message("username is required")
        |      ^
      7 |     .empty()
      8 |     .message("username is not allowed to …
Run Code Online (Sandbox Code Playgroud)

validation node.js express joi

16
推荐指数
2
解决办法
2万
查看次数

如何在 Joi 中添加自定义验证器功能?

我有 Joi 模式,想添加一个自定义验证器来验证默认 Joi 验证器无法实现的数据。

目前,我使用的是 Joi 16.1.7 版本

   const method = (value, helpers) => {
      // for example if the username value is (something) then it will throw an error with flowing message but it throws an error inside (value) object without error message. It should throw error inside the (error) object with a proper error message

      if (value === "something") {
        return new Error("something is not allowed as username");
      }

      // Return the value unchanged
      return value;
    }; …
Run Code Online (Sandbox Code Playgroud)

javascript validation node.js express joi

10
推荐指数
2
解决办法
2万
查看次数

无法将SVG导入Next JS?

当我尝试导入SVG图像时,显示以下错误。我必须使用哪个加载器来导入SVG图像?

./static/Rolling-1s-200px.svg 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 2000"><filter id="b"><feGaussianBlur stdDeviation="12" /></filter><path fill="#817c70" d="M0 0h2000v2000H0z"/><g filter="url(#b)" transform="translate(4 4) scale(7.8125)" fill-opacity=".5"><ellipse fill="#000210" rx="1" ry="1" transform="matrix(50.41098 -3.7951 11.14787 148.07886 107 194.6)"/><ellipse fill="#eee3bb" rx="1" ry="1" transform="matrix(-56.38179 17.684 -24.48514 -78.06584 205 110.1)"/><ellipse fill="#fff4bd" rx="1" ry="1" transform="matrix(35.40604 -5.49219 14.85017 95.73337 16.4 123.6)"/><ellipse fill="#79c7db" cx="21" cy="39" rx="65" ry="65"/><ellipse fill="#0c1320" cx="117" cy="38" rx="34" ry="47"/><ellipse fill="#5cb0cd" rx="1" ry="1" transform="matrix(-39.46201 77.24476 …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js webpack-4

8
推荐指数
6
解决办法
7315
查看次数

magnificPopup 无法与 webpack 一起使用

我已经通过“npm i magnific-popup”命令安装了 magnificPopup,然后将其导入到 app.js 文件中。但在浏览器控制台中它显示(magnificPopup不是一个函数)

应用程序.js

import $ from "jQuery";
window.$ = window.jQuery = $;
import "magnific-popup";

$(document).ready(function() {
    $('.play-btn').magnificPopup({ type: 'video' });

});
Run Code Online (Sandbox Code Playgroud)

webpack.config.js

var path = require("path");
var webpack = require('webpack');


module.exports = {
    entry: {
        app: "./app/assets/scripts/app.js",
        vendor: "./app/assets/scripts/vendor.js"
    },
    output: {
        path: path.resolve(__dirname, "./app/temp/scripts"),
        filename: "[name].js"
    },
    module: {
        rules: [{
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ["es2015"]
                    }
                }
            }

        ]
    },
    plugins: [
        new webpack.ProvidePlugin({
            '$': 'jquery',
            'jQuery': …
Run Code Online (Sandbox Code Playgroud)

javascript jquery magnific-popup webpack

3
推荐指数
1
解决办法
5764
查看次数