CodeSampleX

Exemple

react-is 18.3.1: isPortal

Échantillon vérifié pour npm react-is 18.3.1: isPortal. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:4b95dcafd96f5b68601e3543046be2acd58355b848208302d7c93ffe2aa8977e

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-30

Cas

HOW
Objectif
verify react-is.isPortal in pkg:npm/react-is@18.3.1
Paquets
Symboles
  • react-is.isPortal
Créé
2026-08-30T09:59:25Z

Contrat

  1. isPortal identifies React portal objects with react.portal symbol type
  2. isPortal returns false for non-portal elements, plain objects, null, undefined, and primitives
  3. Portal symbol matches typeOf on valid React portal objects

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 react-is.isPortal in pkg:npm/react-is@18.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-is@18.3.1
Demonstrate these symbols/APIs:
  - react-is.isPortal

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:c87bd1ac326d4a0e3f784529faf8edb13362a3d28a2647a8bcb634c979f6996b","contract":["isPortal identifies React portal objects with react.portal symbol type","isPortal returns false for non-portal elements, plain objects, null, undefined, and primitives","Portal symbol matches typeOf on valid React portal objects"],"goal":"verify react-is.isPortal in pkg:npm/react-is@18.3.1","kind":"HOW","packages":["pkg:npm/react-is@18.3.1"],"schemaVersion":1,"symbols":["react-is.isPortal"]},"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/react-is@18.3.1"],"schemaVersion":1,"subject":"pkg:npm/react-is@18.3.1","symbols":["react-is.isPortal"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-is-portal",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-is-portal",
      "version": "1.0.0",
      "dependencies": {
        "react-is": "18.3.1"
      }
    },
    "node_modules/react-is": {
      "version": "18.3.1",
      "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",
      "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-react-is-portal",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of react-is isPortal API",
  "type": "module",
  "main": "src/index.js",
  "dependencies": {
    "react-is": "18.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-is.isPortal in pkg:npm/react-is@18.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-is@18.3.1"
  ],
  "symbols": [
    "react-is.isPortal"
  ]
}
src/index.js
import { isPortal, Portal, typeOf } from 'react-is';

/**
 * Check if the given value is a valid React portal object.
 *
 * @param {*} value - The value to check.
 * @returns {boolean} True if the value is a React portal.
 */
export function checkIsPortal(value) {
  return isPortal(value);
}

/**
 * Create a mock React portal object.
 *
 * @param {*} children - Portal children.
 * @param {*} containerInfo - DOM container or target info.
 * @param {string|null} key - Optional key.
 * @returns {object} A React portal element structure.
 */
export function createMockPortal(children = null, containerInfo = {}, key = null) {
  return {
    $$typeof: Symbol.for('react.portal'),
    key,
    children,
    containerInfo,
    implementation: null,
  };
}

export { isPortal, Portal, typeOf };
test/contract.mjs
import assert from 'node:assert/strict';
import {
  checkIsPortal,
  createMockPortal,
  isPortal,
  Portal,
  typeOf,
} from '../src/index.js';

// 1. Export types and symbols verification
assert.equal(typeof isPortal, 'function', 'isPortal should be an exported function');
assert.equal(typeof checkIsPortal, 'function', 'checkIsPortal helper should be a function');
assert.equal(typeof createMockPortal, 'function', 'createMockPortal helper should be a function');
assert.equal(typeof Portal, 'symbol', 'Portal should be an exported symbol');

// 2. isPortal identifies React portal objects with react.portal symbol type
const portalObject = createMockPortal('hello portal', { nodeType: 1 }, 'portal-key');
assert.equal(isPortal(portalObject), true, 'isPortal should return true for a valid React portal object');
assert.equal(checkIsPortal(portalObject), true, 'checkIsPortal helper should return true for a valid React portal object');

const directPortal = {
  $$typeof: Symbol.for('react.portal'),
  key: null,
  children: null,
  containerInfo: {},
  implementation: null,
};
assert.equal(isPortal(directPortal), true, 'isPortal should return true for direct portal representation');

// 3. isPortal returns false for non-portal elements, plain objects, null, undefined, and primitives
const plainElement = {
  $$typeof: Symbol.for('react.element'),
  type: 'div',
  props: {},
  key: null,
  ref: null,
};
assert.equal(isPortal(plainElement), false, 'isPortal should return false for standard React elements');
assert.equal(isPortal({}), false, 'isPortal should return false for empty plain objects');
assert.equal(isPortal(null), false, 'isPortal should return false for null');
assert.equal(isPortal(undefined), false, 'isPortal should return false for undefined');
assert.equal(isPortal('portal'), false, 'isPortal should return false for string primitives');
assert.equal(isPortal(12345), false, 'isPortal should return false for number primitives');
assert.equal(isPortal(true), false, 'isPortal should return false for boolean primitives');
assert.equal(isPortal([]), false, 'isPortal should return false for arrays');

// 4. Portal symbol matches typeOf on valid React portal objects
assert.equal(typeOf(portalObject), Portal, 'typeOf(portalObject) must equal Portal');
assert.equal(typeOf(directPortal), Portal, 'typeOf(directPortal) must equal Portal');
assert.notEqual(typeOf(plainElement), Portal, 'typeOf(plainElement) must not equal Portal');

console.log('All contract tests for react-is.isPortal in react-is@18.3.1 passed.');

Seeder d'origine

anonyme