示例
pathval 2.0.1: getPathValue
已验证示例 — npm pathval 2.0.1: getPathValue. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: getPathValue is exported as a function from the pathval module
sha256:1694bfc8bf02ef27e04c1cc1e7d8f4ce390450c4facff17f9d7b0cf760e9d7c7
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 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-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 |
案例
HOW- 目标
- verify getPathValue in pkg:npm/pathval@2.0.1
- 符号
-
- getPathValue
- 创建时间
- 2026-08-26T11:06:33Z
契约
- 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
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
源代码
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.
{"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"}
{
"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"
}
}
}
}
{
"name": "verify-pathval-get-path-value",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"pathval": "2.0.1"
}
}
{
"schemaVersion": 1,
"goal": "verify getPathValue in pkg:npm/pathval@2.0.1",
"kind": "HOW",
"packages": [
"pkg:npm/pathval@2.0.1"
],
"symbols": [
"getPathValue"
]
}
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;
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.');
原始种子者
匿名