UNPKG

ecs-pf

Version:

CLI for port-forwarding to RDS via AWS ECS

36 lines (35 loc) 1.16 kB
export const DIGITS_ONLY = /^\d+$/; export const AWS_REGION_NAME = /^[a-z0-9-]+$/; export const DB_ENDPOINT_FORMAT = /^[a-zA-Z0-9.-]+$/; export const WHITESPACE_SPLIT = /\s+/; export const HYPHEN_UNDERSCORE_SPLIT = /[-_]/; export const WORD_SEPARATOR_SPLIT = /[-_\s]/; export const ECS_TASK_ARN = new RegExp(/^arn:aws:ecs:[a-z0-9-]+:\d{12}:task\/[A-Za-z0-9-_]+\/[A-Za-z0-9]+$/); export function isDigitsOnly(value) { return DIGITS_ONLY.test(value); } export function isValidRegionName(value) { return AWS_REGION_NAME.test(value); } export function isValidDbEndpoint(value) { return DB_ENDPOINT_FORMAT.test(value); } export function splitByWhitespace(text) { return text.split(WHITESPACE_SPLIT).filter(Boolean); } export function splitByHyphenUnderscore(text) { return text.split(HYPHEN_UNDERSCORE_SPLIT); } export function splitByWordSeparators(text) { return text.split(WORD_SEPARATOR_SPLIT); } export function isTaskArnShape(input) { const str = String(input); if (ECS_TASK_ARN.test(str)) { return true; } if (str.startsWith("ecs:") && str.split("_").length >= 3) { return true; } return false; }