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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(date): introduce faker.defaultRefDate and setDefaultRefDate #1757

Merged
merged 15 commits into from
Jan 24, 2023

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Jan 18, 2023

Fixes #859

This PR introduces the faker.setDefaultRefDate method, that can be used to configure the default refDate fallback value.

  • fakerjs.dev: grafik (will update when the next release is created)
  • next.fakerjs.dev: grafik (will update when the next PR is merged)
  • dev: grafik (and it will stay like this)

I'm not very happy with both the name and implementation.

  • For the name, I also considered refDateFallbackSource.
  • For the implementation, I considered adding it directly to the date module, but then I would need to pass the fallback to the toDate function that is located outside.
    • Adding it directly to the DateModule would complicate Faker.fork and Faker.derive.
    • Adding toDate to the module directly causes some issues as well (IIRC)
    • My current approach is adding this as MVP and then move these kind of configs to fakerCore.config{dateRefDateFallbackSource, helpersUniqueFallbackStore, ...} or something similar. That way, it can share or not share these things between faker instances, configure it globally or per method (it's bound fakerCore)
  • I'm unsure how I can document the Defaults to `refDateSource()`. in an easier to understand way.

Any feedback or suggestions are welcome!

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug m: date Something is referring to the date module labels Jan 18, 2023
@ST-DDT ST-DDT requested review from a team January 18, 2023 23:49
@ST-DDT ST-DDT self-assigned this Jan 18, 2023
@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #1757 (4fa1a23) into next (28a9848) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #1757   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files        2340     2340           
  Lines      242624   242653   +29     
  Branches     1103     1110    +7     
=======================================
+ Hits       241772   241801   +29     
  Misses        831      831           
  Partials       21       21           
Impacted Files Coverage Δ
src/faker.ts 95.48% <100.00%> (+0.36%) ⬆️
src/modules/date/index.ts 99.79% <100.00%> (+<0.01%) ⬆️
src/modules/git/index.ts 100.00% <100.00%> (ø)

@Shinigami92
Copy link
Member

I think refDateSource or defaultRefDate is a good name
I didn't thought enough yet, but the idea with having a faker.config sounds good to me 🤔 (later PR / iteration)

But I would like to have (for now) a faker.defaultRefDate
Not sure if we already want to mix it together with "tree-shakable" "global-faker-npm-module" ideas yet

IMO for now it should be next to faker.seed like the issue author mentioned

src/faker.ts Outdated Show resolved Hide resolved
src/faker.ts Outdated Show resolved Hide resolved
@ST-DDT ST-DDT marked this pull request as ready for review January 23, 2023 20:24
@ST-DDT ST-DDT requested review from Shinigami92 and a team January 23, 2023 20:25
@ST-DDT ST-DDT changed the title feat(date): introduce refDateSource feat(date): introduce faker.defaultRefDate and faker.setDefaultRefDate Jan 23, 2023
@ST-DDT ST-DDT mentioned this pull request Jan 23, 2023
4 tasks
@ST-DDT ST-DDT requested a review from a team January 23, 2023 22:35
@ST-DDT ST-DDT changed the title feat(date): introduce faker.defaultRefDate and faker.setDefaultRefDate feat(date): introduce faker.defaultRefDate and setDefaultRefDate Jan 24, 2023
@ST-DDT ST-DDT merged commit 3a44d5f into next Jan 24, 2023
@ST-DDT ST-DDT deleted the feat/date/custom-ref-date-default branch January 24, 2023 21:51
matthewmayer pushed a commit to matthewmayer/faker that referenced this pull request Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature m: date Something is referring to the date module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

feat(date): introduce global refDate instead of passing it every time
3 participants