Skip to content

return as value instead of throwing #17

@sakgoyal

Description

@sakgoyal

Would it be possible to add an option to return the error as a value instead of throwing?
I would rather have a "success" check instead of having a try catch.
eg:

//do this
const qsOptions = {..., safe : true}
let match = qs.qsStrict(qsOptions, qsDefintion, "...");
if (!match.success) { ... }
// instead of this:
try {
	let match = qs.qsStrict(qsOptions, qsDefintion, "...");
} catch (error) {
	//...
}

try catch makes everything more complex and simply handling a error value is much easier.

it would just be a new parameter in the options type and instead of always throwing, you just check what the safe option is set to.

Doing this would also follow the same conventions of zod.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions