surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
293 stars 48 forks source link

`jsonify()` method #259

Closed kearfy closed 4 months ago

kearfy commented 4 months ago

Thank you for submitting this pull request! We appreciate you spending the time to work on these changes.

What is the motivation?

We improved toJSON support in #256 with the slight oversight that native datatypes don't generally have a toJSON method.

What does this change do?

It introduces a jsonify method which effectively JSON stringifies the passed value and then parses it again, allthough it adds typing to it to preserve the type of the passed value and converts them.

We're going with a simple stringify + parse method because we need a bit more time if something custom which would loop through all values recursively could be faster and acurate.

What is your testing strategy?

Transformed the toJSON unit test into jsonify

Is this related to any issues?

Continuation of #256

Have you read the Contributing Guidelines?