CodeSampleX

示例

hasown 2.0.4: hasOwn

已验证示例 — npm hasown 2.0.4: hasOwn. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: hasOwn returns true for direct own properties on plain objects…

sha256:c886ab294bb3afe864b94927cf821cc736b627449a5bc3a9ae3c326afa5e51dd

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22 linux x64 node 22 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

案例

HOW
目标
verify pkg:npm/hasown@2.0.4
包
符号
  • hasOwn
环境
node 22
创建时间
2026-08-18T17:58:24Z

契约

  1. hasOwn returns true for direct own properties on plain objects including undefined and null values
  2. hasOwn returns false for inherited prototype properties like toString and valueOf
  3. hasOwn returns true for valid array indices and length property while returning false for out of bounds indices and array prototype methods
  4. hasOwn works correctly on objects created with Object.create(null) lacking Object prototype methods
  5. hasOwn correctly identifies properties on objects where hasOwnProperty is shadowed or overridden
  6. hasOwn returns true for properties with falsy values such as false, empty string, and zero
  7. hasOwn supports Symbol properties when Symbol is available in the environment

文件

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

下载源代码构件 (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/hasown@2.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/hasown@2.0.4
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:e872aa68f1629b728f550338c4935085a16e4c372bc9d43b5b985d89f7e22b95","constraints":{"executionContext":"node"},"contract":["hasOwn returns true for direct own properties on plain objects including undefined and null values","hasOwn returns false for inherited prototype properties like toString and valueOf","hasOwn returns true for valid array indices and length property while returning false for out of bounds indices and array prototype methods","hasOwn works correctly on objects created with Object.create(null) lacking Object prototype methods","hasOwn correctly identifies properties on objects where hasOwnProperty is shadowed or overridden","hasOwn returns true for properties with falsy values such as false, empty string, and zero","hasOwn supports Symbol properties when Symbol is available in the environment"],"goal":"verify pkg:npm/hasown@2.0.4","kind":"HOW","packages":["pkg:npm/hasown@2.0.4"],"schemaVersion":1,"symbols":["hasOwn"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"linux","packageManager":"npm","packageManagerVersion":"10","runtime":"node","runtimeVersion":"22","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/hasown@2.0.4"],"schemaVersion":1,"symbols":["hasOwn"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

var hasOwn = require('hasown');

function checkProperty(object, property) {
  return hasOwn(object, property);
}

module.exports = {
  hasOwn: hasOwn,
  checkProperty: checkProperty
};
package-lock.json
{
  "name": "sample-hasown",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hasown",
      "version": "1.0.0",
      "dependencies": {
        "hasown": "2.0.4"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/hasown": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
      "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
      "license": "MIT",
      "dependencies": {
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    }
  }
}
package.json
{
  "name": "sample-hasown",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of hasown package",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "hasown": "2.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/hasown@2.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/hasown@2.0.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.js
'use strict';

var assert = require('assert');
var sample = require('../index.js');
var hasOwn = sample.hasOwn;

// 1. Direct own properties on plain objects
var obj = { a: 1, b: undefined, nullProp: null };
assert.strictEqual(hasOwn(obj, 'a'), true);
assert.strictEqual(hasOwn(obj, 'b'), true);
assert.strictEqual(hasOwn(obj, 'nullProp'), true);
assert.strictEqual(hasOwn(obj, 'c'), false);

// 2. Inherited properties return false
assert.strictEqual(hasOwn(obj, 'toString'), false);
assert.strictEqual(hasOwn(obj, 'valueOf'), false);
assert.strictEqual(hasOwn(obj, 'hasOwnProperty'), false);

// 3. Array indices and length property
var arr = [10, 20, 30];
assert.strictEqual(hasOwn(arr, 0), true);
assert.strictEqual(hasOwn(arr, '0'), true);
assert.strictEqual(hasOwn(arr, 2), true);
assert.strictEqual(hasOwn(arr, 3), false);
assert.strictEqual(hasOwn(arr, 'length'), true);
assert.strictEqual(hasOwn(arr, 'map'), false);

// 4. Objects created with Object.create(null) (no prototype)
var nullProtoObj = Object.create(null);
nullProtoObj.key = 'value';
assert.strictEqual(hasOwn(nullProtoObj, 'key'), true);
assert.strictEqual(hasOwn(nullProtoObj, 'missing'), false);

// 5. Objects with shadowed / overridden hasOwnProperty
var shadowed = {
  hasOwnProperty: function () {
    return false;
  },
  foo: 'bar'
};
assert.strictEqual(hasOwn(shadowed, 'foo'), true);
assert.strictEqual(hasOwn(shadowed, 'hasOwnProperty'), true);
assert.strictEqual(hasOwn(shadowed, 'nonexistent'), false);

// 6. Object with property having falsy or boolean values
var boolObj = { flag: false, empty: '', zero: 0 };
assert.strictEqual(hasOwn(boolObj, 'flag'), true);
assert.strictEqual(hasOwn(boolObj, 'empty'), true);
assert.strictEqual(hasOwn(boolObj, 'zero'), true);

// 7. Symbol properties
if (typeof Symbol === 'function') {
  var sym = Symbol('test');
  var symObj = {};
  symObj[sym] = 42;
  assert.strictEqual(hasOwn(symObj, sym), true);
}

// 8. Custom wrapper checkProperty
assert.strictEqual(sample.checkProperty(obj, 'a'), true);
assert.strictEqual(sample.checkProperty(obj, 'missing'), false);

console.log('PASS: hasown contract verified');

原始种子者

匿名