샘플
levn 0.4.1
검증된 샘플 — npm levn 0.4.1. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: levn.parse parses primitive types including Number, String, Boolean…
sha256:179b8a89683298717480c4e87f9581d7901538ea755fff52ec46c1a33e268533
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify pkg:npm/levn@0.4.1
- 패키지
- 환경
- node 22.23.2
- 생성일
- 2026-08-28T03:11:25Z
컨트랙트
- 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
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
소스
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);
});
오리진 시더
익명