Ejemplo
minimist 1.2.8: parse CLI arguments with string, boolean options, aliases and defaults using minimist
Muestra verificada para npm minimist 1.2.8: parse CLI arguments with string, boolean options, aliases and defaults using minimist. El contrato se ejecutó en…
sha256:6b1429ca854e1f6b53d3c78c0f4943b6814298d81c0ab3c6ad46e7d092d71e96
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux 24 · ubuntu · glibc 2.39 x64 npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-28 |
Caso
HOW- Objetivo
- parse CLI arguments with string, boolean options, aliases and defaults using minimist
- Paquetes
- Símbolos
-
- minimist
- Creado
- 2026-08-28T05:34:00Z
Contrato
- minimist parses long and short boolean flags and supports negation with --no- prefix
- minimist parses string arguments passed with spaces or equal signs
- minimist forces specified option keys to string type and preserves leading zeros
- minimist forces specified option keys to boolean type without consuming following values
- minimist maps option aliases bidirectionally to full names and alias keys
- minimist applies default values for unspecified options without overriding provided values
- minimist collects remaining positional arguments in the _ array and arguments after -- in the -- array
- minimist supports stopEarly to treat all arguments after the first positional argument as positional
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
Código fuente
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: parse CLI arguments with string, boolean options, aliases and defaults using minimist
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/minimist@1.2.8
Demonstrate these symbols/APIs:
- minimist
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:225cee59f0e7bb95b6993989dce43dbfeeeea921f588433d2a6bdceca53c103a","contract":["minimist parses long and short boolean flags and supports negation with --no- prefix","minimist parses string arguments passed with spaces or equal signs","minimist forces specified option keys to string type and preserves leading zeros","minimist forces specified option keys to boolean type without consuming following values","minimist maps option aliases bidirectionally to full names and alias keys","minimist applies default values for unspecified options without overriding provided values","minimist collects remaining positional arguments in the _ array and arguments after -- in the -- array","minimist supports stopEarly to treat all arguments after the first positional argument as positional"],"goal":"parse CLI arguments with string, boolean options, aliases and defaults using minimist","kind":"HOW","packages":["pkg:npm/minimist@1.2.8"],"schemaVersion":1,"symbols":["minimist"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/minimist@1.2.8"],"schemaVersion":1,"subject":"pkg:npm/minimist@1.2.8","symbols":["minimist"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-minimist",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-minimist",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"minimist": "1.2.8"
}
},
"node_modules/minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"license": "MIT"
}
}
}
{
"name": "sample-minimist",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"minimist": "1.2.8"
}
}
{
"schemaVersion": 1,
"goal": "parse CLI arguments with string, boolean options, aliases and defaults using minimist",
"kind": "HOW",
"packages": [
"pkg:npm/minimist@1.2.8"
],
"symbols": [
"minimist"
]
}
import minimist from 'minimist';
/**
* Parse command-line arguments using minimist with options.
* @param {string[]} args Array of argument strings
* @param {object} [opts] Parsing options (string, boolean, alias, default, etc.)
* @returns {object} Parsed argument object
*/
export function parseArgs(args, opts) {
return minimist(args, opts);
}
export { minimist };
export default minimist;
import assert from 'node:assert/strict';
import { minimist, parseArgs } from '../src/index.mjs';
// 1. minimist parses long and short boolean flags and supports negation with --no- prefix
{
const argv = minimist(['-v', '--verbose', '--no-debug', '-x']);
assert.equal(argv.v, true);
assert.equal(argv.verbose, true);
assert.equal(argv.debug, false);
assert.equal(argv.x, true);
}
// 2. minimist parses string arguments passed with spaces or equal signs
{
const argv = parseArgs(['--host', 'example.com', '--port=8080', '-f', 'config.json']);
assert.equal(argv.host, 'example.com');
assert.equal(argv.port, 8080);
assert.equal(argv.f, 'config.json');
}
// 3. minimist forces specified option keys to string type and preserves leading zeros
{
const argv = minimist(['--code', '0123', '--id', '456'], {
string: ['code', 'id']
});
assert.equal(argv.code, '0123');
assert.equal(typeof argv.code, 'string');
assert.equal(argv.id, '456');
assert.equal(typeof argv.id, 'string');
}
// 4. minimist forces specified option keys to boolean type without consuming following values
{
const argv = minimist(['-a', 'true', '-b', 'false', '-c', 'value'], {
boolean: ['a', 'b', 'c']
});
assert.equal(argv.a, true);
assert.equal(argv.b, false);
assert.equal(argv.c, true);
assert.deepEqual(argv._, ['value']);
}
// 5. minimist maps option aliases bidirectionally to full names and alias keys
{
const argv = minimist(['-h', 'localhost', '-p', '3000'], {
alias: {
h: 'host',
p: ['port', 'pnum']
}
});
assert.equal(argv.h, 'localhost');
assert.equal(argv.host, 'localhost');
assert.equal(argv.p, 3000);
assert.equal(argv.port, 3000);
assert.equal(argv.pnum, 3000);
}
// 6. minimist applies default values for unspecified options without overriding provided values
{
const argv = minimist(['--name', 'alice'], {
default: {
name: 'anonymous',
timeout: 5000,
enabled: true
}
});
assert.equal(argv.name, 'alice');
assert.equal(argv.timeout, 5000);
assert.equal(argv.enabled, true);
}
// 7. minimist collects remaining positional arguments in the _ array and arguments after -- in the -- array
{
const argv = minimist(['cmd', 'subcmd', '--opt', 'val', '--', 'extra1', '--flag', 'extra2'], {
'--': true
});
assert.equal(argv.opt, 'val');
assert.deepEqual(argv._, ['cmd', 'subcmd']);
assert.deepEqual(argv['--'], ['extra1', '--flag', 'extra2']);
}
// 8. minimist supports stopEarly to treat all arguments after the first positional argument as positional
{
const argv = minimist(['--bool', 'cmd', '--other', 'value'], {
boolean: ['bool'],
stopEarly: true
});
assert.equal(argv.bool, true);
assert.deepEqual(argv._, ['cmd', '--other', 'value']);
assert.equal(argv.other, undefined);
}
Seeder de origen
anónimo