@e280/stz 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/s/dispenser.ts +5 -3
- package/x/dispenser.d.ts +4 -4
- package/x/dispenser.js +3 -1
- package/x/dispenser.js.map +1 -1
package/package.json
CHANGED
package/s/dispenser.ts
CHANGED
|
@@ -4,7 +4,7 @@ export class Dispenser<T> {
|
|
|
4
4
|
#content: T[] = []
|
|
5
5
|
|
|
6
6
|
constructor(private getRefill: () => T[]) {
|
|
7
|
-
this.#
|
|
7
|
+
this.#refillWhenEmpty()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/** see what's currently available in the dispenser */
|
|
@@ -15,6 +15,8 @@ export class Dispenser<T> {
|
|
|
15
15
|
#refillWhenEmpty() {
|
|
16
16
|
if (this.#content.length === 0)
|
|
17
17
|
this.#content = [...this.getRefill()]
|
|
18
|
+
if (this.#content.length === 0)
|
|
19
|
+
throw new Error("dispenser's getRefill returned an empty array")
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/** take everything that's left, and refill */
|
|
@@ -35,13 +37,13 @@ export class Dispenser<T> {
|
|
|
35
37
|
/** take out the first item */
|
|
36
38
|
takeFirst() {
|
|
37
39
|
this.#refillWhenEmpty()
|
|
38
|
-
return this.#content.shift()
|
|
40
|
+
return this.#content.shift()! as T
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/** take out the last item */
|
|
42
44
|
takeLast() {
|
|
43
45
|
this.#refillWhenEmpty()
|
|
44
|
-
return this.#content.pop()
|
|
46
|
+
return this.#content.pop()! as T
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** @alias takeFirst */
|
package/x/dispenser.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export declare class Dispenser<T> {
|
|
|
10
10
|
/** take a random item out of the dispenser */
|
|
11
11
|
takeRandom(): T;
|
|
12
12
|
/** take out the first item */
|
|
13
|
-
takeFirst(): T
|
|
13
|
+
takeFirst(): T;
|
|
14
14
|
/** take out the last item */
|
|
15
|
-
takeLast(): T
|
|
15
|
+
takeLast(): T;
|
|
16
16
|
/** @alias takeFirst */
|
|
17
|
-
shift: () => T
|
|
17
|
+
shift: () => T;
|
|
18
18
|
/** @alias takeLast */
|
|
19
|
-
pop: () => T
|
|
19
|
+
pop: () => T;
|
|
20
20
|
}
|
package/x/dispenser.js
CHANGED
|
@@ -4,7 +4,7 @@ export class Dispenser {
|
|
|
4
4
|
#content = [];
|
|
5
5
|
constructor(getRefill) {
|
|
6
6
|
this.getRefill = getRefill;
|
|
7
|
-
this.#
|
|
7
|
+
this.#refillWhenEmpty();
|
|
8
8
|
}
|
|
9
9
|
/** see what's currently available in the dispenser */
|
|
10
10
|
get currentStock() {
|
|
@@ -13,6 +13,8 @@ export class Dispenser {
|
|
|
13
13
|
#refillWhenEmpty() {
|
|
14
14
|
if (this.#content.length === 0)
|
|
15
15
|
this.#content = [...this.getRefill()];
|
|
16
|
+
if (this.#content.length === 0)
|
|
17
|
+
throw new Error("dispenser's getRefill returned an empty array");
|
|
16
18
|
}
|
|
17
19
|
/** take everything that's left, and refill */
|
|
18
20
|
takeAll() {
|
package/x/dispenser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispenser.js","sourceRoot":"","sources":["../s/dispenser.ts"],"names":[],"mappings":"AACA,uDAAuD;AACvD,MAAM,OAAO,SAAS;IAGD;IAFpB,QAAQ,GAAQ,EAAE,CAAA;IAElB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QACvC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"dispenser.js","sourceRoot":"","sources":["../s/dispenser.ts"],"names":[],"mappings":"AACA,uDAAuD;AACvD,MAAM,OAAO,SAAS;IAGD;IAFpB,QAAQ,GAAQ,EAAE,CAAA;IAElB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QACvC,IA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