dummy-json
dummy-json copied to clipboard
[Feature Request] Generate MongoDB ObjectId
Hello maintainers, given how popular of a DB Mongo is I think many people would appreciate having an ObjectId generator. What do you think?
Thanks, I like this idea, I'll be sure to add it in a future update. Will keep this open until I do.
I know an ObjectId isn't just a random hex string but here's a custom helper I threw together in the meantime.
const myHelpers = {
objectid() {
return 'xxxxxxxxxxxxxxxxxxxxxxxx'.replaceAll(
'x',
() => dummyjson.utils.randomInt(0, 0xf).toString(16)
);
}
};
const template = '{{objectid}}';
const result = dummyjson.parse(template, { helpers: myHelpers });
console.log(result); // 35bebbc8b80d567fbafb6c16