Pick a random value from a list in Yaak requests
A Yaak plugin that adds template functions for picking a random value from a list of values.
random.choicePicks one value at random from a comma-separated list.
| Argument | Type | Required | Description |
|---|---|---|---|
values |
text | yes | Comma-separated options. Whitespace around each entry is trimmed; empty ones ignored. |
${[ random.choice(values='red,green,blue') ]}
Renders red, green, or blue, re-rolled every time the request is sent.
Example JSON body:
{
"tier": "${[ random.choice(values='free,pro,enterprise') ]}",
"locale": "${[ random.choice(values='en-US, de-DE, ja-JP') ]}"
}
Returns an empty value when the list is empty or contains only blanks.
From the Yaak plugin registry — search for “Random Choice” under Settings → Plugins in the Yaak app, or:
yaak plugin install @cyanic/yaak-random-choice
From source:
git clone https://github.com/cyanicr/yaak-random-choice.git
cd yaak-random-choice
npm install
npm run build
yaak plugin install .
Requires Node.js 20+ and the Yaak CLI on your PATH.
npm install
npm run dev # rebuild the bundle on every file change
npm run check # typecheck + tests
| Script | What it does |
|---|---|
npm run build |
Build the plugin bundle into build/ |
npm run dev |
Rebuild continuously while you edit |
npm test |
Run the Vitest suite once |
npm run test:watch |
Run tests in watch mode |
npm run typecheck |
tsc --noEmit |
npm run check |
Typecheck, then tests — what CI runs |
The plugin definition lives in src/index.ts. Each entry in
templateFunctions becomes a template tag in the Yaak UI; onRender receives the
user-supplied argument values and returns the rendered string (or null for no value).
build/ is generated output and is not committed — run npm run build after cloning.
version in package.json and note the change in CHANGELOG.md.npm run check && npm run buildyaak plugin publishgit tag v0.1.0 && git push --tagsIssues and pull requests are welcome — see CONTRIBUTING.md.
Please make sure npm run check passes before opening a PR.
MIT © cyanicr