SayIf.ts 595 B

12345678910111213141516
  1. /// <reference path="../Say.ts" />
  2. class SayIf extends Say {
  3. private condition : () => boolean;
  4. public constructor (condition : () => boolean, ...objs : Array<any>) {
  5. super(...objs);
  6. this.condition = condition != undefined ? condition : () => { return true; };
  7. }
  8. public async getPureElements () : Promise<Array<Element | Text>> {
  9. if (this.condition()) {
  10. let paragraphs = await this.getParagraphs();
  11. return paragraphs.length == 1 ? paragraphs[0] : Array.prototype.concat.apply([], paragraphs);
  12. }
  13. return [];
  14. }
  15. }