CodeSampleX

Exemplo

boolean 3.2.0: boolean

Amostra verificada para npm boolean 3.2.0: boolean. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: boolean parses truthy strings including…

sha256:c4e66cd29d6cbf77e03fb2ecb93d76e15bc16d16c85121ac8e982d28af025331

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 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

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-26

Caso

HOW
Objetivo
verify pkg:npm/boolean@3.2.0
Pacotes
Símbolos
  • boolean
Ambiente
node 22.23.2
Criado
2026-08-26T07:54:04Z

Contrato

  1. boolean parses truthy strings including true, t, yes, y, on, and 1 case-insensitively and trimmed
  2. boolean returns true for numeric 1 and boolean true
  3. boolean returns false for falsy strings, numbers other than 1, null, undefined, objects, and unknown strings
  4. boolean supports boxed String, Number, and Boolean objects
  5. isBooleanable returns true for valid truthy and falsy boolean representations
  6. isBooleanable returns false for unparseable strings, numbers other than 0 and 1, null, undefined, and objects

Arquivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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: verify pkg:npm/boolean@3.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/boolean@3.2.0
Demonstrate these symbols/APIs:
  - boolean

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:ac0b1d0a0008b34012352f3310daf539c1fa6addbf6b2f94cfe823c58af52378","contract":["boolean parses truthy strings including true, t, yes, y, on, and 1 case-insensitively and trimmed","boolean returns true for numeric 1 and boolean true","boolean returns false for falsy strings, numbers other than 1, null, undefined, objects, and unknown strings","boolean supports boxed String, Number, and Boolean objects","isBooleanable returns true for valid truthy and falsy boolean representations","isBooleanable returns false for unparseable strings, numbers other than 0 and 1, null, undefined, and objects"],"goal":"verify pkg:npm/boolean@3.2.0","kind":"HOW","packages":["pkg:npm/boolean@3.2.0"],"schemaVersion":1,"symbols":["boolean"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/boolean@3.2.0"],"schemaVersion":1,"subject":"pkg:npm/boolean@3.2.0","symbols":["boolean"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-boolean",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-boolean",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "boolean": "3.2.0"
      }
    },
    "node_modules/boolean": {
      "version": "3.2.0",
      "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.2.0.tgz",
      "integrity": "sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==",
      "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-boolean",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for boolean@3.2.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "boolean": "3.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/boolean@3.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/boolean@3.2.0"
  ],
  "symbols": [
    "boolean"
  ]
}
src/index.js
const { boolean, isBooleanable } = require('boolean');

/**
 * Converts various values (string, number, boolean, wrappers) to a boolean.
 *
 * @param {*} value - The input value to convert.
 * @returns {boolean} True if the value represents a truthy boolean string/number/boolean, false otherwise.
 */
function toBoolean(value) {
  return boolean(value);
}

/**
 * Checks whether a value can be parsed or interpreted as a valid boolean representation.
 *
 * @param {*} value - The input value to test.
 * @returns {boolean} True if the value represents a known boolean or boolean-like string/number.
 */
function checkBooleanable(value) {
  return isBooleanable(value);
}

module.exports = {
  boolean,
  isBooleanable,
  toBoolean,
  checkBooleanable
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { boolean, isBooleanable, toBoolean, checkBooleanable } = require('../src/index.js');

// 1. Export verification
assert.equal(typeof boolean, 'function', 'boolean should be exported as a function');
assert.equal(typeof isBooleanable, 'function', 'isBooleanable should be exported as a function');
assert.equal(typeof toBoolean, 'function', 'toBoolean helper should be a function');
assert.equal(typeof checkBooleanable, 'function', 'checkBooleanable helper should be a function');

// 2. Truthy string parsing with case-insensitivity and trimming
const truthyStrings = ['true', 'TRUE', 'True', 't', 'T', 'yes', 'YES', 'y', 'Y', 'on', 'ON', '1', '  true  ', '\tyes\n'];
for (const val of truthyStrings) {
  assert.equal(boolean(val), true, `boolean(${JSON.stringify(val)}) should be true`);
  assert.equal(toBoolean(val), true, `toBoolean(${JSON.stringify(val)}) should be true`);
}

// 3. Numeric 1 and boolean true
assert.equal(boolean(1), true, 'boolean(1) should be true');
assert.equal(boolean(true), true, 'boolean(true) should be true');
assert.equal(toBoolean(1), true, 'toBoolean(1) should be true');
assert.equal(toBoolean(true), true, 'toBoolean(true) should be true');

// 4. Falsy strings, non-1 numbers, null, undefined, objects, and arbitrary strings
const falsyValues = ['false', 'FALSE', 'f', 'F', 'no', 'NO', 'n', 'N', 'off', 'OFF', '0', '  false  ', 0, -1, 2, 42, NaN, Infinity, null, undefined, {}, [], () => {}, 'unknown', 'invalid'];
for (const val of falsyValues) {
  assert.equal(boolean(val), false, `boolean(${String(val)}) should be false`);
  assert.equal(toBoolean(val), false, `toBoolean(${String(val)}) should be false`);
}

// 5. Boxed String, Number, and Boolean objects
assert.equal(boolean(new String('true')), true, 'boolean(new String("true")) should be true');
assert.equal(boolean(new String('YES')), true, 'boolean(new String("YES")) should be true');
assert.equal(boolean(new String('false')), false, 'boolean(new String("false")) should be false');
assert.equal(boolean(new Number(1)), true, 'boolean(new Number(1)) should be true');
assert.equal(boolean(new Number(0)), false, 'boolean(new Number(0)) should be false');
assert.equal(boolean(new Boolean(true)), true, 'boolean(new Boolean(true)) should be true');
assert.equal(boolean(new Boolean(false)), false, 'boolean(new Boolean(false)) should be false');

// 6. isBooleanable returns true for recognized boolean representations
const booleanableValues = [
  'true', 'TRUE', 't', 'T', 'yes', 'YES', 'y', 'Y', 'on', 'ON', '1',
  'false', 'FALSE', 'f', 'F', 'no', 'NO', 'n', 'N', 'off', 'OFF', '0',
  '  true  ', '  false  ',
  1, 0, true, false,
  new String('true'), new String('false'), new Number(1), new Number(0), new Boolean(true), new Boolean(false)
];
for (const val of booleanableValues) {
  assert.equal(isBooleanable(val), true, `isBooleanable(${String(val)}) should be true`);
  assert.equal(checkBooleanable(val), true, `checkBooleanable(${String(val)}) should be true`);
}

// 7. isBooleanable returns false for unparseable or arbitrary values
const nonBooleanableValues = ['foo', 'bar', '2', '-1', 2, -1, 100, NaN, Infinity, null, undefined, {}, [], () => {}];
for (const val of nonBooleanableValues) {
  assert.equal(isBooleanable(val), false, `isBooleanable(${String(val)}) should be false`);
  assert.equal(checkBooleanable(val), false, `checkBooleanable(${String(val)}) should be false`);
}

console.log('All boolean@3.2.0 contract tests passed successfully.');

Seeder de origem

anônimo