/** * @fileoverview Utilities for parsing, validating, and converting environment variables. * * This module provides comprehensive functionality for working with environment variables * in various formats, including shell format (NAME=value), JSON format, and structured * JavaScript objects. It supports proper quote handling, multi-line values, validation, * and error reporting. * * Key features: * - Parse shell-format environment variables with proper escaping * - Parse JSON-format environment variables * - Convert between different formats (JSON, shell, objects, arrays) * - Validate variable names according to different standards * - Handle duplicates, invalid names, and malformed input gracefully * - Comprehensive error reporting with line/column information */ import type { EnvironmentVariable, EnvVarParsingError, EnvVarValidationMode } from './environment.types.js'; export declare const ERROR_TYPES: { INVALID_NAME: number; DUPLICATED_NAME: number; INVALID_LINE: number; INVALID_VALUE: number; INVALID_JSON: number; INVALID_JSON_FORMAT: number; INVALID_JSON_ENTRY: number; INVALID_NAME_STRICT: number; JAVA_INFO: number; }; /** * Validates an environment variable name according to the specified mode. * * Supports two validation modes: * - 'simple': Allows letters, digits, underscores, dashes, and dots (Clever Cloud extended) * - 'strict': Only allows letters, digits (not first char), and underscores (Linux standard) * * @param name - The environment variable name to validate * @param mode - Validation mode: 'simple' or 'strict' ('simple' by default) * @returns True if the name is valid according to the specified mode */ export declare function validateName(name: string, mode?: EnvVarValidationMode): boolean; /** * Parses raw environment variable input in shell format (NAME=value) into structured data. * * Supports various input formats: * - Simple format: NAME=value * - Quoted values: NAME="value" or NAME='value' * - Multi-line values with proper escaping * - Comments (lines starting with #) * - Empty lines (ignored) * * The parser handles: * - Proper quote escaping and unescaping * - Multi-line values * - Duplicate variable detection * - Invalid name validation * - Malformed line detection * * @param rawInput - Raw environment variables string in shell format * @param options - Parsing options including validation mode * @returns Object containing parsed variables and any parsing errors encountered */ export declare function parseRaw(rawInput?: string, options?: { mode?: EnvVarValidationMode; }): { variables: Array; errors: Array; }; /** * Parses raw environment variable input in JSON format into structured data. * * Expects input in JSON format with name-value pairs: * ```json * { * "VAR_NAME": "value", * "ANOTHER_VAR": "another value" * } * ``` * * The parser handles: * - JSON parsing with error handling * - Variable name validation according to specified mode * - Invalid name detection and error reporting * - Type validation (ensures all values are strings) * * @param rawInput - Raw environment variables string in JSON format * @param options - Parsing options including validation mode * @returns Object containing an array of parsed environment variables and any parsing errors encountered */ export declare function parseRawJson(rawInput?: string, options?: { mode?: EnvVarValidationMode; }): { variables: Array; errors: Array; }; /** * Converts an array of environment variables into a formatted JSON string. * * Features: * - Automatically sorts variables by name for consistent output * - Uses 2-space indentation for readability * * @param variables - Array of environment variables to convert * @returns Formatted JSON string representation of the variables */ export declare function toJson(variables: Array): string; /** * Converts an array of environment variables into a shell-compatible string format. * * Features: * - Always double-quotes values with proper escaping * - Sorts variables by name for consistent output * - Optional export prefix for shell sourcing * * Output format: * - Without exports: `VAR_NAME="value"` * - With exports: `export VAR_NAME="value"` * * @param variables - The environment variables to convert * @param options - Options object * @returns Shell-compatible string representation of the variables */ export declare function toNameEqualsValueString(variables: Array, options?: { addExports?: boolean; }): string; /** * Converts an array of environment variables into a plain JavaScript object. * * Features: * - Automatically merges duplicated names (keeps last value) * - Removes variables with invalid names * * @param variables - The environment variables to convert * @returns Plain object with variable names as keys and values as strings */ export declare function toNameValueObject(variables: Array): Record; /** * Converts a plain JavaScript object into an array of environment variables. * * This is the inverse operation of toNameValueObject. It takes a simple key-value * object and converts it into the structured EnvironmentVariable format. * * Features: * - Automatically removes variables with invalid names * - Preserves original key-value relationships * * @param variables - Plain object with variable names as keys * @returns Array of structured environment variable objects */ export declare function toArray(variables: Record): Array; //# sourceMappingURL=environment-utils.d.ts.map