Skip to content

Commit fb33e0c

Browse files
committed
docs: added list of methods/properties
1 parent 5d30929 commit fb33e0c

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

ArrayDatabase.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export declare class ArrayDatabase<T = any> {
1818
some(callbackfn: (value: T) => boolean): boolean;
1919
every(callbackfn: (value: T) => boolean): boolean;
2020
[Symbol.iterator](): IterableIterator<T>;
21-
private trySave;
2221
get size(): number;
22+
private trySave;
2323
private load;
2424
private unload;
2525
private get keyPrefix();

ArrayDatabase.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export class ArrayDatabase {
9090
[Symbol.iterator]() {
9191
return this.values();
9292
}
93+
get size() {
94+
return this.cache.reduce((acc, arr) => acc + arr.length, 0);
95+
}
9396
trySave(values, swap = []) {
9497
let sizeOK = true;
9598
const stringified = JSON.stringify(values);
@@ -114,9 +117,6 @@ export class ArrayDatabase {
114117
this.trySave(swap);
115118
}
116119
}
117-
get size() {
118-
return this.cache.reduce((acc, arr) => acc + arr.length, 0);
119-
}
120120
load() {
121121
this.currentKeyIndex = world.getDynamicProperty(this.indexKey) ?? 0;
122122
const keys = world.getDynamicPropertyIds();

ArrayDatabase.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export class ArrayDatabase<T = any> {
2525
return this;
2626
}
2727

28-
public has(value: T) {
28+
public has(value: T): boolean {
2929
const locations = this.getAll();
3030
return locations.includes(value);
3131
}
3232

33-
public clear() {
33+
public clear(): void {
3434
const keys = world.getDynamicPropertyIds();
3535
const prefix = this.keyPrefix;
3636
for (const key of keys) {
@@ -97,6 +97,10 @@ export class ArrayDatabase<T = any> {
9797
return this.values();
9898
}
9999

100+
public get size(): number {
101+
return this.cache.reduce((acc, arr) => acc + arr.length, 0);
102+
}
103+
100104
private trySave(values: T[], swap: T[] = []) {
101105
let sizeOK = true;
102106
const stringified = JSON.stringify(values);
@@ -120,10 +124,6 @@ export class ArrayDatabase<T = any> {
120124
}
121125
}
122126

123-
public get size(): number {
124-
return this.cache.reduce((acc, arr) => acc + arr.length, 0);
125-
}
126-
127127
private load() {
128128
this.currentKeyIndex = world.getDynamicProperty(this.indexKey) as number ?? 0;
129129
const keys = world.getDynamicPropertyIds();
@@ -160,7 +160,7 @@ export class ArrayDatabase<T = any> {
160160
private get indexKey(): string {
161161
return `${ArrayDatabase.PREFIX}:index_${this.id}` as string;
162162
}
163-
163+
164164
public get [Symbol.toStringTag](): string {
165165
return this.id;
166166
}

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const db = new ArrayDatabase('test');
99

1010
db.put('hello');
1111
db.put('world');
12-
db.get(); // ["hello", "world"]
12+
db.getAll(); // ["hello", "world"]
1313
db.has('hello'); // true
1414
db.clear();
1515
db.size; // 0
@@ -21,9 +21,26 @@ const db = new ArrayDatabase<Vector3>('test');
2121

2222
db.put({ x: 0, y: 0, z: 0 });
2323
db.put({ x: 1, y: 1, z: 1 });
24-
db.get(); // [{ x: 0, y: 0, z: 0 }, { x: 1, y: 1, z: 1 }]
24+
db.getAll(); // [{ x: 0, y: 0, z: 0 }, { x: 1, y: 1, z: 1 }]
2525
```
2626

27+
## Method/Properties
28+
- (template) `T`
29+
- `readonly id: string`
30+
- `get size(): number`
31+
- `getAll(): T[]`
32+
- `add(value: T): this`
33+
- `has(value: T): boolean`
34+
- `clear(): void`
35+
- `*values(): IterableIterator<T>`
36+
- `find(callbackfn: (value: T) => boolean): T | undefined`
37+
- `filter(callbackfn: (value: T) => boolean): T[]`
38+
- `map<U>(callbackfn: (value: T) => U): U[]`
39+
- `forEach(callbackfn: (value: T) => void): void`
40+
- `some(callbackfn: (value: T) => boolean): boolean`
41+
- `every(callbackfn: (value: T) => boolean): boolean`
42+
- `[Symbol.iterator](): IterableIterator<T>`
43+
2744
## Benchmark (put)
2845
||x10|x100|
2946
|-|-|-|

0 commit comments

Comments
 (0)