Skip to content

Commit 81ddf88

Browse files
authored
Use # field operator for private fields (#32)
1 parent 44ba19f commit 81ddf88

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

src/EmailAddress.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -223,33 +223,33 @@ export class EmailAddress implements IEquatable, IJsonStringifyable {
223223
* you will normally use EmailAddress.parse(string) or EmailAddress.tryParse(string).
224224
*/
225225
private constructor(value: string) {
226-
this.value = value;
226+
this.#value = value;
227227
}
228228

229229
/**
230230
* The underlying value.
231231
*/
232-
private readonly value: string;
232+
readonly #value: string;
233233

234234
/**
235235
* The length of the email address.
236236
*/
237237
public get length(): number {
238-
return this.value.length;
238+
return this.#value.length;
239239
}
240240

241241
/**
242242
* Indicates if the email address is IP-based.
243243
*/
244244
public get isIPBased(): boolean {
245-
return this.value.endsWith(']');
245+
return this.#value.endsWith(']');
246246
}
247247

248248
/**
249249
* Returns a string that represents the current email address.
250250
*/
251251
public toString(): string {
252-
return this.value;
252+
return this.#value;
253253
}
254254

255255
/**
@@ -258,14 +258,14 @@ export class EmailAddress implements IEquatable, IJsonStringifyable {
258258
*/
259259
public equals(other: unknown): boolean {
260260
return other instanceof (EmailAddress)
261-
&& other.value === this.value;
261+
&& other.#value === this.#value;
262262
}
263263

264264
/**
265265
* Returns a JSON representation of the email address.
266266
*/
267267
public toJSON(): string {
268-
return this.value;
268+
return this.#value;
269269
}
270270

271271
/**

src/Guid.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,45 @@ export class Guid implements IEquatable, IFormattable, IJsonStringifyable {
1111
* you will normally use Guid.newGuid() or Guid.parse(string).
1212
*/
1313
private constructor(value: string) {
14-
this.value = value;
14+
this.#value = value;
1515
}
1616

1717
/**
1818
* The underlying value.
1919
*/
20-
private readonly value: string;
20+
readonly #value: string;
2121

2222
/**
2323
* Returns a string that represents the current GUID.
2424
*/
2525
public toString(): string {
26-
return this.value;
26+
return this.#value;
2727
}
2828
/**
2929
* Returns a string that represents the current GUID.
3030
*/
3131
public format(f?: string): string {
3232
switch (f) {
33-
case 'B': return '{' + this.value + '}';
34-
case 'b': return '{' + this.value.toLowerCase() + '}';
35-
case 'S': return this.value.replace(/-/g, '');
36-
case 's': return this.value.replace(/-/g, '').toLowerCase();
37-
case 'l': return this.value.toLowerCase();
38-
case 'U': case 'u': default: return this.value;
33+
case 'B': return '{' + this.#value + '}';
34+
case 'b': return '{' + this.#value.toLowerCase() + '}';
35+
case 'S': return this.#value.replace(/-/g, '');
36+
case 's': return this.#value.replace(/-/g, '').toLowerCase();
37+
case 'l': return this.#value.toLowerCase();
38+
case 'U': case 'u': default: return this.#value;
3939
}
4040
}
4141
/**
4242
* Returns a JSON representation of the GUID.
4343
*/
4444
public toJSON(): string {
45-
return this.value;
45+
return this.#value;
4646
}
4747

4848
/**
4949
* Returns the version of the GUID.
5050
*/
5151
public get version(): number {
52-
return parseInt(this.value.slice(14, 15));
52+
return parseInt(this.#value.slice(14, 15));
5353
}
5454

5555
/**
@@ -58,7 +58,7 @@ export class Guid implements IEquatable, IFormattable, IJsonStringifyable {
5858
*/
5959
public equals(other: unknown): boolean {
6060
return other instanceof (Guid)
61-
&& other.value === this.value;
61+
&& other.#value === this.#value;
6262
}
6363

6464
/**
@@ -125,7 +125,7 @@ export class Guid implements IEquatable, IFormattable, IJsonStringifyable {
125125
if (seed !== null && seed instanceof (Guid)) {
126126
let merged = '';
127127
for (let i = 0; i < 36; i++) {
128-
const l = '0123456789ABCDEF'.indexOf(seed.value.charAt(i));
128+
const l = '0123456789ABCDEF'.indexOf(seed.#value.charAt(i));
129129
const r = '0123456789ABCDEF'.indexOf(v.charAt(i));
130130
merged += l === -1 || r === -1 ? v.charAt(i) : '0123456789ABCDEF'.charAt(l ^ r);
131131
}

src/InternationalBankAccountNumber.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ export class InternationalBankAccountNumber implements IEquatable, IFormattable,
77
* you will normally use InternationalBankAccountNumber.parse(string).
88
*/
99
private constructor(value: string) {
10-
this.value = value;
10+
this.#value= value;
1111
}
1212

1313
/**
1414
* The underlying value.
1515
*/
16-
private readonly value;
16+
readonly #value;
1717

1818
/**
1919
* Gets the country of the IBAN.
2020
*/
2121
public get country() {
22-
return this.value.slice(0, 2);
22+
return this.#value.slice(0, 2);
2323
}
2424

2525
/**
2626
* Gets the length of the IBAN.
2727
*/
2828
public get length() {
29-
return this.value.length;
29+
return this.#value.length;
3030
}
3131

3232
/**
3333
* Returns a string that represents the current IBAN.
3434
*/
3535
public toString(): string {
36-
return this.value;
36+
return this.#value;
3737
}
3838

3939
/**
@@ -51,8 +51,8 @@ export class InternationalBankAccountNumber implements IEquatable, IFormattable,
5151
*/
5252
public format(f?: string): string {
5353
switch (f) {
54-
case 'u': case 'm': return this.value.toLowerCase();
55-
case 'U': case 'M': return this.value;
54+
case 'u': case 'm': return this.#value.toLowerCase();
55+
case 'U': case 'M': return this.#value;
5656
case 'f': return this.humanReadable(' ').toLowerCase();
5757
case 'F': return this.humanReadable(' ');
5858
case 'h': return this.humanReadable(' ').toLowerCase();
@@ -61,7 +61,7 @@ export class InternationalBankAccountNumber implements IEquatable, IFormattable,
6161
}
6262

6363
private humanReadable(ch: string): string {
64-
return this.value.replace(/.{4}(?!$)/g, '$&' + ch);
64+
return this.#value.replace(/.{4}(?!$)/g, '$&' + ch);
6565
}
6666

6767
/**
@@ -70,14 +70,14 @@ export class InternationalBankAccountNumber implements IEquatable, IFormattable,
7070
*/
7171
public equals(other: unknown): boolean {
7272
return other instanceof (InternationalBankAccountNumber)
73-
&& other.value === this.value;
73+
&& other.#value === this.#value;
7474
}
7575

7676
/**
7777
* Returns a JSON representation of the IBAN.
7878
*/
7979
public toJSON(): string {
80-
return this.value;
80+
return this.#value;
8181
}
8282

8383
/**

src/PostalCode.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ export class PostalCode implements IEquatable, IFormattable, IJsonStringifyable
3333
* PostalCode use PostalCode.parse(string).
3434
*/
3535
private constructor(value: string) {
36-
this.value = value;
36+
this.#value = value;
3737
}
3838

3939
/**
4040
* The underlying value.
4141
*/
42-
private readonly value: string;
42+
readonly #value: string;
4343

4444
/**
4545
* Gets the length of the postal code.
4646
*/
4747
public get length() {
48-
return this.value.length;
48+
return this.#value.length;
4949
}
5050

5151
/**
5252
* Returns a string that represents the current postal code.
5353
*/
5454
public toString(): string {
55-
return this.value;
55+
return this.#value;
5656
}
5757

5858
/**
@@ -61,16 +61,16 @@ export class PostalCode implements IEquatable, IFormattable, IJsonStringifyable
6161
public format(f: string): string {
6262
const info = PostalCode.Infos.get(f);
6363

64-
return info?.isValid(this.value)
65-
? info.format(this.value)
66-
: this.value;
64+
return info?.isValid(this.#value)
65+
? info.format(this.#value)
66+
: this.#value;
6767
}
6868

6969
/**
7070
* Returns a JSON representation of the postal code.
7171
*/
7272
public toJSON(): string {
73-
return this.value;
73+
return this.#value;
7474
}
7575

7676
/**
@@ -79,7 +79,7 @@ export class PostalCode implements IEquatable, IFormattable, IJsonStringifyable
7979
*/
8080
public equals(other: unknown): boolean {
8181
return other instanceof (PostalCode)
82-
&& other.value === this.value;
82+
&& other.#value === this.#value;
8383
}
8484

8585
/**
@@ -89,7 +89,7 @@ export class PostalCode implements IEquatable, IFormattable, IJsonStringifyable
8989
*/
9090
public isValid(country: string): boolean {
9191
const info = PostalCode.Infos.get(country);
92-
return info?.isValid(this.value) === true;
92+
return info?.isValid(this.#value) === true;
9393
}
9494

9595
/**

0 commit comments

Comments
 (0)