{"id":26579,"library":"vars-expand","title":"vars-expand","description":"A zero-dependency template transpiler that performs shell-like variable expansion with support for default values, alternate values, and substitution operators (:- :- :+ + :? ? etc.). Inspired by Bash's Shell Parameter Expansion syntax. Current stable version is 0.0.3, released infrequently. Key differentiators: lightweight (no dependencies), TypeScript-first with bundled typings, and full support for POSIX-style expansion patterns. Unlike general template engines (e.g., Handlebars), it strictly mirrors shell semantics, making it ideal for CI/CD pipelines, configuration loaders, and environment variable interpolation.","status":"active","version":"0.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/allex/vars-expand","tags":["javascript","shell-like","shell-variable-expand","vars-expand","transpiler","typescript"],"install":[{"cmd":"npm install vars-expand","lang":"bash","label":"npm"},{"cmd":"yarn add vars-expand","lang":"bash","label":"yarn"},{"cmd":"pnpm add vars-expand","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package uses ESM default export. CommonJS require() will work but may need .default access depending on bundler.","wrong":"const varsBraceExpand = require('vars-expand')","symbol":"varsBraceExpand","correct":"import varsBraceExpand from 'vars-expand'"},{"note":"Named export is aliased to default; both styles work identically.","wrong":"import { varsBraceExpand } from 'vars-expand/varsBraceExpand'","symbol":"varsBraceExpand","correct":"import { varsBraceExpand } from 'vars-expand'"},{"note":"TypeScript type export (if available in future versions; not present in 0.0.3). Currently no explicit type export.","wrong":"","symbol":"VarsExpandOptions","correct":"import type { VarsExpandOptions } from 'vars-expand'"}],"quickstart":{"code":"import varsBraceExpand from 'vars-expand';\n\nconst data = {\n  NAME: 'Alice',\n  GREETING: '',\n};\n\nconst template = `Hello, ${NAME:-World}! Today is ${DAY:-Monday}.`;\nconst result = varsBraceExpand(template, data);\nconsole.log(result); // 'Hello, Alice! Today is Monday.'","lang":"typescript","description":"Demonstrates shell-like variable expansion with default values using the varsBraceExpand function."},"warnings":[{"fix":"For empty string fallback, use ${VAR:-default} only if VAR is unset; to treat empty as unset, preprocess data or use a different operator.","message":"Empty strings are treated as set, so ${VAR:-default} will not replace an empty VAR with default. Use ${VAR:?error} to flag empty variables.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use String.raw`...` or escape dollar signs in JavaScript to prevent premature interpolation.","message":"Template syntax uses backtick or single-quoted strings must be careful with JavaScript template literals to avoid double interpolation. Use \\${} or raw strings.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always wrap variable names in curly braces: ${VAR}, not $VAR.","message":"The library only supports brace expansion syntax (${...}), not $VAR without braces. Attempting to use $VAR will leave it unexpanded.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import varsBraceExpand from 'vars-expand' or const { default: varsBraceExpand } = require('vars-expand').","cause":"CommonJS require() returns an object with default property but is not directly callable in strict ESM environments.","error":"TypeError: varsBraceExpand is not a function"},{"fix":"Provide a default value with ${VAR:-default} or ensure the variable exists in the data object.","cause":"Variable name in the template (${VAR}) does not exist in the data object and no default is provided.","error":"ReferenceError: VAR is not defined"},{"fix":"Use String.raw`...` or escape $ as \\$ in the template string.","cause":"Template contains a dollar sign that JavaScript interprets as template literal interpolation. Occurs when template is defined as a template literal (backticks) without escaping.","error":"SyntaxError: Invalid or unexpected token"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}