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(helpers): fake from array #1453

Merged
merged 28 commits into from
Dec 23, 2022
Merged

feat(helpers): fake from array #1453

merged 28 commits into from
Dec 23, 2022

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Oct 15, 2022

Fixes #1446

Example Usage:

faker.helpers.fake(['A: {{name.firstName}}', 'B: {{name.lastName}}']) // 'A: Barry'
Docs Preview

grafik

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug m: helpers Something is referring to the helpers module labels Oct 15, 2022
@ST-DDT ST-DDT requested review from a team October 15, 2022 00:25
@ST-DDT ST-DDT self-assigned this Oct 15, 2022
@codecov
Copy link

codecov bot commented Oct 15, 2022

Codecov Report

Merging #1453 (d496483) into next (4ce8e98) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff            @@
##             next    #1453    +/-   ##
========================================
  Coverage   99.64%   99.65%            
========================================
  Files        2244     2244            
  Lines      240413   240509    +96     
  Branches     1071     1076     +5     
========================================
+ Hits       239562   239674   +112     
+ Misses        830      814    -16     
  Partials       21       21            
Impacted Files Coverage Δ
src/modules/company/index.ts 100.00% <100.00%> (ø)
src/modules/helpers/index.ts 99.15% <100.00%> (+0.12%) ⬆️
src/modules/location/index.ts 99.77% <100.00%> (-0.01%) ⬇️
src/modules/internet/user-agent.ts 91.08% <0.00%> (+4.32%) ⬆️

pkuczynski
pkuczynski previously approved these changes Oct 15, 2022
src/modules/helpers/index.ts Outdated Show resolved Hide resolved
test/helpers.spec.ts Show resolved Hide resolved
@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Oct 16, 2022
src/modules/helpers/index.ts Outdated Show resolved Hide resolved
@ST-DDT ST-DDT removed the s: needs decision Needs team/maintainer decision label Oct 22, 2022
@ST-DDT ST-DDT requested review from Shinigami92 and a team October 24, 2022 21:24
Copy link
Member

@xDivisionByZerox xDivisionByZerox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I don't like this change, as it adds a lot of "unnecessary" complexity on top of an already complex function.
But I don't see anything wrong with the implementation itself.

@ST-DDT
Copy link
Member Author

ST-DDT commented Oct 31, 2022

@xDivisionByZerox Would you prefer a separate method? Any suggestions for a name? fakeOneOf?

src/modules/helpers/index.ts Outdated Show resolved Hide resolved
src/modules/helpers/index.ts Outdated Show resolved Hide resolved
@xDivisionByZerox
Copy link
Member

xDivisionByZerox commented Oct 31, 2022

@xDivisionByZerox Would you prefer a separate method? Any suggestions for a name? fakeOneOf?

A separate method would definitely satisfy the single responsibility principle. But I guess that would negate the overall code improvement you had in mind with this changes? As now every function is required to first check the type and then call the according function:

function foo(options: string | string[]) {
  return Array.isArray(options) 
    ? this.faker.helpers.fakeOneOf(options) 
    : this faker.helpers.fake(options);
}

ST-DDT and others added 2 commits October 31, 2022 14:05
@ST-DDT ST-DDT changed the title feat: fake from array feat(helpers): fake from array Nov 3, 2022
@xDivisionByZerox xDivisionByZerox requested a review from a team December 23, 2022 16:26
@ST-DDT ST-DDT merged commit 75a31f6 into next Dec 23, 2022
@ST-DDT ST-DDT deleted the feat/fake-from-array branch December 23, 2022 19:42
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: helpers Something is referring to the helpers 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.

Introduce fakeArrayElement helpers
5 participants