Initial commit of the qmk keymap generator
This commit is contained in:
53
lib/Layer.ts
Normal file
53
lib/Layer.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { IKeyRow, IKeyRows } from './Row';
|
||||
|
||||
export interface ILayer extends IterableIterator<IKeyRow> {
|
||||
rows: IKeyRows;
|
||||
index: number;
|
||||
length: number;
|
||||
forEach(fn: (k: IKeyRow, i: number) => any): void;
|
||||
map(fn: (k: IKeyRow, i: number) => IKeyRow): IKeyRows;
|
||||
}
|
||||
|
||||
export type ILayers = ILayer[];
|
||||
|
||||
class Layer implements ILayer {
|
||||
rows: IKeyRows = [];
|
||||
index: number = 0;
|
||||
|
||||
constructor(rows: IKeyRows) {
|
||||
this.rows = rows;
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
forEach(fn: (k: IKeyRow, i: number) => any): void {
|
||||
return this.rows.forEach(fn);
|
||||
}
|
||||
|
||||
map(fn: (k: IKeyRow, i: number) => IKeyRow): IKeyRows {
|
||||
return this.rows.map(fn);
|
||||
}
|
||||
|
||||
get length(): number {
|
||||
return this.rows.length;
|
||||
}
|
||||
|
||||
public next(): IteratorResult<IKeyRow> {
|
||||
if (this.index < this.rows.length) {
|
||||
return {
|
||||
done: false,
|
||||
value: this.rows[this.index++],
|
||||
};
|
||||
}
|
||||
return {
|
||||
done: true,
|
||||
value: null,
|
||||
};
|
||||
}
|
||||
|
||||
[Symbol.iterator](): IterableIterator<IKeyRow> {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export const layer = (...rows: IKeyRows): ILayer => new Layer(rows);
|
||||
export default layer;
|
||||
Reference in New Issue
Block a user