File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { isEmpty } from './validators'
22
3+ /**
4+ * Reads an environment variable, and logs it.
5+ * If the environment variable cannot be found, the process is exited (die).
6+ * @param envName the name of the environment variable to be read
7+ */
38export function readEnvOrDie ( envName : string ) : string {
49 const env = process . env [ envName ]
510 if ( isEmpty ( env ) ) {
Original file line number Diff line number Diff line change 1- import { sleep } from './sleep'
2- import * as validators from './validators'
3- import * as stringifiers from './stringifiers'
4- import { readEnvOrDie } from './env'
5-
6- export {
7- sleep ,
8- validators ,
9- readEnvOrDie ,
10- stringifiers
11- }
1+ export { sleep } from './sleep'
2+ export * as validators from './validators'
3+ export * as stringifiers from './stringifiers'
4+ export { readEnvOrDie } from './env'
Original file line number Diff line number Diff line change 1+ /**
2+ * Return promise after given amount of milliseconds. Await the promise to simulate a sleep.
3+ * @param ms time in milliseconds
4+ */
15export async function sleep ( ms : number ) : Promise < void > {
26 return await new Promise < void > ( resolve => setTimeout ( resolve , ms ) )
37}
Original file line number Diff line number Diff line change 11
2+ /**
3+ * Stringifies an array and cuts out text from elements if it is longer than maxLen.
4+ * Can be used for logging to reduce clutter.
5+ * @param arg the array of objects to be logged.
6+ * @param maxLen if length of stringified arg is longer than maxLen, then we cut it short.
7+ */
28export function stringifyArray ( args : unknown [ ] , maxLen ?: number ) : string {
39 return JSON . stringify (
410 args . map ( arg => stringify ( arg , maxLen ) )
511 )
612}
713
14+ /**
15+ * Stringifies an object and cuts out text if it is longer than maxLen.
16+ * Can be used for logging to reduce clutter.
17+ * @param arg the object to be logged.
18+ * @param maxLen if length of stringified arg is longer than maxLen, then we cut it short.
19+ */
820export const stringify = ( arg : unknown , maxLen ?: number ) : string => {
921 const json = JSON . stringify ( arg )
1022 if ( maxLen === undefined || json . length <= maxLen ) {
Original file line number Diff line number Diff line change 1+ /**
2+ * Type guard checking if x is a number.
3+ * @param x
4+ */
15export function isNumber ( x : unknown ) : x is number {
26 return typeof x === 'number'
37}
48
9+ /**
10+ * Type guard checking if x is a string.
11+ * @param x
12+ */
513export function isString ( x : unknown ) : x is string {
614 return typeof x === 'string'
715}
816
17+ /**
18+ * Type guard checking if value is undefined or empty.
19+ * @param value
20+ */
921export function isEmpty ( value : string | undefined ) : value is undefined {
1022 return value === undefined || value === ''
1123}
1224
25+ /**
26+ * Type guard checking if x is an object.
27+ * @param x
28+ */
1329export function isObject ( x : unknown ) : x is object {
1430 return typeof x === 'object'
1531}
1632
33+ /**
34+ * Type guard checking if object has property p.
35+ * @param object the object to be checked
36+ * @param name name of the property
37+ */
1738// Helper function to fix issue that `in` operator as type guard is not widening type with the asserted property key
1839// See https://github.com/microsoft/TypeScript/issues/21732
1940export function hasProperty < P extends PropertyKey , O extends object > ( object : O , name : P ) :
You can’t perform that action at this time.
0 commit comments