UNPKG

spinjs

Version:

<p align="center"><a href="#"><img width="150" src="https://rawgit.com/sysgears/jsapp/master/packages/spinjs/logo.svg"></a></p>

50 lines (46 loc) 1.4 kB
export default class Stack { public technologies: string[]; public platform: string; constructor(...stack) { 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}`); } } 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; } }