Exemplo
levn 0.4.1
Amostra verificada para npm levn 0.4.1. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: levn.parse parses primitive types including Number…
sha256:179b8a89683298717480c4e87f9581d7901538ea755fff52ec46c1a33e268533
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
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
- verify pkg:npm/levn@0.4.1
- Pacotes
- Ambiente
- node 22.23.2
- Criado
- 2026-08-28T03:11:25Z
Contrato
- levn.parse parses primitive types including Number, String, Boolean, Undefined, Null, and NaN from string notation
- levn.parse parses composite types including arrays, tuples, and objects with nested type specifications
- levn.parse parses special types including Date literals and RegExp patterns with optional delimiters and flags
- levn.parse parses union types by attempting candidate type conversions in left-to-right precedence order
- levn.parse supports explicit mode using wildcard type or explicit option to require unambiguous literal syntax
- levn.parse supports custom type definitions with custom typeOf, validate, and cast functions
- levn.parsedTypeParse parses input string values using a pre-parsed type structure from type-check
- levn.VERSION exposes the package version string
Arquivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Código-fonte
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/levn@0.4.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/levn@0.4.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.
{"case":{"caseId":"case:sha256:5aebe899bdf6ed858032eefdfda0cf57e797321e6017281dad6b06da768d63db","contract":["levn.parse parses primitive types including Number, String, Boolean, Undefined, Null, and NaN from string notation","levn.parse parses composite types including arrays, tuples, and objects with nested type specifications","levn.parse parses special types including Date literals and RegExp patterns with optional delimiters and flags","levn.parse parses union types by attempting candidate type conversions in left-to-right precedence order","levn.parse supports explicit mode using wildcard type or explicit option to require unambiguous literal syntax","levn.parse supports custom type definitions with custom typeOf, validate, and cast functions","levn.parsedTypeParse parses input string values using a pre-parsed type structure from type-check","levn.VERSION exposes the package version string"],"goal":"verify pkg:npm/levn@0.4.1","kind":"HOW","packages":["pkg:npm/levn@0.4.1"],"schemaVersion":1},"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/levn@0.4.1"],"schemaVersion":1,"subject":"pkg:npm/levn@0.4.1","verifierAdapter":"node-typescript@1"}
{
"name": "sample-levn",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-levn",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"levn": "0.4.1"
}
},
"node_modules/levn": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
"integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==",
"license": "MIT",
"dependencies": {
"prelude-ls": "^1.2.1",
"type-check": "~0.4.0"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/prelude-ls": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
"license": "MIT",
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/type-check": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
"integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==",
"license": "MIT",
"dependencies": {
"prelude-ls": "^1.2.1"
},
"engines": {
"node": ">= 0.8.0"
}
}
}
}
{
"name": "sample-levn",
"version": "1.0.0",
"description": "Clean-room verification for levn",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"levn": "0.4.1"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/levn@0.4.1",
"kind": "HOW",
"packages": [
"pkg:npm/levn@0.4.1"
]
}
const levn = require('levn');
/**
* Parses a string input into a JavaScript value based on the specified type.
* @param {string} type - Type specification string.
* @param {string} input - Levn formatted string input.
* @param {object} [options] - Optional parsing options.
* @returns {*} Parsed JavaScript value.
*/
function parseValue(type, input, options) {
return levn.parse(type, input, options);
}
/**
* Parses a string input using a pre-parsed type structure.
* @param {object} parsedType - Parsed type structure.
* @param {string} input - Levn formatted string input.
* @param {object} [options] - Optional parsing options.
* @returns {*} Parsed JavaScript value.
*/
function parseWithParsedType(parsedType, input, options) {
return levn.parsedTypeParse(parsedType, input, options);
}
module.exports = {
parseValue,
parseWithParsedType,
levn,
};
import assert from 'node:assert';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { parseValue, parseWithParsedType, levn } = require('../src/index.js');
const typeCheck = require('type-check');
async function runContract() {
// 1. levn.parse parses primitive types including Number, String, Boolean, Undefined, Null, and NaN from string notation
assert.strictEqual(parseValue('Number', '42'), 42);
assert.strictEqual(parseValue('Number', '3.14'), 3.14);
assert.strictEqual(parseValue('String', 'hello world'), 'hello world');
assert.strictEqual(parseValue('Boolean', 'true'), true);
assert.strictEqual(parseValue('Boolean', 'false'), false);
assert.strictEqual(parseValue('Undefined', 'undefined'), undefined);
assert.strictEqual(parseValue('Null', 'null'), null);
assert.strictEqual(Number.isNaN(parseValue('NaN', 'NaN')), true);
// 2. levn.parse parses composite types including arrays, tuples, and objects with nested type specifications
assert.deepStrictEqual(parseValue('[Number]', '1, 2, 3'), [1, 2, 3]);
assert.deepStrictEqual(parseValue('[String]', 'foo, bar, baz'), ['foo', 'bar', 'baz']);
assert.deepStrictEqual(parseValue('(String, Number, Boolean)', 'alice, 30, true'), ['alice', 30, true]);
assert.deepStrictEqual(
parseValue('{name: String, count: Number}', 'name: item, count: 5'),
{ name: 'item', count: 5 }
);
// 3. levn.parse parses special types including Date literals and RegExp patterns with optional delimiters and flags
const parsedDate = parseValue('Date', '2025-01-15');
assert.ok(parsedDate instanceof Date);
assert.strictEqual(parsedDate.getUTCFullYear(), 2025);
const parsedRegExp = parseValue('RegExp', '/[a-z]+/i');
assert.ok(parsedRegExp instanceof RegExp);
assert.strictEqual(parsedRegExp.test('ABC'), true);
const unquotedRegExp = parseValue('RegExp', 'hello');
assert.ok(unquotedRegExp instanceof RegExp);
assert.strictEqual(unquotedRegExp.test('hello'), true);
// 4. levn.parse parses union types by attempting candidate type conversions in left-to-right precedence order
assert.strictEqual(parseValue('Number | String', '123'), 123);
assert.strictEqual(parseValue('Number | String', 'sample-text'), 'sample-text');
assert.strictEqual(parseValue('Boolean | Number', 'true'), true);
assert.strictEqual(parseValue('Boolean | Number', '99'), 99);
// 5. levn.parse supports explicit mode using wildcard type or explicit option to require unambiguous literal syntax
assert.deepStrictEqual(parseValue('*', '[1, "two", true]'), [1, 'two', true]);
assert.strictEqual(parseValue('String', 'value', { explicit: true }), 'value');
assert.throws(() => {
parseValue('RegExp', 'not-a-regex-literal', { explicit: true });
}, /does not type check/);
// 6. levn.parse supports custom type definitions with custom typeOf, validate, and cast functions
const customOptions = {
customTypes: {
EvenNumber: {
typeOf: 'Number',
validate: function(x) {
return typeof x === 'number' && x % 2 === 0;
},
cast: function(val) {
const num = parseInt(val, 10);
return isNaN(num) ? { type: 'Nothing' } : { type: 'Just', value: num };
}
}
}
};
assert.strictEqual(parseValue('EvenNumber', '8', customOptions), 8);
assert.throws(() => {
parseValue('EvenNumber', '9', customOptions);
}, /does not type check/);
// 7. levn.parsedTypeParse parses input string values using a pre-parsed type structure from type-check
const parsedType = typeCheck.parseType('[Number]');
assert.deepStrictEqual(parseWithParsedType(parsedType, '10, 20, 30'), [10, 20, 30]);
// 8. levn.VERSION exposes the package version string
assert.strictEqual(typeof levn.VERSION, 'string');
assert.strictEqual(levn.VERSION, '0.4.1');
console.log('Contract tests passed successfully.');
}
runContract().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
Seeder de origem
anônimo