CodeSampleX

샘플

json-stable-stringify-without-jsonify 1.0.1: stringify

검증된 샘플 — npm json-stable-stringify-without-jsonify 1.0.1: stringify. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:69ffc299da3e9cb29a64c81af3890ac1dfe903b825797277e5d81e97363e2a8b

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

케이스

HOW
목표
verify stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1
패키지
심벌
  • stringify
생성일
2026-09-01T19:51:48Z

컨트랙트

  1. stringify deterministically sorts object keys in alphabetical order regardless of insertion order
  2. stringify supports custom indentation formatting using numeric and string space options
  3. stringify supports custom key comparator functions to define explicit sorting order
  4. stringify supports custom replacer functions to transform or filter object properties
  5. stringify safely handles circular references by returning a placeholder when cycles option is enabled
  6. stringify throws a TypeError on circular references when cycles option is disabled
  7. stringify respects custom toJSON serialization methods on objects
  8. stringify handles nested structures containing arrays, objects, and primitive values

파일

  • 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 stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-stable-stringify-without-jsonify@1.0.1
Demonstrate these symbols/APIs:
  - stringify

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:a508428e5d204c21b9f1bb6bdbe463c8239eb056a6746c5434b02f4689d8fd9c","contract":["stringify deterministically sorts object keys in alphabetical order regardless of insertion order","stringify supports custom indentation formatting using numeric and string space options","stringify supports custom key comparator functions to define explicit sorting order","stringify supports custom replacer functions to transform or filter object properties","stringify safely handles circular references by returning a placeholder when cycles option is enabled","stringify throws a TypeError on circular references when cycles option is disabled","stringify respects custom toJSON serialization methods on objects","stringify handles nested structures containing arrays, objects, and primitive values"],"goal":"verify stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1","kind":"HOW","packages":["pkg:npm/json-stable-stringify-without-jsonify@1.0.1"],"schemaVersion":1,"symbols":["stringify"]},"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/json-stable-stringify-without-jsonify@1.0.1"],"schemaVersion":1,"subject":"pkg:npm/json-stable-stringify-without-jsonify@1.0.1","symbols":["stringify"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json-stable-stringify-without-jsonify",
  "version": "1.0.1",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json-stable-stringify-without-jsonify",
      "version": "1.0.1",
      "license": "MIT-0",
      "dependencies": {
        "json-stable-stringify-without-jsonify": "1.0.1"
      }
    },
    "node_modules/json-stable-stringify-without-jsonify": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
      "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-json-stable-stringify-without-jsonify",
  "version": "1.0.1",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "json-stable-stringify-without-jsonify": "1.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify stringify in pkg:npm/json-stable-stringify-without-jsonify@1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-stable-stringify-without-jsonify@1.0.1"
  ],
  "symbols": [
    "stringify"
  ]
}
src/index.mjs
import stringify from 'json-stable-stringify-without-jsonify';

/**
 * Deterministically stringifies a JavaScript value into a stable JSON string.
 * @param {any} obj The value to serialize
 * @param {object|Function} [opts] Options object or comparison function
 * @returns {string|undefined} The serialized JSON string
 */
export function stableStringify(obj, opts) {
  return stringify(obj, opts);
}

export { stringify };
export default stringify;
test/contract.mjs
import assert from 'node:assert/strict';
import { stringify, stableStringify } from '../src/index.mjs';

// 1. stringify deterministically sorts object keys in alphabetical order regardless of insertion order
{
  const obj1 = { c: 3, a: 1, b: 2 };
  const obj2 = { b: 2, c: 3, a: 1 };
  const result1 = stringify(obj1);
  const result2 = stableStringify(obj2);

  assert.equal(result1, '{"a":1,"b":2,"c":3}');
  assert.equal(result2, '{"a":1,"b":2,"c":3}');
  assert.equal(result1, result2);
}

// 2. stringify supports custom indentation formatting using numeric and string space options
{
  const obj = { b: 2, a: 1 };
  const formattedWithNumber = stringify(obj, { space: 2 });
  assert.equal(formattedWithNumber, '{\n  "a": 1,\n  "b": 2\n}');

  const formattedWithString = stringify(obj, { space: '\t' });
  assert.equal(formattedWithString, '{\n\t"a": 1,\n\t"b": 2\n}');
}

// 3. stringify supports custom key comparator functions to define explicit sorting order
{
  const obj = { apple: 10, zebra: 20, banana: 30 };
  const customSorted = stringify(obj, {
    cmp: (a, b) => b.key.localeCompare(a.key)
  });
  assert.equal(customSorted, '{"zebra":20,"banana":30,"apple":10}');

  const cmpShorthand = stringify(obj, (a, b) => b.key.localeCompare(a.key));
  assert.equal(cmpShorthand, '{"zebra":20,"banana":30,"apple":10}');
}

// 4. stringify supports custom replacer functions to transform or filter object properties
{
  const obj = { id: 1, secret: 'password123', visible: true };
  const filtered = stringify(obj, {
    replacer: (key, value) => {
      if (key === 'secret') return undefined;
      if (typeof value === 'number') return value * 10;
      return value;
    }
  });
  assert.equal(filtered, '{"id":10,"visible":true}');
}

// 5. stringify safely handles circular references by returning a placeholder when cycles option is enabled
{
  const circularObj = { name: 'cycle-test' };
  circularObj.self = circularObj;

  const result = stringify(circularObj, { cycles: true });
  assert.equal(result, '{"name":"cycle-test","self":"__cycle__"}');
}

// 6. stringify throws a TypeError on circular references when cycles option is disabled
{
  const circularObj = { name: 'cycle-error' };
  circularObj.self = circularObj;

  assert.throws(
    () => stringify(circularObj),
    (err) => err instanceof TypeError && /Converting circular structure to JSON/.test(err.message)
  );
}

// 7. stringify respects custom toJSON serialization methods on objects
{
  const customObj = {
    x: 10,
    toJSON() {
      return { normalized: this.x * 2 };
    }
  };
  const result = stringify({ item: customObj });
  assert.equal(result, '{"item":{"normalized":20}}');
}

// 8. stringify handles nested structures containing arrays, objects, and primitive values
{
  const nested = {
    users: [
      { z: 'last', a: 'first' },
      { y: 2, b: 1 }
    ],
    count: 2,
    active: true,
    empty: null
  };
  const result = stringify(nested);
  assert.equal(
    result,
    '{"active":true,"count":2,"empty":null,"users":[{"a":"first","z":"last"},{"b":1,"y":2}]}'
  );
}

console.log('Contract assertions passed.');

오리진 시더

익명