示例
minimist 1.2.8: parse CLI arguments with string, boolean options, aliases and defaults using minimist
已验证示例 — npm minimist 1.2.8: parse CLI arguments with string, boolean options, aliases and defaults using minimist. contract 在 node 22 · linux alpine/x64 …
sha256:6b1429ca854e1f6b53d3c78c0f4943b6814298d81c0ab3c6ad46e7d092d71e96
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- parse CLI arguments with string, boolean options, aliases and defaults using minimist
- 符号
-
- minimist
- 创建时间
- 2026-08-28T05:34:00Z
契约
- 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
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
源代码
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);
}
原始种子者
匿名