faker icon indicating copy to clipboard operation
faker copied to clipboard

feat(zodiac): add new module

Open luciferreeves opened this issue 3 years ago • 42 comments

This PR adds the functionality of generating random zodiac signs and birthdate

New Functions:

  • ~~faker.date.birthdate()~~ (Moved to a separate PR)
  • faker.zodiac.sign()

Usage:

faker.date.birthdate():

// generates a random birthdate of a person aged between 18 and 80
console.log(faker.date.birthdate()) // 1970-12-22T05:00:00.000Z

// generates a random birthdate of a person, between two years
console.log(faker.date.birthdate({ min: 1990, max: 2000 });) // 1992-03-06T05:00:00.000Z

you can also pass a mode to the birthdate object. mode can be 'age' or 'year'

// generates a random birthdate of a person, between two years
console.log(faker.date.birthdate({ min: 1990, max: 2000, mode: 'year' });) // 1992-03-06T05:00:00.000Z

// generates a random birthdate of a person, between two ages
console.log(faker.date.birthdate({ min: 4, max: 5, mode: 'age' });) // 2017-06-08T04:00:00.000Z

faker.zodiac.sign():

// returns a random zodiac sign
console.log(faker.zodiac.sign()) // Leo

// takes optional 'birthday' parameter, if provided returns the zodiac sign for the given birthday
console.log(faker.zodiac.sign('1997-12-20')) // Sagittarius

Unit tests for both the functions added.

Sorry for the repeated commit found later. Its a refactor, but I have some zsh extensions which automatically complete commands in the terminal and it picked up on the last commit message.

Closes #175

luciferreeves avatar Jan 17 '22 00:01 luciferreeves

✔️ Deploy Preview for vigilant-wescoff-04e480 ready!

🔨 Explore the source changes: 652f568df78e39b1fc2dd45b6e942cbd60644f44

🔍 Inspect the deploy log: https://app.netlify.com/sites/vigilant-wescoff-04e480/deploys/61e4c13c519e350007f8a5c9

😎 Browse the preview: https://deploy-preview-182--vigilant-wescoff-04e480.netlify.app

netlify[bot] avatar Jan 17 '22 00:01 netlify[bot]

I will review this after 6.0.0 was released

Shinigami92 avatar Jan 18 '22 21:01 Shinigami92

I would expect faker.date.birthday to have a bit different signature:

faker.date.birthday(age: number, refDate?: string | Date)
faker.date.birthday(options: { min: number, max: number }, refDate?: string | Date)

So instead of providing a year, I would rather expect to provide an age...

pkuczynski avatar Jan 23 '22 20:01 pkuczynski

I would expect faker.date.birthday to have a bit different signature:

faker.date.birthday(age: number, refDate?: string | Date)
faker.date.birthday(options: { min: number, max: number }, refDate?: string | Date)

So instead of providing a year, I would rather expect to provide an age...

I have added a mode option to the faker.date.birthday object. Please take a look at the updated description.

luciferreeves avatar Jan 26 '22 20:01 luciferreeves

Please migrate all js files to ts.

ST-DDT avatar Jan 26 '22 20:01 ST-DDT

Please migrate all js files to ts.

I think it was an accidental commit of lib/* files...

pkuczynski avatar Jan 26 '22 21:01 pkuczynski

I removed the older js files

luciferreeves avatar Jan 26 '22 22:01 luciferreeves

Have the examples files been committed intentionally?

ST-DDT avatar Jan 27 '22 00:01 ST-DDT

I didn't notice the example files were removed from the newer structure of the repo. I removed them from this PR too.

luciferreeves avatar Jan 27 '22 01:01 luciferreeves

Everything that was suggested is added. Please check

luciferreeves avatar Jan 28 '22 03:01 luciferreeves

General comment: you should separate zodiac signs and birthday into two separate PR, as they are totally independent.

pkuczynski avatar Jan 28 '22 20:01 pkuczynski

General comment: you should separate zodiac signs and birthday into two separate PR, as they are totally independent.

@pkuczynski Maybe from next time, I will target smaller issues/PRs. Too many commits have gone in this PR and it would be hard to undo those changes, split branches and redo again.

luciferreeves avatar Jan 28 '22 20:01 luciferreeves

@pkuczynski Maybe from next time, I will target smaller issues/PRs. Too many commits have gone in this PR and it would be hard to undo those changes, split branches and redo again.

You don't need to split branches. Just create a new one and copy 3 files from this PR regarding date, create new PR from them, and delete in this PR. We don't need the whole commit/review history. This way you increase a chance that one of them will be merged faster.

pkuczynski avatar Jan 28 '22 20:01 pkuczynski

I see. Although, I still fail to see the usage of 2 PRs now since this once is almost completed review and is targeted for v6.2 and won't be merged anytime soon either. A lot of PRs target multiple features/bugs and doing multiple things in the same PR is not something new. However, I will try to split the PRs if I get time.

luciferreeves avatar Jan 28 '22 21:01 luciferreeves

Okay, everything is fixed now. Instead of datatype.number() as suggested, I used this.faker.datatype.float({ min: 0, max: 1, precision: 0.0000000000000001 }) to replicate the Math.random() behavior.

Can you explain why? AFAIK datatype.number should return a value between startDate and endDate.

ST-DDT avatar Jan 28 '22 23:01 ST-DDT

I replaced your return statement with

return new Date(
      this.faker.datatype.number({
        min: startDate,
        max: endDate,
      })
    );

And the tests still pass.

ST-DDT avatar Jan 28 '22 23:01 ST-DDT

Okay, done. I used:

return new Date(
  this.faker.datatype.number({
    min: startDate,
    max: endDate,
  })
);

luciferreeves avatar Jan 29 '22 00:01 luciferreeves

I have resolved all the notified issues, and added comments to the unresolved ones.

luciferreeves avatar Jan 29 '22 00:01 luciferreeves

Tests pass on my system but are failing here. I am looking into it. Please disregard the review request.

luciferreeves avatar Jan 29 '22 20:01 luciferreeves

You might have to rebase.

ST-DDT avatar Jan 29 '22 20:01 ST-DDT

Okay, I think this is now ready to be reviewed.

luciferreeves avatar Jan 30 '22 16:01 luciferreeves

Codecov Report

Merging #182 (8509fbe) into next (d363258) will decrease coverage by 0.00%. The diff coverage is 93.75%.

:exclamation: Current head 8509fbe differs from pull request most recent head 78878b0. Consider uploading reports for the commit 78878b0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             next     #182      +/-   ##
==========================================
- Coverage   99.64%   99.63%   -0.01%     
==========================================
  Files        2213     2176      -37     
  Lines      238637   237668     -969     
  Branches     1014     1014              
==========================================
- Hits       237783   236812     -971     
- Misses        833      835       +2     
  Partials       21       21              
Impacted Files Coverage Δ
src/definitions/person.ts 0.00% <0.00%> (ø)
src/locales/en/person/index.ts 100.00% <100.00%> (ø)
src/locales/en/person/western_zodiac_sign.ts 100.00% <100.00%> (ø)
src/modules/person/index.ts 100.00% <100.00%> (ø)
src/locales/index.ts 100.00% <0.00%> (ø)
src/modules/git/index.ts 100.00% <0.00%> (ø)
src/locales/dv/company/adjective.ts
src/locales/dv/location/city_suffix.ts
src/locales/dv/location/postcode.ts
src/locales/dv/cell_phone/formats.ts
... and 34 more

codecov[bot] avatar Feb 08 '22 17:02 codecov[bot]

Could you please also include the source for the zodiac sign dates above the switch case? There seems to be different dates based on the page you visit (e.g. German wiki vs English wiki). 😱

ST-DDT avatar Feb 09 '22 22:02 ST-DDT

We're starting work on the v6.2 milestone, but this PR needs a rebase. Please rebase and resolve all conflicts. Until then, we're moving it to the v6 milestone, which now serves as the "v6-Backlog". If this PR no longer contains any conflicts and can certainly be a target for the next release, we will move it to the then active milestone v6.x.

Shinigami92 avatar Apr 05 '22 14:04 Shinigami92

I updated the branch and will fix remaining issues.

ST-DDT avatar Apr 30 '22 20:04 ST-DDT

Docs Preview (Click to expand)

grafik

grafik

ST-DDT avatar May 04 '22 23:05 ST-DDT

Please check whether that FakerError is generally unsafe to use or just from inside our tests.

at least in the current version (v6.3.1) it is possible 🤔 image

if you like you could add an extra test that checks importing the error, but I trust esbuild 🤷

Shinigami92 avatar May 05 '22 08:05 Shinigami92

if you like you could add an extra test that checks importing the error, but I trust esbuild

It might be only an issue if we use it from the faker modules itself (circular reference: module -> [email protected] -> faker -> module).

ST-DDT avatar May 05 '22 09:05 ST-DDT

@faker-js/members @faker-js/maintainers: As per @Shinigami92's request: Should we have faker.zodiac.sign(birthday) as option or is that too much of a utility method. (We would still have faker.zodiac.sign())

ST-DDT avatar May 05 '22 10:05 ST-DDT

@faker-js/members @faker-js/maintainers: As per @Shinigami92's request: Should we have faker.zodiac.sign(birthday) as option or is that too much of a utility method. (We would still have faker.zodiac.sign())

Hmm, I don't know. I'm leaning towards it being too much of a utility method, but let's see what the other members of the team think.

import-brain avatar May 05 '22 11:05 import-brain