Skip to content

Commit a896ebf

Browse files
committed
add utility class Collection
1 parent e3e75da commit a896ebf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { WindowsScriptingHost} from './node/node-wsh.js';
2+
export { Collection} from './node/utils.js';

lib/node/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export class Collection {
2+
3+
#ticket;
4+
#type;
5+
6+
constructor( ticket, type) {
7+
this.#ticket = ticket;
8+
this.#type = type;
9+
}
10+
11+
get length() {
12+
return this.#ticket.get( 'Count');
13+
}
14+
15+
get( indexBase0) {
16+
return this.#ticket.get( 'Item', t2 => t2.apply.bind( t2))( this, [ indexBase0 + 1], t3 => new this.#type( t3));
17+
}
18+
19+
*[ Symbol.iterator]() {
20+
const length = this.length; // expect anomoly if the underlying collect is changing
21+
for( let i = 0; i < length; i++)
22+
yield this.get( i);
23+
}
24+
}

0 commit comments

Comments
 (0)