-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: generate tag with min 2 digits
- Loading branch information
1 parent
517026f
commit 34d0310
Showing
6 changed files
with
58 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class TagBuilder { | ||
private tagTemplate: string; | ||
private prefix: string | undefined; | ||
|
||
constructor(tagTemplate: string) { | ||
this.tagTemplate = `${tagTemplate}`; // Deep copy | ||
} | ||
|
||
private static format(value: number) { | ||
return value < 10 ? `0${value}` : `${value}`; | ||
} | ||
|
||
public inject(templatePart: string, value: number) { | ||
this.tagTemplate = this.tagTemplate.replaceAll( | ||
templatePart, | ||
TagBuilder.format(value) | ||
); | ||
return this; | ||
} | ||
|
||
public addPrefix(prefix: string) { | ||
this.prefix = prefix; | ||
return this; | ||
} | ||
|
||
public build() { | ||
if (!this.prefix) { | ||
return this.tagTemplate; | ||
} | ||
return `${this.prefix}${this.tagTemplate}`; | ||
} | ||
} | ||
|
||
export default TagBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters