faker-js / faker

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

support cidr #2252

Open unional opened 1 year ago

unional commented 1 year ago

Clear and concise description of the problem

Add support to generate IP CIDR:

https://aws.amazon.com/what-is/cidr/#:~:text=CIDR%20notation%20represents%20an%20IP,1.0%2F22. https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing

Suggested solution

Add as an option to faker.internet.ipv4(...) and faker.internet.ipv6(...).

faker.internet.ipv4({ maskBit: 24 }) // 192.168.1.0/24

faker.internet.ipv4({ maskBit: { min: 8, max: 32 }}) // 10.0.0.0/10

Alternative

No response

Additional context

No response

github-actions[bot] commented 1 year ago

Thank you for your feature proposal.

We marked it as "waiting for user interest" for now to gather some feedback from our community:

xDivisionByZerox commented 1 year ago

Thank you for your suggestion @unional.

To better weigh the importance of your feature, it would help if you could provide the information on whether this is a "nice to have" feature request or if you have an actual use case. If you have an actual use case, it would help if you could provide it as well.

unional commented 1 year ago

Hi,

Yes. It is an actual use case.

You can kind of mimic this by string concatenation, except that the subnet mask must be 0 to the number of bits in IPv4 or IPv6.

That's why it is better to provided by faker instead.