CodeSampleX

Sample

natural-compare 1.4.0

Verified sample for npm natural-compare 1.4.0. The contract ran on node 22 · linux alpine/x64 · docker and passed: naturalCompare returns 0 for identical…

sha256:d12664cfaec501fbb2a0c93f1e2bfbdaf99e565cfb9b86e8167c0f1b1d2be386

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Case

HOW
Goal
verify pkg:npm/natural-compare@1.4.0
Packages
Environment
node 22.23.2
Created
2026-08-20T18:43:23Z

Contract

  1. naturalCompare returns 0 for identical strings and empty strings
  2. naturalCompare sorts multi-digit numbers embedded in strings in natural numerical order
  3. naturalCompare orders alphabetical strings in ascending lexicographical order
  4. naturalCompare places uppercase characters before lowercase characters in default sorting order
  5. naturalCompare works as a comparator with Array.prototype.sort to naturally order string lists
  6. naturalCompare coerces non-string arguments to strings before performing comparison
  7. naturalCompare supports custom character precedence configured on String.alphabet

Files

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

Download the source artifact (tar.gz)

Source

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/natural-compare@1.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/natural-compare@1.4.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - runtime: node@22.23.2

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:ce4def86c72fdc703c2b91c785893112fbd732a4a5fb75911255c05dbdd49c0b","constraints":{"executionContext":"node"},"contract":["naturalCompare returns 0 for identical strings and empty strings","naturalCompare sorts multi-digit numbers embedded in strings in natural numerical order","naturalCompare orders alphabetical strings in ascending lexicographical order","naturalCompare places uppercase characters before lowercase characters in default sorting order","naturalCompare works as a comparator with Array.prototype.sort to naturally order string lists","naturalCompare coerces non-string arguments to strings before performing comparison","naturalCompare supports custom character precedence configured on String.alphabet"],"goal":"verify pkg:npm/natural-compare@1.4.0","kind":"HOW","packages":["pkg:npm/natural-compare@1.4.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/natural-compare@1.4.0"],"schemaVersion":1,"subject":"pkg:npm/natural-compare@1.4.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-natural-compare",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-natural-compare",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "natural-compare": "1.4.0"
      }
    },
    "node_modules/natural-compare": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
      "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-natural-compare",
  "version": "1.0.0",
  "description": "verify pkg:npm/natural-compare@1.4.0",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "natural-compare": "1.4.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/natural-compare@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/natural-compare@1.4.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const naturalCompare = require('natural-compare');

/**
 * Compare two strings in natural sort order.
 *
 * @param {string|number} a - First value to compare.
 * @param {string|number} b - Second value to compare.
 * @returns {number} -1 if a < b, 1 if a > b, 0 if equal.
 */
function compare(a, b) {
  return naturalCompare(a, b);
}

module.exports = {
  naturalCompare,
  compare
};
test/contract.js
'use strict';

const assert = require('assert');
const { naturalCompare, compare } = require('../src/index');

// 1. Module export verification
{
  assert.strictEqual(typeof naturalCompare, 'function');
  assert.strictEqual(typeof compare, 'function');
}

// 2. naturalCompare returns 0 for identical strings and empty strings
{
  assert.strictEqual(naturalCompare('alpha', 'alpha'), 0);
  assert.strictEqual(naturalCompare('', ''), 0);
  assert.strictEqual(naturalCompare('item42', 'item42'), 0);
  assert.strictEqual(compare('abc', 'abc'), 0);
}

// 3. naturalCompare sorts multi-digit numbers embedded in strings in natural numerical order
{
  assert.strictEqual(naturalCompare('file2.txt', 'file10.txt'), -1);
  assert.strictEqual(naturalCompare('file10.txt', 'file2.txt'), 1);
  assert.strictEqual(naturalCompare('item1', 'item2'), -1);
  assert.strictEqual(naturalCompare('img100.png', 'img20.png'), 1);
}

// 4. naturalCompare orders alphabetical strings in ascending lexicographical order
{
  assert.strictEqual(naturalCompare('a', 'b'), -1);
  assert.strictEqual(naturalCompare('b', 'a'), 1);
  assert.strictEqual(naturalCompare('foo', 'bar'), 1);
  assert.strictEqual(naturalCompare('bar', 'foo'), -1);
}

// 5. naturalCompare places uppercase characters before lowercase characters in default sorting order
{
  assert.strictEqual(naturalCompare('A', 'a'), -1);
  assert.strictEqual(naturalCompare('a', 'A'), 1);
  assert.strictEqual(naturalCompare('Z', 'a'), -1);
}

// 6. naturalCompare works as a comparator with Array.prototype.sort to naturally order string lists
{
  const files = ['file10.txt', 'file2.txt', 'file1.txt', 'file20.txt'];
  files.sort(naturalCompare);
  assert.deepStrictEqual(files, ['file1.txt', 'file2.txt', 'file10.txt', 'file20.txt']);

  const versions = ['v1.10.0', 'v1.2.0', 'v1.1.0'];
  versions.sort(naturalCompare);
  assert.deepStrictEqual(versions, ['v1.1.0', 'v1.2.0', 'v1.10.0']);
}

// 7. naturalCompare coerces non-string arguments to strings before performing comparison
{
  assert.strictEqual(naturalCompare(2, 10), -1);
  assert.strictEqual(naturalCompare(10, 2), 1);
  assert.strictEqual(naturalCompare(5, 5), 0);
}

// 8. naturalCompare supports custom character precedence configured on String.alphabet
{
  String.alphabet = 'BAb';
  assert.strictEqual(naturalCompare('B', 'A'), -1);
  assert.strictEqual(naturalCompare('A', 'B'), 1);
  delete String.alphabet;
}

console.log('All natural-compare contract tests passed.');

Origin Seeder

anonymous