CodeSampleX

샘플

yargs-parser 21.1.1

검증된 샘플 — npm yargs-parser 21.1.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: yargsParser parses command-line argument arrays and strings…

sha256:3246e0f5e686a30bf000a9f3911e478e2485c0d45540a5a7dacb67aeefa112d3

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-23

케이스

HOW
목표
verify pkg:npm/yargs-parser@21.1.1
패키지
생성일
2026-08-23T08:19:27Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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.");

오리진 시더

익명