UNPKG

@pallad/app-env

Version:

Detects environment (production, staging, test, development, ci) and helps making decision based on that

55 lines (54 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Builder = void 0; const builder_1 = require("@pallad/builder"); class Builder extends builder_1.Builder { info; found = false; value; constructor(info) { super(); this.info = info; } evalRule(isValid, value) { if (this.found) { return this; } if (isValid) { this.found = true; this.value = value instanceof Function ? value(this.info) : value; } return this; } forEnv(names, value) { return this.evalRule(this.info.is(...names), value); } forCI(value) { return this.evalRule(this.info.isCi, value); } forProduction(value) { return this.evalRule(this.info.isProduction, value); } forTest(value) { return this.evalRule(this.info.isTest, value); } forDevelopment(value) { return this.evalRule(this.info.isDevelopment, value); } forPreview(value) { return this.evalRule(this.info.isPreview, value); } forStaging(value) { return this.evalRule(this.info.isStaging, value); } get() { return this.value; } getOrDefault(value) { if (this.found) { return this.value; } return value; } } exports.Builder = Builder;