CodeSampleX

Exemplo

lodash.isequal 4.5.0: deep comparison with lodash.isequal

Amostra verificada para npm lodash.isequal 4.5.0: deep comparison with lodash.isequal. O contrato rodou em node 22 · linux alpine/x64 · docker e passou.

sha256:444f6d2b34eb867bd162812ad26c6afe131826ffdf899289763cce25f3712501

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-28

Caso

HOW
Objetivo
deep comparison with lodash.isequal
Pacotes
Símbolos
  • isEqual
Criado
2026-08-28T05:00:50Z

Contrato

  1. isEqual returns true for equivalent primitive values including identical strings, numbers, booleans, and NaN
  2. isEqual performs deep equality comparison between nested plain objects with identical keys and values
  3. isEqual performs deep equality comparison between arrays of identical order, length, and elements
  4. isEqual returns true for equivalent Date and RegExp instances with identical internal state
  5. isEqual returns true for equivalent Map and Set instances with matching entries and values
  6. isEqual handles circular references without entering infinite recursion
  7. isEqual returns false for values with different types, differing nested properties, or different array lengths
  8. isEqual compares functions by reference and treats distinct function instances as not equal

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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: deep comparison with lodash.isequal
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/lodash.isequal@4.5.0
Demonstrate these symbols/APIs:
  - isEqual

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:53e6128b3c66ce3f4a1b5908bd2788533928db8d848c71fa6cb21e69b94a131d","contract":["isEqual returns true for equivalent primitive values including identical strings, numbers, booleans, and NaN","isEqual performs deep equality comparison between nested plain objects with identical keys and values","isEqual performs deep equality comparison between arrays of identical order, length, and elements","isEqual returns true for equivalent Date and RegExp instances with identical internal state","isEqual returns true for equivalent Map and Set instances with matching entries and values","isEqual handles circular references without entering infinite recursion","isEqual returns false for values with different types, differing nested properties, or different array lengths","isEqual compares functions by reference and treats distinct function instances as not equal"],"goal":"deep comparison with lodash.isequal","kind":"HOW","packages":["pkg:npm/lodash.isequal@4.5.0"],"schemaVersion":1,"symbols":["isEqual"]},"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/lodash.isequal@4.5.0"],"schemaVersion":1,"subject":"pkg:npm/lodash.isequal@4.5.0","symbols":["isEqual"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-lodash-isequal",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-lodash-isequal",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "lodash.isequal": "4.5.0"
      }
    },
    "node_modules/lodash.isequal": {
      "version": "4.5.0",
      "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
      "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
      "deprecated": "This package is deprecated. Use require('node:util').isDeepStrictEqual instead.",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-lodash-isequal",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "lodash.isequal": "4.5.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "deep comparison with lodash.isequal",
  "kind": "HOW",
  "packages": [
    "pkg:npm/lodash.isequal@4.5.0"
  ],
  "symbols": [
    "isEqual"
  ]
}
src/index.mjs
import isEqual from 'lodash.isequal';

/**
 * Compare two values deeply to determine if they are equivalent.
 * @param {*} value The value to compare.
 * @param {*} other The other value to compare.
 * @returns {boolean} Returns true if the values are equivalent, else false.
 */
export function areValuesEqual(value, other) {
  return isEqual(value, other);
}

/**
 * Check if an object matches a subset of expected key-value pairs deeply.
 * @param {Record<string, any>} object The target object.
 * @param {Record<string, any>} subset The expected subset object.
 * @returns {boolean} Returns true if subset matches deeply, else false.
 */
export function matchesSubset(object, subset) {
  if (typeof object !== 'object' || object === null) {
    return false;
  }
  return Object.keys(subset).every((key) => isEqual(object[key], subset[key]));
}

/**
 * Filter an array of items to return only those deeply equal to a target value.
 * @param {Array<any>} items The items to filter.
 * @param {*} target The target value to compare against.
 * @returns {Array<any>} Filtered items deeply equal to target.
 */
export function filterEqualItems(items, target) {
  return items.filter((item) => isEqual(item, target));
}

export { isEqual };
export default isEqual;
test/contract.mjs
import assert from 'node:assert/strict';
import { isEqual, areValuesEqual, matchesSubset, filterEqualItems } from '../src/index.mjs';

// 1. isEqual returns true for equivalent primitive values including identical strings, numbers, booleans, and NaN
{
  assert.equal(isEqual(42, 42), true);
  assert.equal(isEqual('hello', 'hello'), true);
  assert.equal(isEqual(true, true), true);
  assert.equal(isEqual(null, null), true);
  assert.equal(isEqual(undefined, undefined), true);
  assert.equal(isEqual(NaN, NaN), true);
  assert.equal(isEqual(+0, -0), true);

  assert.equal(areValuesEqual('test', 'test'), true);
}

// 2. isEqual performs deep equality comparison between nested plain objects with identical keys and values
{
  const obj1 = {
    id: 1,
    meta: {
      tags: ['a', 'b'],
      config: { enabled: true, timeout: 3000 }
    }
  };
  const obj2 = {
    id: 1,
    meta: {
      tags: ['a', 'b'],
      config: { enabled: true, timeout: 3000 }
    }
  };

  assert.equal(isEqual(obj1, obj2), true);
  assert.equal(matchesSubset(obj1, { id: 1, meta: { tags: ['a', 'b'], config: { enabled: true, timeout: 3000 } } }), true);
}

// 3. isEqual performs deep equality comparison between arrays of identical order, length, and elements
{
  const arr1 = [1, [2, { key: 'value' }], 4];
  const arr2 = [1, [2, { key: 'value' }], 4];

  assert.equal(isEqual(arr1, arr2), true);

  const list = [
    { type: 'item', id: 10 },
    { type: 'item', id: 20 },
    { type: 'item', id: 10 }
  ];
  const filtered = filterEqualItems(list, { type: 'item', id: 10 });
  assert.equal(filtered.length, 2);
}

// 4. isEqual returns true for equivalent Date and RegExp instances with identical internal state
{
  const date1 = new Date('2026-01-01T00:00:00.000Z');
  const date2 = new Date('2026-01-01T00:00:00.000Z');
  assert.equal(isEqual(date1, date2), true);

  const regex1 = /^[a-z]+$/gi;
  const regex2 = /^[a-z]+$/gi;
  assert.equal(isEqual(regex1, regex2), true);
}

// 5. isEqual returns true for equivalent Map and Set instances with matching entries and values
{
  const map1 = new Map([['k1', { val: 1 }], ['k2', { val: 2 }]]);
  const map2 = new Map([['k1', { val: 1 }], ['k2', { val: 2 }]]);
  assert.equal(isEqual(map1, map2), true);

  const set1 = new Set(['x', 'y', 'z']);
  const set2 = new Set(['x', 'y', 'z']);
  assert.equal(isEqual(set1, set2), true);
}

// 6. isEqual handles circular references without entering infinite recursion
{
  const circ1 = { name: 'node' };
  circ1.self = circ1;

  const circ2 = { name: 'node' };
  circ2.self = circ2;

  assert.equal(isEqual(circ1, circ2), true);
}

// 7. isEqual returns false for values with different types, differing nested properties, or different array lengths
{
  assert.equal(isEqual(42, '42'), false);
  assert.equal(isEqual(null, undefined), false);
  assert.equal(isEqual({ a: 1, b: 2 }, { a: 1, b: 3 }), false);
  assert.equal(isEqual({ a: 1 }, { a: 1, b: 2 }), false);
  assert.equal(isEqual([1, 2], [1, 2, 3]), false);
  assert.equal(isEqual([1, 2], [2, 1]), false);
  assert.equal(isEqual(new Date('2026-01-01'), new Date('2026-01-02')), false);
  assert.equal(isEqual(/abc/i, /abc/g), false);
}

// 8. isEqual compares functions by reference and treats distinct function instances as not equal
{
  const fn1 = () => 1;
  const fn2 = () => 1;
  assert.equal(isEqual(fn1, fn1), true);
  assert.equal(isEqual(fn1, fn2), false);
}

console.log('Contract assertions passed.');

Seeder de origem

anônimo