CodeSampleX

サンプル

parse-conflict-json 4.0.0

検証済みサンプル — npm parse-conflict-json 4.0.0. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: parseConflictJson parses plain JSON without conflict…

sha256:088961ae1050655b46b267aa4bff098f2e203ecd380da837d43596d3ced021fc

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-10-18

ケース

HOW
ゴール
verify pkg:npm/parse-conflict-json@4.0.0
パッケージ
作成日
2026-10-18T09:13:31Z

コントラクト

  1. parseConflictJson parses plain JSON without conflict markers and isDiff returns falsy
  2. parseConflictJson resolves diff3-style JSON conflicts (<{7}, |{7}, ={7}, >{7}) preferring 'ours' by default or 'theirs' when specified
  3. parseConflictJson applies an optional JSON reviver to parent, ours, and theirs branches before merging
  4. parseConflictJson throws TypeError when prefer is neither 'ours' nor 'theirs'

ファイル

  • 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/parse-conflict-json@4.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/parse-conflict-json@4.0.0

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:ca10eb6722dc3854c82c4ad826ad7773dcb4e237d1d030feadb45d320f58b3a4","contract":["parseConflictJson parses plain JSON without conflict markers and isDiff returns falsy","parseConflictJson resolves diff3-style JSON conflicts (\u003c{7}, |{7}, ={7}, \u003e{7}) preferring 'ours' by default or 'theirs' when specified","parseConflictJson applies an optional JSON reviver to parent, ours, and theirs branches before merging","parseConflictJson throws TypeError when prefer is neither 'ours' nor 'theirs'"],"goal":"verify pkg:npm/parse-conflict-json@4.0.0","kind":"HOW","packages":["pkg:npm/parse-conflict-json@4.0.0"],"schemaVersion":1,"symbols":["parseConflictJSON","isDiff"]},"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/parse-conflict-json@4.0.0"],"schemaVersion":1,"subject":"pkg:npm/parse-conflict-json@4.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-parse-conflict-json",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-parse-conflict-json",
      "version": "1.0.0",
      "dependencies": {
        "parse-conflict-json": "4.0.0"
      }
    },
    "node_modules/json-parse-even-better-errors": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-4.0.0.tgz",
      "integrity": "sha512-lR4MXjGNgkJc7tkQ97kb2nuEMnNCyU//XYVH0MKTGcXEiSudQ5MKGKen3C5QubYy0vmq+JGitUg92uuywGEwIA==",
      "license": "MIT",
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/just-diff": {
      "version": "6.0.2",
      "resolved": "https://registry.npmjs.org/just-diff/-/just-diff-6.0.2.tgz",
      "integrity": "sha512-S59eriX5u3/QhMNq3v/gm8Kd0w8OS6Tz2FS1NG4blv+z0MuQcBRJyFWjdovM0Rad4/P4aUPFtnkNjMjyMlMSYA==",
      "license": "MIT"
    },
    "node_modules/just-diff-apply": {
      "version": "5.5.0",
      "resolved": "https://registry.npmjs.org/just-diff-apply/-/just-diff-apply-5.5.0.tgz",
      "integrity": "sha512-OYTthRfSh55WOItVqwpefPtNt2VdKsq5AnAK6apdtR6yCH8pr0CmSr710J0Mf+WdQy7K/OzMy7K2MgAfdQURDw==",
      "license": "MIT"
    },
    "node_modules/parse-conflict-json": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/parse-conflict-json/-/parse-conflict-json-4.0.0.tgz",
      "integrity": "sha512-37CN2VtcuvKgHUs8+0b1uJeEsbGn61GRHz469C94P5xiOoqpDYJYwjg4RY9Vmz39WyZAVkR5++nbJwLMIgOCnQ==",
      "license": "ISC",
      "dependencies": {
        "json-parse-even-better-errors": "^4.0.0",
        "just-diff": "^6.0.0",
        "just-diff-apply": "^5.2.0"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    }
  }
}
package.json
{
  "name": "verify-parse-conflict-json",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "parse-conflict-json": "4.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/parse-conflict-json@4.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/parse-conflict-json@4.0.0"
  ]
}
src/index.mjs
import parseConflictJson from 'parse-conflict-json';

export function parseConflictedJson(input, reviver, prefer) {
  return parseConflictJson(input, reviver, prefer);
}

export function hasConflictMarkers(input) {
  return Boolean(parseConflictJson.isDiff(input));
}
test/contract.mjs
import assert from 'node:assert/strict';
import parseConflictJson from 'parse-conflict-json';
import { parseConflictedJson, hasConflictMarkers } from '../src/index.mjs';

const stripFormattingSymbols = (obj) => JSON.parse(JSON.stringify(obj));

// 1. Plain JSON without conflict markers
const plainJson = '{"name": "sample", "count": 1}';
assert.equal(hasConflictMarkers(plainJson), false);
const parsedPlain = parseConflictedJson(plainJson);
assert.deepEqual(stripFormattingSymbols(parsedPlain), { name: 'sample', count: 1 });
// json-parse-even-better-errors attaches Symbol.for('indent') and Symbol.for('newline')
assert.equal(parsedPlain[Symbol.for('indent')], '');
assert.equal(parsedPlain[Symbol.for('newline')], '');

// 2. 3-way merge conflict (diff3 style with <<<<<<<, |||||||, =======, >>>>>>>)
const conflicted3Way = [
  '{',
  '<<<<<<< HEAD',
  '  "shared": "ours",',
  '  "leftOnly": 10',
  '||||||| parent',
  '  "shared": "base"',
  '=======',
  '  "shared": "theirs",',
  '  "rightOnly": 20',
  '>>>>>>> branch',
  '}'
].join('\n');

assert.equal(hasConflictMarkers(conflicted3Way), true);

// Default prefer is 'ours'
const resolvedOurs = parseConflictedJson(conflicted3Way);
assert.deepEqual(stripFormattingSymbols(resolvedOurs), {
  shared: 'ours',
  leftOnly: 10,
  rightOnly: 20
});

// Prefer 'theirs'
const resolvedTheirs = parseConflictedJson(conflicted3Way, null, 'theirs');
assert.deepEqual(stripFormattingSymbols(resolvedTheirs), {
  shared: 'theirs',
  leftOnly: 10,
  rightOnly: 20
});

// 3. Reviver function support on conflicted JSON
const revived = parseConflictJson(
  conflicted3Way,
  (key, val) => (typeof val === 'number' ? val * 2 : val),
  'ours'
);
assert.deepEqual(stripFormattingSymbols(revived), {
  shared: 'ours',
  leftOnly: 20,
  rightOnly: 40
});

// 4. Invalid prefer parameter throws TypeError
assert.throws(
  () => parseConflictJson(plainJson, null, 'invalid'),
  {
    name: 'TypeError',
    message: /prefer param must be "ours" or "theirs" if set/
  }
);

オリジンシーダー

匿名