github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/regress-8403/nodejs/utilities.ts (about)

     1  // *** WARNING: this file was generated by test. ***
     2  // *** Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  
     5  export function getEnv(...vars: string[]): string | undefined {
     6      for (const v of vars) {
     7          const value = process.env[v];
     8          if (value) {
     9              return value;
    10          }
    11      }
    12      return undefined;
    13  }
    14  
    15  export function getEnvBoolean(...vars: string[]): boolean | undefined {
    16      const s = getEnv(...vars);
    17      if (s !== undefined) {
    18          // NOTE: these values are taken from https://golang.org/src/strconv/atob.go?s=351:391#L1, which is what
    19          // Terraform uses internally when parsing boolean values.
    20          if (["1", "t", "T", "true", "TRUE", "True"].find(v => v === s) !== undefined) {
    21              return true;
    22          }
    23          if (["0", "f", "F", "false", "FALSE", "False"].find(v => v === s) !== undefined) {
    24              return false;
    25          }
    26      }
    27      return undefined;
    28  }
    29  
    30  export function getEnvNumber(...vars: string[]): number | undefined {
    31      const s = getEnv(...vars);
    32      if (s !== undefined) {
    33          const f = parseFloat(s);
    34          if (!isNaN(f)) {
    35              return f;
    36          }
    37      }
    38      return undefined;
    39  }
    40  
    41  export function getVersion(): string {
    42      let version = require('./package.json').version;
    43      // Node allows for the version to be prefixed by a "v", while semver doesn't.
    44      // If there is a v, strip it off.
    45      if (version.indexOf('v') === 0) {
    46          version = version.slice(1);
    47      }
    48      return version;
    49  }
    50  
    51  /** @internal */
    52  export function resourceOptsDefaults(): any {
    53      return { version: getVersion() };
    54  }
    55  
    56  /** @internal */
    57  export function lazyLoad(exports: any, props: string[], loadModule: any) {
    58      for (let property of props) {
    59          Object.defineProperty(exports, property, {
    60              enumerable: true,
    61              get: function() {
    62                  return loadModule()[property];
    63              },
    64          });
    65      }
    66  }