-
-
Notifications
You must be signed in to change notification settings - Fork 885
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: add ability to define number of generated extensions in system.filePath #395
Changes from 3 commits
dc569ba
d706f18
a0f7905
4edadf2
1cddd1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,12 +174,32 @@ export class System { | |
/** | ||
* Returns a file path. | ||
* | ||
* @param ext Defines number of generated extensions. Defaults to `1`. | ||
* | ||
* @example | ||
* faker.system.filePath() // '/usr/local/src/money.dotx' | ||
* faker.system.filePath(0) // '/usr/local/src/money' | ||
* faker.system.filePath(2) // '/usr/local/src/money.dotx.zip' | ||
*/ | ||
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file. | ||
filePath(): string { | ||
return `${this.directoryPath()}/${this.fileName()}`; | ||
filePath(ext = 1): string { | ||
const path = `${this.directoryPath()}/${this.fileName()}`; | ||
|
||
switch (true) { | ||
case ext === 0: | ||
return path.slice(0, path.lastIndexOf('.')); | ||
|
||
case ext === 1: | ||
return path; | ||
|
||
default: { | ||
const extensions = new Array(ext - 1) | ||
.fill('') | ||
.map(() => this.fileExt()) | ||
.join('.'); | ||
|
||
return `${path}.${extensions}`; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move this logic into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, let me do that... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, Mayne I should do that in a separate PR not to mix concerts @ST-DDT ? It would be also better to spot on the changelog? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is about changing the number of generated extensions,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we just need to adjust the PR title a little bit 🤷 |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make it also possible to set the nested dir depth?
So we would need to forward an arg to
directoryPath
So IMO we should use an option here
{extCount = 1, dirCount: 1-3?}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, why not! :) I can do that once #300 is merged, ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, for now stick to a fixed number for each of them.
In a later feature we can introduce
number | { min, max }
(that might be handy for multiple locations)Words, Lorem, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directoryPath
does not take any params. I would propose to extend it in a separate PR not to mix the concerns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directory path in separate PR: OK