@@ -16,7 +16,7 @@ export class AliasAccessor {
1616 public constructor ( private globalInfo : GlobalInfo ) { }
1717
1818 /**
19- * Returns all the aliases for all the usernames
19+ * Returns all the aliases for all the values
2020 */
2121 public getAll ( ) : SfAliases ;
2222 /**
@@ -28,9 +28,9 @@ export class AliasAccessor {
2828 public getAll ( entity ?: Aliasable ) : string [ ] | SfAliases {
2929 const all = this . globalInfo . get ( SfInfoKeys . ALIASES ) || { } ;
3030 if ( entity ) {
31- const username = this . getNameOf ( entity ) ;
31+ const value = this . getNameOf ( entity ) ;
3232 return Object . entries ( all )
33- . filter ( ( entry ) => entry [ 1 ] === username )
33+ . filter ( ( entry ) => entry [ 1 ] === value )
3434 . map ( ( entry ) => entry [ 0 ] ) ;
3535 } else {
3636 return all ;
@@ -46,6 +46,15 @@ export class AliasAccessor {
4646 return this . getAll ( entity ) . find ( ( alias ) => alias ) ?? null ;
4747 }
4848
49+ /**
50+ * Returns the value that corresponds to the given alias if it exists
51+ *
52+ * @param alias the alias that corresponds to a value
53+ */
54+ public getValue ( alias : string ) : Nullable < string > {
55+ return this . getAll ( ) [ alias ] ?? null ;
56+ }
57+
4958 /**
5059 * Returns the username that corresponds to the given alias if it exists
5160 *
@@ -55,6 +64,20 @@ export class AliasAccessor {
5564 return this . getAll ( ) [ alias ] ?? null ;
5665 }
5766
67+ /**
68+ * If the provided string is an alias, it returns the corresponding value.
69+ * If the provided string is not an alias, we assume that the provided string
70+ * is the value and return it.
71+ *
72+ * This method is helpful when you don't know if the string you have is a value
73+ * or an alias.
74+ *
75+ * @param valueOrAlias a string that might be a value or might be an alias
76+ */
77+ public resolveValue ( valueOrAlias : string ) : string {
78+ return this . getValue ( valueOrAlias ) ?? valueOrAlias ;
79+ }
80+
5881 /**
5982 * If the provided string is an alias, it returns the corresponding username.
6083 * If the provided string is not an alias, we assume that the provided string
@@ -76,8 +99,8 @@ export class AliasAccessor {
7699 * @param entity the aliasable entity that's being aliased
77100 */
78101 public set ( alias : string , entity : Aliasable ) : void {
79- const username = this . getNameOf ( entity ) ;
80- this . globalInfo . set ( `${ SfInfoKeys . ALIASES } ["${ alias } "]` , username ) ;
102+ const value = this . getNameOf ( entity ) ;
103+ this . globalInfo . set ( `${ SfInfoKeys . ALIASES } ["${ alias } "]` , value ) ;
81104 }
82105
83106 /**
@@ -87,8 +110,8 @@ export class AliasAccessor {
87110 * @param entity the aliasable entity that's being aliased
88111 */
89112 public update ( alias : string , entity : Aliasable ) : void {
90- const username = this . getNameOf ( entity ) ;
91- this . globalInfo . update ( `${ SfInfoKeys . ALIASES } ["${ alias } "]` , username ) ;
113+ const value = this . getNameOf ( entity ) ;
114+ this . globalInfo . update ( `${ SfInfoKeys . ALIASES } ["${ alias } "]` , value ) ;
92115 }
93116
94117 public unset ( alias : string ) : void {
0 commit comments