Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: str.replace is not a function. #344

Closed
TimiBolu opened this issue May 24, 2024 · 7 comments
Closed

TypeError: str.replace is not a function. #344

TimiBolu opened this issue May 24, 2024 · 7 comments

Comments

@TimiBolu
Copy link

TimiBolu commented May 24, 2024

Hi, I really appreciate your library and have used it ever since I found out about it (roughly a year).

However, I encountered an issue.
When I tried to compile the following code, I get the error below,

*** The code ****

Screenshot 2024-05-24 at 10 51 06

**** The error ****

Screenshot 2024-05-24 at 10 45 56

When I change any two things, it works fine.
1 - If I remove the "form" field.
or
2 - or I change the string types
Screenshot 2024-05-24 at 10 47 47

Please what could be the issue.

@FerX
Copy link
Contributor

FerX commented Jun 19, 2024

Please do not send screenshots, but the schema and example data.

@TimiBolu
Copy link
Author

TimiBolu commented Jun 19, 2024

import Validator from "fastest-validator";

const v = new Validator();

const header = {
    "socials": {
        "$$type": "object|optional",
        "apps": {
            "type": "array",
            "items": {
                "type": "object",
                "props": {
                    "name": {
                        "type": "string",
                        "enum": [
                            "instagram",
                            "twitter",
                            "facebook",
                            "github",
                            "linkedin",
                            "tiktok",
                            "dribbble",
                            "behance",
                            "twitch",
                            "snapchat",
                            "email",
                            "whatsapp",
                            "webaddress"
                        ]
                    },
                    "handle": {
                        "type": "string",
                        "optional": true
                    },
                    "url": {
                        "type": "string",
                        "optional": true
                    }
                }
            },
            "optional": true
        },
        "iconStyle": {
            "type": "string",
            "optional": true,
            "enum": [
                "outline",
                "color",
                "solid"
            ]
        },
        "alignment": {
            "type": "string",
            "optional": true,
            "enum": [
                "left",
                "center",
                "right"
            ]
        }
    },
    "text": {
        "$$type": "object|optional",
        "value": {
            "type": "string",
            "optional": true
        },
        "font": {
            "type": "string",
            "optional": true
        }
    },
    "title": {
        "$$type": "object|optional",
        "heading": {
            "type": "string",
            "optional": true
        },
        "subHeading": {
            "type": "string",
            "optional": true
        },
        "alignment": {
            "type": "string",
            "optional": true,
            "enum": [
                "left",
                "center",
                "right"
            ],
            "default": "center"
        }
    },
    "image": {
        "$$type": "object",
        "value": {
            "type": "string",
            "optional": true
        },
        "style": {
            "type": "string",
            "optional": true,
            "enum": [
                "round",
                "straight",
                "curved",
                "curved-md"
            ]
        },
        "alignment": {
            "type": "string",
            "optional": true,
            "enum": [
                "full_width",
                "none"
            ]
        }
    },
    "layout": {
        "type": "string",
        "enum": [
            "img-right",
            "img-left",
            "img-top",
            "img-bg",
            "img-top-bg"
        ]
    },
    "form": {
        "$$type": "object|optional",
        "title": {
            "type": "string"
        },
        "description": {
            "type": "string"
        },
        "label": {
            "type": "string"
        },
        "field1": {
            "$$type": "object",
            "name": {
                "type": "string"
            },
            "value": {
                "type": "string"
            }
        },
        "field2": {
            "$$type": "object",
            "name": {
                "type": "string"
            },
            "value": {
                "type": "string"
            }
        }
    }
};

const ssc = v.compile(header);
console.log({ssc})

 const data = {
    "image": {
        "value": "https://res.cloudinary.com/dnsbjog0b/image/upload/v1705415231/fmm2oskwp6r2q8gu1ack.jpg",
        "style": "round",
        "alignment": "none"
    },
    "text": {
        "size": "narrow",
        "value": "With fingers flying over the keyboard, I turn code into symphonies, creating not just functional but stylish tech wonders."
    },
    "title": {
        "heading": "Timi Adesina",
        "subHeading": "",
        "alignment": "center"
    },
    "socials": {
        "apps": [
            "twitch": {
                "handle": "",
                "url": "",
            },
            "instagram": {
                "handle": "",
                "url": "https://www.instagram.com/",
            },
            "twitter": {
                "handle": "TimmyAdesina",
                "url": "https://twitter.com/TimmyAdesina",
            },
            "facebook": {
                "handle": "",
                "url": "https://web.facebook.com/",
            },
            "github": {
                "handle": "TimiBolu",
                "url": "https://github.com/TimiBolu",
            },
            "linkedin": {
                "handle": "timiadesina",
                "url": "https://www.linkedin.com/in/timiadesina",
            },
            "tiktok": {
                "handle": "",
                "url": "https://www.tiktok.com/@",
            },
            "dribbble": {
                "handle": "",
                "url": "https://dribbble.com/",
            },
            "behance": {
                "handle": "",
                "url": "https://www.behance.net/",
            },
            "snapchat": {
                "handle": "",
                "url": "https://www.snapchat.com/add/",
            },
            "email": {
                "handle": "[email protected]",
                "url": "mailto:[email protected]",
            },
            "whatsapp": {
                "handle": "09066744819",
                "url": "https://wa.me/09066744819",
            },
            "webaddress": {
                "handle": "",
                "url": "//",
            }
        ],
        "iconStyle": "outline",
        "alignment": "center"
    },
    "form": {
        "title": "",
        "description": "",
        "field1": "",
        "field2": "",
        "label": ""
    },
    "layout": "img-top"
}

@FerX
Copy link
Contributor

FerX commented Jun 20, 2024

ok, the issue is "label" property into form..

try this:

"form": {
type:"object",
props:{
	"title": {
		"type": "string"
	},
	"description": {
		"type": "string"
	},
	"label": {
		"type": "string"
	}
}
}

@FerX
Copy link
Contributor

FerX commented Jun 20, 2024

the pull request #345
fix also this bug.

@TimiBolu
Copy link
Author

Thank you so much. I really appreciate it.
I actually wrote a very light wrapper for my use case with a joi/zod like syntax that compiles to fastest-validator schema.
I have discovered writing the json schema like syntax can be quite daunting so I now auto generate them.
It kind of allows me get the best of both worlds.
I feel this may be a good way forward as an api extension for users who may be interested.

@TimiBolu TimiBolu reopened this Jul 16, 2024
@thib3113
Copy link
Collaborator

thib3113 commented Sep 2, 2024

@TimiBolu can we close this issue ?

@TimiBolu
Copy link
Author

TimiBolu commented Sep 2, 2024

Sure 👍

@thib3113 thib3113 closed this as completed Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants