@oscarpalmer/mora 0.20.0 → 0.21.0

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/dist/mora.full.js CHANGED
@@ -419,8 +419,14 @@ class ReactiveArray extends Reactive {
419
419
  map(callback) {
420
420
  return computed(() => this.get().map(callback));
421
421
  }
422
- peek(length) {
423
- return length === true ? this.#size.peek() : [...this.state.value];
422
+ peek(value) {
423
+ if (value === true) {
424
+ return this.#size.peek();
425
+ }
426
+ if (typeof value === 'number') {
427
+ return this.state.value.at(value);
428
+ }
429
+ return [...this.state.value];
424
430
  }
425
431
  /**
426
432
  * Remove and return the last item of the array
@@ -76,8 +76,14 @@ class ReactiveArray extends value_reactive.Reactive {
76
76
  map(callback) {
77
77
  return value_computed.computed(() => this.get().map(callback));
78
78
  }
79
- peek(length) {
80
- return length === true ? __privateGet(this, _size).peek() : [...this.state.value];
79
+ peek(value) {
80
+ if (value === true) {
81
+ return __privateGet(this, _size).peek();
82
+ }
83
+ if (typeof value === "number") {
84
+ return this.state.value.at(value);
85
+ }
86
+ return [...this.state.value];
81
87
  }
82
88
  /**
83
89
  * Remove and return the last item of the array
@@ -74,8 +74,14 @@ class ReactiveArray extends Reactive {
74
74
  map(callback) {
75
75
  return computed(() => this.get().map(callback));
76
76
  }
77
- peek(length) {
78
- return length === true ? __privateGet(this, _size).peek() : [...this.state.value];
77
+ peek(value) {
78
+ if (value === true) {
79
+ return __privateGet(this, _size).peek();
80
+ }
81
+ if (typeof value === "number") {
82
+ return this.state.value.at(value);
83
+ }
84
+ return [...this.state.value];
79
85
  }
80
86
  /**
81
87
  * Remove and return the last item of the array
package/package.json CHANGED
@@ -54,5 +54,5 @@
54
54
  },
55
55
  "type": "module",
56
56
  "types": "./types/index.d.ts",
57
- "version": "0.20.0"
57
+ "version": "0.21.0"
58
58
  }
@@ -112,13 +112,23 @@ export class ReactiveArray<Item> extends Reactive<Item[], Item> {
112
112
  */
113
113
  peek(): Item[];
114
114
 
115
+ peek(index: number): Item | undefined;
116
+
115
117
  /**
116
118
  * Get the length of the array _(without reactivity)_
117
119
  */
118
120
  peek(length: true): number;
119
121
 
120
- peek(length?: unknown): Item[] | number {
121
- return length === true ? this.#size.peek() : [...this.state.value];
122
+ peek(value?: unknown): unknown {
123
+ if (value === true) {
124
+ return this.#size.peek();
125
+ }
126
+
127
+ if (typeof value === 'number') {
128
+ return this.state.value.at(value);
129
+ }
130
+
131
+ return [...this.state.value];
122
132
  }
123
133
 
124
134
  /**
@@ -111,6 +111,7 @@ declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
111
111
  * @inheritdoc
112
112
  */
113
113
  peek(): Item[];
114
+ peek(index: number): Item | undefined;
114
115
  /**
115
116
  * Get the length of the array _(without reactivity)_
116
117
  */
@@ -115,6 +115,7 @@ declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
115
115
  * @inheritdoc
116
116
  */
117
117
  peek(): Item[];
118
+ peek(index: number): Item | undefined;
118
119
  /**
119
120
  * Get the length of the array _(without reactivity)_
120
121
  */
package/types/index.d.cts CHANGED
@@ -127,6 +127,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
127
127
  * @inheritdoc
128
128
  */
129
129
  peek(): Item[];
130
+ peek(index: number): Item | undefined;
130
131
  /**
131
132
  * Get the length of the array _(without reactivity)_
132
133
  */
@@ -103,6 +103,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
103
103
  * @inheritdoc
104
104
  */
105
105
  peek(): Item[];
106
+ peek(index: number): Item | undefined;
106
107
  /**
107
108
  * Get the length of the array _(without reactivity)_
108
109
  */
@@ -40,6 +40,7 @@ export declare class ReactiveArray<Item> extends Reactive<Item[], Item> {
40
40
  * @inheritdoc
41
41
  */
42
42
  peek(): Item[];
43
+ peek(index: number): Item | undefined;
43
44
  /**
44
45
  * Get the length of the array _(without reactivity)_
45
46
  */