__________________
< srsly dude, why? >
------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
cowsay is a configurable talking cow, originally written in Perl by its original author
This project is a translation in JavaScript of the original program and an attempt to bring the same silliness to node.js.
npm install -g cowsay
Requires Node.js 22.21 or later.
cowsay JavaScript FTW!
or
cowthink node.js is cool
It acts in the same way as the original cowsay, so consult cowsay(1) or run cowsay -h
________
< indeed >
--------
\
\
.
8000
::!!!!!!!:.
.!!!!!:. .:!!!!!!!!!!!!
~~~~!!!!!!. .:!!!!!!!!!UWWW$$$
:$$NWX!!: .:!!!!!!XUWW$$$$$$$$$P
$$$$$##WX!: .<!!!!UW$$$$" $$$$$$$$#
$$$$$ $$$UX :!!UW$$$$$$$$$ 4$$$$$*
^$$$B $$$$\ $$$$$$$$$$$$ d$$R"
"*$bd$$$$ '*$$$$$$$$$$$o+#"
"""" """""""
echo please repeat | cowsay
cowsay can be used as any other npm dependency. It is an ES module and ships its own TypeScript types.
import * as cowsay from 'cowsay';
console.log(
cowsay.say({
text: "I'm a moooodule",
e: 'oO',
T: 'U ',
}),
);
// or cowsay.think() _________________
( I'm a moooodule )
-----------------
o ^__^
o (oO)\_______
(__)\ )\/\
U ||----w |
|| ||
import cowsay from 'cowsay' works too, and so does require('cowsay') from CommonJS.
| Option | Description |
|---|---|
text |
The message. |
f |
Name of a cow from the cows folder (e.g. 'USA') or a file path. |
r |
Pick a random cow. |
e |
Eyes, e.g. '^^'. |
T |
Tongue, e.g. 'U '. |
W |
Wrap the message at this column (no wrapping by default). |
n |
Disable wrapping. |
b d g p s t w y |
Modes (borg, dead, greedy, paranoia, stoned, tired, wired, youthful); they override e and T. |
Getting a list of cow names:
function get_cows(error, cow_names) {
if (error) {
console.log(error);
} else if (cow_names) {
console.log(`Number of cows available: ${cow_names.length}`);
}
}
cowsay.list(get_cows);
// or, with the returned promise
const cowNames = await cowsay.list();import * as cowsay from 'cowsay';
let output: string = cowsay.say({ text: 'Hello from typescript!' });
console.log(output);Getting a list of cow names:
function get_cows(error: NodeJS.ErrnoException | null, cow_names?: Array<string>): void {
if (error) {
console.log(`Error getting cow names: ${error.message}`);
} else if (cow_names) {
console.log(`Number of cows available: ${cow_names.length}`);
}
}
cowsay.list(get_cows);Importing the IOptions interface directly:
import { type IOptions } from 'cowsay'; // optional
let opts: IOptions = {
text: 'Hello from TypeScript!',
e: '^^',
r: true,
};
console.log(cowsay.say(opts));cowsay works in your browser too with rollup / webpack / vite / esbuild / you name it.
import { say } from 'cowsay/browser';
console.log(say({ text: 'grazing in the browser' }));Bundlers that use the browser export condition also pick the browser build for a plain import … from 'cowsay'. Import from 'cowsay/browser' to get the matching TypeScript types.
You can customize the cow by importing the relevant one
import { think, SQUIRREL } from 'cowsay/browser';
console.log(
think({
text: 'grazing in the browser',
cow: SQUIRREL,
eyes: 'pp',
tongue: ';;',
}),
);All cows are included in the bundle, but you can use your bundler's tree-shaking feature to reduce the final bundle size.
The browser build needs Chrome/Edge 112+, Firefox 125+ or Safari 17+.
Without a bundler, load the UMD build, which defines a global cowsay (see sample.html):
<script src="https://unpkg.com/cowsay/dist/cowsay.umd.js"></script>say({
text: 'hello',
cow: '', // Template for a cow, get inspiration from `./cows`
eyes: 'oo', // Select the appearance of the cow's eyes, equivalent to cowsay -e
tongue: 'L|', // The tongue is configurable similarly to the eyes through -T and tongue_string, equivalent to cowsay -T
wrap: false, // Disable word wrapping; true (the default) enables it. equivalent to cowsay -n
wrapLength: 40, // Specifies roughly where the message should be wrapped. equivalent to cowsay -W
mode: 'b', // One of "b", "d", "g", "p", "s", "t", "w", "y"
});The desktop web app in web/ uses this library through a local
package dependency. It includes a live editor, template selection, copy/download
and a saved history in localStorage. History changes only when Save is pressed.
Sources live in src/; tsdown builds JavaScript and declarations
into dist/. The complete repository needs Node.js 22.21 or later, as in the
TypeScript snapshot. Dependency versions and Node requirements have not been
upgraded during the integration; use the committed lockfiles with npm ci.
From a clean checkout:
npm ci
npm run build
npm --prefix web ci
cd web
npx playwright install chromium
cd ..
npm run verify -- --no-openThe Playwright install downloads the browser matching the already pinned version; it does not update Playwright. Use the environment's documented browser setup if the sandbox already provides that revision. No global TypeScript loader is needed.
| Command | What it does |
|---|---|
npm run build |
Regenerates the typed cow catalog and builds library, CLI and browser outputs. |
npm test |
Builds and runs the library's Node test suite with ASCII terminal output. |
npm run verify:lib |
Library types, lint, format, tests, package checks and an installed-tarball smoke test. |
npm run verify |
All library and web checks; writes and opens the reviewer dashboard. |
npm run verify -- --no-open |
The same checks without opening a browser tab. |
npm run check:installed |
Installs an actual tarball offline using locked runtime dependency versions; checks runtime and consumer types. |
npm --prefix web run dev |
Starts the React editor with Vite. |
npm --prefix web run report |
Serves the latest dashboard at localhost:4174. |
npm run typecheck |
Checks source, scripts, tests and generated catalog consistency. |
npm run lint |
Checks library code with ESLint; web has its own oxlint configuration. |
npm run format |
Formats library files; web has its own Prettier configuration. |
npm run test:report |
Optional library-only Allure report. |
cows/ remains the source of truth for templates. scripts/generate-catalog.ts
generates src/browser-cows.ts, including constants, the frozen cows map and
CowName. Commit catalog changes with their templates; typecheck detects a stale
catalog. Browser declarations are also compiled without Node ambient types.
test/fixtures/v1-baseline.json records the original repository at eef317a,
including artist signatures. test/fixtures/intentional-changes.json explains the
reviewed output differences; test/integration.test.ts independently checks the
new wrapping, Unicode, parser and browser contracts. See CHANGELOG.md.
- Review
src/core.ts,balloon.ts,faces.tsandreplacer.ts, then the browser adapter and generated catalog. Node and browser share the same renderer. - Run
npm run verify -- --no-open. The twelve checks include the actual installed package, React components, coverage thresholds, production build and Chromium end-to-end/accessibility tests. Results and logs are inweb/reports/; the JSON Node reporter preserves individual failures without parsing terminal text. - Smoke-test
node dist/cli.mjs -W -1 hello, piped stdin,--think,-land a named template. Trynode dist/cli.mjs -e 00 -T U helloas well. - Start
npm --prefix web run dev. Change message, cow, eyes, mode and wrapping; check the preview, Copy and Download. Save, reload and restore history. Check that cancelling Clear preserves history and confirming Clear removes it.
No CI service is configured by this integration. npm run verify is the shared
local entry point. Build output, test reports and dependency directories stay out
of Git and the published npm package; the private React app is not published.
npm run test:report runs the suite and serves an Allure report: tests grouped by file and suite, search and status filters, failure details, timings, and a trend chart that fills in over repeated runs. Each run starts its own local server and opens one browser tab on the Overview page; stop it with Ctrl+C. The results (allure-results/, allure-report/, allure-history.jsonl) stay local and are git-ignored; Allure's analytics are switched off in allurerc.mjs.
Tests use a small ASCII-only reporter (test/reporters/ascii.ts), so the output stays readable in any terminal, including ones without a UTF-8 locale. Results are grouped by file and suite with their counts; large suites that pass completely are shown as counts only (TEST_VERBOSE=1 npm test lists every test). Failures are repeated at the end with their location. When output differs, expected and actual are shown side by side:
Output differs (lines marked > differ):
expected | actual
4 \ ^__^ | \ ^__^
> 5 \ (oo)\_______ | \ (oO)\_______