env-cmd/src/utils.ts
Todd Bluhm 33d0ac3461
feat(nodejs)!: remove v18 & < 20.10 support
added support for node 24
2025-07-12 00:34:59 -08:00

35 lines
1.0 KiB
TypeScript

import { resolve } from 'node:path'
import { homedir } from 'node:os'
import { cwd } from 'node:process'
// Special file extensions that node can natively import
export const IMPORT_HOOK_EXTENSIONS = ['.json', '.js', '.cjs', '.mjs']
/**
* A simple function for resolving the path the user entered
*/
export function resolveEnvFilePath(userPath: string): string {
// Make sure a home directory exist
const home = homedir() as string | undefined
if (home != null) {
userPath = userPath.replace(/^~($|\/|\\)/, `${home}$1`)
}
return resolve(cwd(), userPath)
}
/**
* A simple function that parses a comma separated string into an array of strings
*/
export function parseArgList(list: string): string[] {
return list.split(',')
}
/**
* A simple function to test if the value is a promise/thenable
*/
export function isPromise<T>(value?: T | PromiseLike<T>): value is PromiseLike<T> {
return value != null
&& typeof value === 'object'
&& 'then' in value
&& typeof value.then === 'function'
}