faker-js / faker

Generate massive amounts of fake data in the browser and node.js
https://fakerjs.dev
Other
12.98k stars 919 forks source link

datatype.number is not immutable #328

Closed pkuczynski closed 2 years ago

pkuczynski commented 2 years ago

Describe the bug

The faker.datatype.number mutates the options param.

Reproduction

const o = { max: 10 }
faker.datatype.number(o)
console.log(o)
// { max: 10, min: 0, precision: 1 }

Additional Info

No response

xDivisionByZerox commented 2 years ago

Based on this. Is there a reason why each property of options is checked against typeof prop === 'undefined' instead of just checking against undefined itself?

ST-DDT commented 2 years ago

Based on this. Is there a reason why each property of options is checked against typeof prop === 'undefined' instead of just checking against undefined itself?

Basically just a convention - https://stackoverflow.com/questions/4725603/variable-undefined-vs-typeof-variable-undefined (That way all possible undefined checks look the same)

FFR: https://github.com/faker-js/faker/blob/main/src/datatype.ts#L38

xDivisionByZerox commented 2 years ago

I will provide a pr. Can I get assigned?