CodeSampleX

Beispiel

pathval 2.0.1: getPathValue

Verifiziertes Beispiel für npm pathval 2.0.1: getPathValue. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:1694bfc8bf02ef27e04c1cc1e7d8f4ce390450c4facff17f9d7b0cf760e9d7c7

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
2
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-26
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-07

Fall

HOW
Ziel
verify getPathValue in pkg:npm/pathval@2.0.1
Pakete
Symbole
  • getPathValue
Erstellt
2026-08-26T11:06:33Z

Contract

  1. getPathValue is exported as a function from the pathval module
  2. getPathValue retrieves shallow and deeply nested object properties using dot-delimited path strings
  3. getPathValue retrieves array elements by index using bracket notation and supports chained object properties within arrays
  4. getPathValue resolves property keys containing literal dots and brackets when escaped with backslashes
  5. getPathValue returns undefined for non-existent direct properties and null when intermediate path segments do not exist
  6. getPathValue returns null without throwing when the target object is null or undefined
  7. getPathValue resolves property and index access on primitive values including string characters and string length
  8. getPathValue prevents prototype pollution by returning undefined when querying prototype, constructor, or __proto__ properties
  9. getPathValue accurately preserves and retrieves falsy values such as false, 0, empty string, and null

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 getPathValue in pkg:npm/pathval@2.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/pathval@2.0.1
Demonstrate these symbols/APIs:
  - getPathValue

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:d8480a77fe50424148a1c99b01a64954e9c218a43ab47a51b18d234d235be805","contract":["getPathValue is exported as a function from the pathval module","getPathValue retrieves shallow and deeply nested object properties using dot-delimited path strings","getPathValue retrieves array elements by index using bracket notation and supports chained object properties within arrays","getPathValue resolves property keys containing literal dots and brackets when escaped with backslashes","getPathValue returns undefined for non-existent direct properties and null when intermediate path segments do not exist","getPathValue returns null without throwing when the target object is null or undefined","getPathValue resolves property and index access on primitive values including string characters and string length","getPathValue prevents prototype pollution by returning undefined when querying prototype, constructor, or __proto__ properties","getPathValue accurately preserves and retrieves falsy values such as false, 0, empty string, and null"],"goal":"verify getPathValue in pkg:npm/pathval@2.0.1","kind":"HOW","packages":["pkg:npm/pathval@2.0.1"],"schemaVersion":1,"symbols":["getPathValue"]},"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/pathval@2.0.1"],"schemaVersion":1,"subject":"pkg:npm/pathval@2.0.1","symbols":["getPathValue"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "verify-pathval-get-path-value",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-pathval-get-path-value",
      "version": "1.0.0",
      "dependencies": {
        "pathval": "2.0.1"
      }
    },
    "node_modules/pathval": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz",
      "integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 14.16"
      }
    }
  }
}
package.json
{
  "name": "verify-pathval-get-path-value",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "pathval": "2.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify getPathValue in pkg:npm/pathval@2.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/pathval@2.0.1"
  ],
  "symbols": [
    "getPathValue"
  ]
}
src/index.mjs
import { getPathValue, getPathInfo, hasProperty, setPathValue } from 'pathval';

/**
 * Retrieve the value located at a string path in an object.
 *
 * @param {Object} obj - Target object to query
 * @param {string} path - Dot/bracket notation path (e.g. "a.b[0].c")
 * @returns {*} The value at the path or undefined if not found
 */
export function getValueByPath(obj, path) {
  return getPathValue(obj, path);
}

export { getPathValue, getPathInfo, hasProperty, setPathValue };
export default getPathValue;
test/contract.mjs
import assert from 'node:assert/strict';
import { getPathValue } from 'pathval';
import { getValueByPath } from '../src/index.mjs';

// 1. Module export verification
{
  assert.equal(typeof getPathValue, 'function');
  assert.equal(typeof getValueByPath, 'function');
}

// 2. getPathValue retrieves shallow and deeply nested object properties using dot-delimited path strings
{
  const data = {
    user: {
      name: 'Alice',
      profile: {
        age: 30,
        city: 'Seoul'
      }
    },
    version: '2.0.1'
  };

  assert.equal(getPathValue(data, 'version'), '2.0.1');
  assert.equal(getPathValue(data, 'user.name'), 'Alice');
  assert.equal(getPathValue(data, 'user.profile.age'), 30);
  assert.equal(getPathValue(data, 'user.profile.city'), 'Seoul');
  assert.equal(getValueByPath(data, 'user.name'), 'Alice');
}

// 3. getPathValue retrieves array elements by index using bracket notation and supports chained object properties within arrays
{
  const catalog = {
    departments: [
      {
        name: 'Engineering',
        members: ['Alice', 'Bob'],
        leads: [
          { role: 'Tech Lead', level: 5 },
          { role: 'Team Lead', level: 4 }
        ]
      },
      {
        name: 'Design',
        members: ['Charlie']
      }
    ]
  };

  assert.equal(getPathValue(catalog, 'departments[0].name'), 'Engineering');
  assert.equal(getPathValue(catalog, 'departments[0].members[0]'), 'Alice');
  assert.equal(getPathValue(catalog, 'departments[0].members[1]'), 'Bob');
  assert.equal(getPathValue(catalog, 'departments[0].leads[1].role'), 'Team Lead');
  assert.equal(getPathValue(catalog, 'departments[1].name'), 'Design');
  assert.equal(getPathValue(catalog, 'departments[1].members[0]'), 'Charlie');
}

// 4. getPathValue resolves property keys containing literal dots and brackets when escaped with backslashes
{
  const complexKeys = {
    'service.endpoint': 'https://example.com/api',
    'matrix[0]': {
      'nested.key': 42
    },
    config: {
      'port:8080.ssl': true
    }
  };

  assert.equal(getPathValue(complexKeys, 'service\\.endpoint'), 'https://example.com/api');
  assert.equal(getPathValue(complexKeys, 'matrix\\[0\\].nested\\.key'), 42);
  assert.equal(getPathValue(complexKeys, 'config.port:8080\\.ssl'), true);
}

// 5. getPathValue returns undefined for non-existent direct properties and null when intermediate path segments do not exist
{
  const target = {
    user: {
      name: 'Alice'
    }
  };

  assert.equal(getPathValue(target, 'unknown'), undefined);
  assert.equal(getPathValue(target, 'user.missingField'), undefined);
  assert.equal(getPathValue(target, 'user.missingField.nested'), null);
  assert.equal(getPathValue(target, 'deeply.nested.non.existent.path'), null);
}

// 6. getPathValue returns null without throwing when the target object is null or undefined
{
  assert.equal(getPathValue(null, 'user.name'), null);
  assert.equal(getPathValue(undefined, 'user.name'), null);
  assert.equal(getPathValue(null, 'items[0]'), null);
  assert.equal(getPathValue(undefined, 'items[0]'), null);
}

// 7. getPathValue resolves property and index access on primitive values including string characters and string length
{
  assert.equal(getPathValue('hello world', 'length'), 11);
  assert.equal(getPathValue('hello', '[0]'), 'h');
  assert.equal(getPathValue('hello', '[4]'), 'o');
  assert.equal(getPathValue(12345, 'toString'), Number.prototype.toString);
}

// 8. getPathValue prevents prototype pollution by returning undefined when querying prototype, constructor, or __proto__ properties
{
  const sampleObj = { data: 'valid' };

  assert.equal(getPathValue(sampleObj, '__proto__'), undefined);
  assert.equal(getPathValue(sampleObj, 'constructor'), undefined);
  assert.equal(getPathValue(sampleObj, 'prototype'), undefined);
  assert.equal(getPathValue(sampleObj, 'data.__proto__'), undefined);
}

// 9. getPathValue accurately preserves and retrieves falsy values such as false, 0, empty string, and null
{
  const falsyData = {
    flags: [false, 0, '', null, undefined, NaN],
    settings: {
      enabled: false,
      count: 0,
      prefix: '',
      fallback: null
    }
  };

  assert.equal(getPathValue(falsyData, 'flags[0]'), false);
  assert.equal(getPathValue(falsyData, 'flags[1]'), 0);
  assert.equal(getPathValue(falsyData, 'flags[2]'), '');
  assert.equal(getPathValue(falsyData, 'flags[3]'), null);
  assert.equal(getPathValue(falsyData, 'flags[4]'), undefined);
  assert.ok(Number.isNaN(getPathValue(falsyData, 'flags[5]')));

  assert.equal(getPathValue(falsyData, 'settings.enabled'), false);
  assert.equal(getPathValue(falsyData, 'settings.count'), 0);
  assert.equal(getPathValue(falsyData, 'settings.prefix'), '');
  assert.equal(getPathValue(falsyData, 'settings.fallback'), null);
}

console.log('All pathval getPathValue contract tests passed successfully.');

Ursprungs-Seeder

anonym