UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

38 lines (37 loc) 2.08 kB
import type { VariableValue } from "../variables/VariableValue"; import { BashExpression } from "./BashExpression"; export type QuotesEscapeMode = "single" | "double"; export type EscapeOptions = { quotes?: QuotesEscapeMode | false; }; /** * escapes a string or bash expression for bash * it either can escape single or double quotes (double is default) */ export declare const bashEscape: (value: VariableValue | any, options?: EscapeOptions) => string | BashExpression; export declare const escapeString: (value: string | null | undefined, { quotes }?: EscapeOptions) => string; export declare const escapeBashExpression: (value: BashExpression, options: EscapeOptions) => BashExpression; export declare const escapeDoubleQuotes: (value: string | null | undefined) => string; export declare const escapeSingleQuotes: (value: string | null | undefined) => string; export declare const escapeBackTicks: (value: string | null | undefined) => string; export declare const escapeNewlines: (value: string | null | undefined) => string; export type EscapeForDotEnvOptions = { quoteMode: "auto" | "always"; }; /** * * escape env vars for .env files. * unfortunatly, the format has many limitations. In order to be very forgiving, we need to do some magic here: * * - when the value contains no newlines, we are fine * - if the value contains newlines, we need to wrap it in quotes. And thats where the problem begins: * - you can't escape quotes. this is a limitation of dotenv and node * - you can have inner quotes, but they break in node.js (not in dotenv though), see https://github.com/nodejs/node/issues/54134 * - so we need to quote cleverly * - to make things worse, we need to check whether we have a simple stirng or a bash expression, that needs to be evalulated first... * * what an absolute nightmare. * * - other languages are currently only partially supported, since most .env implementations are slightly different */ export declare const escapeForDotEnv: (value: VariableValue | undefined | null, options?: EscapeForDotEnvOptions) => string;