UNPKG

spinjs

Version:

[![Join the chat at https://gitter.im/sysgears/spinjs](https://badges.gitter.im/sysgears/spinjs.svg)](https://gitter.im/sysgears/spinjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![npm version](https://badge.fury.io/js/spi

52 lines (48 loc) 1.46 kB
export default class Stack { public technologies: string[]; public platform: string; constructor(name: string, ...stack: string[]) { this.technologies = stack .reduce((acc, tech) => { if (!tech) { return acc; } else if (tech.constructor === Array) { return acc.concat(tech); } else { return acc.concat(tech.split(':')); } }, []) .filter((v, i, a) => a.indexOf(v) === i); if (this.hasAny('server')) { this.platform = 'server'; } else if (this.hasAny('web')) { this.platform = 'web'; } else if (this.hasAny('android')) { this.platform = 'android'; } else if (this.hasAny('ios')) { this.platform = 'ios'; } else { throw new Error( `stack should include one of 'server', 'web', 'android', 'ios', stack: ${this.technologies} for builder ${name}` ); } } public hasAny(technologies): boolean { const array = technologies.constructor === Array ? technologies : [technologies]; for (const feature of array) { if (this.technologies.indexOf(feature) >= 0) { return true; } } return false; } public hasAll(technologies): boolean { const array = technologies.constructor === Array ? technologies : [technologies]; for (const feature of array) { if (this.technologies.indexOf(feature) < 0) { return false; } } return true; } }