Skip to content

Commit 861a364

Browse files
committed
Memoize and return on one line
1 parent 7f06280 commit 861a364

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

lib/index.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,17 @@ class Postcode {
225225

226226
incode(): string | null {
227227
if (this._incode) return this._incode;
228-
this._incode = toIncode(this._raw);
229-
return this._incode;
228+
return (this._incode = toIncode(this._raw));
230229
}
231230

232231
outcode(): string | null {
233232
if (this._outcode) return this._outcode;
234-
this._outcode = toOutcode(this._raw);
235-
return this._outcode;
233+
return (this._outcode = toOutcode(this._raw));
236234
}
237235

238236
area(): string | null {
239237
if (this._area) return this._area;
240-
this._area = toArea(this._raw);
241-
return this._area;
238+
return (this._area = toArea(this._raw));
242239
}
243240

244241
district(): string | null {
@@ -248,20 +245,17 @@ class Postcode {
248245

249246
subDistrict(): string | null {
250247
if (this._subDistrict) return this._subDistrict;
251-
this._subDistrict = toSubDistrict(this._raw);
252-
return this._subDistrict;
248+
return (this._subDistrict = toSubDistrict(this._raw));
253249
}
254250

255251
sector(): string | null {
256252
if (this._sector) return this._sector;
257-
this._sector = toSector(this._raw);
258-
return this._sector;
253+
return (this._sector = toSector(this._raw));
259254
}
260255

261256
unit(): string | null {
262257
if (this._unit) return this._unit;
263-
this._unit = toUnit(this._raw);
264-
return this._unit;
258+
return (this._unit = toUnit(this._raw));
265259
}
266260

267261
normalise(): string | null {

0 commit comments

Comments
 (0)