Created
May 17, 2020 21:00
-
-
Save clintonyeb/da39cb89198e3ffc689f7ad39bfbe130 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* interfaces fill the role of naming types, | |
* and are a powerful way of defining contracts within your code as well as contracts with code outside of your project. | |
*/ | |
export interface ICurrency { | |
readonly label: string; | |
readonly value: string; | |
readonly currency_name: string; | |
} | |
/** | |
* create type for Array | |
*/ | |
export type CurrencyPairs = Array<ICurrency>; | |
/** | |
* create new instance of property that allow to modify elements | |
*/ | |
export class Currency implements ICurrency { | |
public readonly label: string; | |
public readonly value: string; | |
public readonly currency_name: string; | |
constructor(data: ICurrency) { | |
this.currency_name = data.currency_name; | |
this.value = data.currency_name; | |
/** | |
* modify currency_name, to add '/' between currency name | |
*/ | |
this.label = data.currency_name.replace(new RegExp(`^(.{${3}})(.)`), `$1${'/'}$2`); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment