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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Support JSON.stringify replacer function #382

Closed
michaelnwani opened this issue Mar 14, 2023 · 1 comment
Closed

[Feature Request] Support JSON.stringify replacer function #382

michaelnwani opened this issue Mar 14, 2023 · 1 comment

Comments

@michaelnwani
Copy link

Firstly, thank you for making mande and continuing to support it 馃檪 this is the best fetch library available. I really appreciate it.

My proposal here is to add a config option for dev's to pass a replacer function to the JSON.stringify that is used when making API calls. This would really help when resolving cyclic reference issues.

Example inspired from MDN:

const replacer = () => {
  const seen = new WeakSet();
  return (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) {
        return;
      }
      seen.add(value);
    }
    return value;
  };
};

JSON.stringify(circularReference, replacer());

Maybe we can set it during the mande initialization, so it would look something like:

import { mande } from 'mande'
const users = mande('/api/users',{replacer})
@michaelnwani michaelnwani changed the title [Feature Request] Support passing replacer function to JSON.stringify [Feature Request] Support JSON.stringify replacer function Mar 14, 2023
@posva
Copy link
Owner

posva commented Apr 5, 2023

Maybe even allow a custom JSON.sringify()

@posva posva mentioned this issue May 31, 2023
12 tasks
@posva posva closed this as completed in afd0c5e Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants