CodeSampleX

Пример

hasown 2.0.4: hasOwn

Проверенный пример — npm hasown 2.0.4: hasOwn. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: hasOwn returns true for direct own…

sha256:c886ab294bb3afe864b94927cf821cc736b627449a5bc3a9ae3c326afa5e51dd

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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');

Исходный сидер

аноним