CodeSampleX

Beispiel

yargs-parser 21.1.1

Verifiziertes Beispiel für npm yargs-parser 21.1.1. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: yargsParser parses command-line…

sha256:3246e0f5e686a30bf000a9f3911e478e2485c0d45540a5a7dacb67aeefa112d3

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-23

Fall

HOW
Ziel
verify pkg:npm/yargs-parser@21.1.1
Pakete
Erstellt
2026-08-23T08:19:27Z

Contract

  1. yargsParser parses command-line argument arrays and strings into key-value flags and positional arguments
  2. yargsParser handles typed options including boolean flags, aliases, numbers, defaults, and custom coercion
  3. yargsParser expands nested object structures via dot-notation and parses boolean negations
  4. yargsParser separates trailing positional arguments following the double-dash delimiter when populate-- configuration is enabled
  5. yargsParser.detailed returns detailed arguments object with parsed argv, configuration, aliases, and error state
  6. yargsParser utility methods convert strings with camelCase and decamelize and identify numeric strings with looksLikeNumber

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
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: verify pkg:npm/yargs-parser@21.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/yargs-parser@21.1.1

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.
csx.json
{"case":{"caseId":"case:sha256:bedb924d5cff13d045a6c96fefca82e4b7c5c6093a5fd851723a1a16a44dad52","contract":["yargsParser parses command-line argument arrays and strings into key-value flags and positional arguments","yargsParser handles typed options including boolean flags, aliases, numbers, defaults, and custom coercion","yargsParser expands nested object structures via dot-notation and parses boolean negations","yargsParser separates trailing positional arguments following the double-dash delimiter when populate-- configuration is enabled","yargsParser.detailed returns detailed arguments object with parsed argv, configuration, aliases, and error state","yargsParser utility methods convert strings with camelCase and decamelize and identify numeric strings with looksLikeNumber"],"goal":"verify pkg:npm/yargs-parser@21.1.1","kind":"HOW","packages":["pkg:npm/yargs-parser@21.1.1"],"schemaVersion":1},"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/yargs-parser@21.1.1"],"schemaVersion":1,"subject":"pkg:npm/yargs-parser@21.1.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-yargs-parser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-yargs-parser",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "yargs-parser": "21.1.1"
      }
    },
    "node_modules/yargs-parser": {
      "version": "21.1.1",
      "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
      "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
      "license": "ISC",
      "engines": {
        "node": ">=12"
      }
    }
  }
}
package.json
{
  "name": "sample-yargs-parser",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of yargs-parser@21.1.1",
  "main": "src/index.mjs",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "yargs-parser": "21.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/yargs-parser@21.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/yargs-parser@21.1.1"
  ]
}
src/index.mjs
import yargsParser from "yargs-parser";

/**
 * Parses command-line arguments using yargs-parser.
 *
 * @param {string|string[]} args - Arguments string or array of argument strings.
 * @param {object} [opts={}] - Parser configuration options.
 * @returns {object} Parsed command-line arguments.
 */
export function parseArgs(args, opts = {}) {
  return yargsParser(args, opts);
}

/**
 * Parses arguments and returns detailed metadata including error and aliases.
 *
 * @param {string|string[]} args - Arguments string or array of argument strings.
 * @param {object} [opts={}] - Parser configuration options.
 * @returns {object} Detailed parsing result.
 */
export function parseDetailed(args, opts = {}) {
  return yargsParser.detailed(args, opts);
}

/**
 * Converts a hyphenated or delimited string into camelCase.
 *
 * @param {string} str - Input string.
 * @returns {string} Camel-cased string.
 */
export function toCamelCase(str) {
  return yargsParser.camelCase(str);
}

/**
 * Converts a camelCase string into a delimited string.
 *
 * @param {string} str - Input string.
 * @param {string} [joinString='-'] - Separator character.
 * @returns {string} Decamelized string.
 */
export function toDecamelize(str, joinString = "-") {
  return yargsParser.decamelize(str, joinString);
}

/**
 * Determines whether a given value looks like a numeric string.
 *
 * @param {any} val - Value to test.
 * @returns {boolean} True if the value appears numeric.
 */
export function looksLikeNumber(val) {
  return yargsParser.looksLikeNumber(val);
}

export default yargsParser;
test/contract.mjs
import assert from "node:assert/strict";
import yargsParser, {
  parseArgs,
  parseDetailed,
  toCamelCase,
  toDecamelize,
  looksLikeNumber,
} from "../src/index.mjs";

// 1. yargsParser parses command-line argument arrays and strings into key-value flags and positional arguments
{
  const parsedArray = yargsParser(["--port", "8080", "--host", "localhost", "build", "target"], {
    number: ["port"],
  });
  assert.strictEqual(parsedArray.port, 8080);
  assert.strictEqual(parsedArray.host, "localhost");
  assert.deepStrictEqual(parsedArray._, ["build", "target"]);

  const parsedString = parseArgs("--mode production file.js");
  assert.strictEqual(parsedString.mode, "production");
  assert.deepStrictEqual(parsedString._, ["file.js"]);
}

// 2. yargsParser handles typed options including boolean flags, aliases, numbers, defaults, and custom coercion
{
  const parsed = parseArgs(["-f", "-c", "4", "--retries", "3"], {
    alias: { f: "force", c: "count" },
    boolean: ["force"],
    number: ["count", "retries"],
    default: { timeout: 5000 },
    coerce: {
      retries: (val) => val * 2,
    },
  });
  assert.strictEqual(parsed.force, true);
  assert.strictEqual(parsed.f, true);
  assert.strictEqual(parsed.count, 4);
  assert.strictEqual(parsed.c, 4);
  assert.strictEqual(parsed.retries, 6);
  assert.strictEqual(parsed.timeout, 5000);
}

// 3. yargsParser expands nested object structures via dot-notation and parses boolean negations
{
  const parsed = parseArgs("--server.host 127.0.0.1 --server.port 3000 --no-ssl --no-cache");
  assert.deepStrictEqual(parsed.server, { host: "127.0.0.1", port: 3000 });
  assert.strictEqual(parsed.ssl, false);
  assert.strictEqual(parsed.cache, false);
}

// 4. yargsParser separates trailing positional arguments following the double-dash delimiter when populate-- configuration is enabled
{
  const parsed = parseArgs(["--watch", "--", "arg1", "arg2", "--opt-inside"], {
    boolean: ["watch"],
    configuration: { "populate--": true },
  });
  assert.strictEqual(parsed.watch, true);
  assert.deepStrictEqual(parsed["--"], ["arg1", "arg2", "--opt-inside"]);
}

// 5. yargsParser.detailed returns detailed arguments object with parsed argv, configuration, aliases, and error state
{
  const detailed = parseDetailed(["-e", "prod"], {
    alias: { e: "env" },
  });
  assert.strictEqual(typeof detailed, "object");
  assert.strictEqual(detailed.error, null);
  assert.strictEqual(detailed.argv.env, "prod");
  assert.strictEqual(detailed.argv.e, "prod");
  assert.strictEqual(typeof detailed.configuration, "object");
  assert.strictEqual(detailed.configuration["boolean-negation"], true);
}

// 6. yargsParser utility methods convert strings with camelCase and decamelize and identify numeric strings with looksLikeNumber
{
  assert.strictEqual(toCamelCase("hello-world-parser"), "helloWorldParser");
  assert.strictEqual(toCamelCase("foo_bar_baz"), "fooBarBaz");

  assert.strictEqual(toDecamelize("helloWorldParser", "-"), "hello-world-parser");
  assert.strictEqual(toDecamelize("fooBarBaz", "_"), "foo_bar_baz");

  assert.strictEqual(looksLikeNumber("12345"), true);
  assert.strictEqual(looksLikeNumber("3.1415"), true);
  assert.strictEqual(looksLikeNumber("0xFF"), true);
  assert.strictEqual(looksLikeNumber("notANumber"), false);
}

console.log("Contract test passed successfully.");

Ursprungs-Seeder

anonym