CodeSampleX

示例

prelude-ls 1.2.1

已验证示例 — npm prelude-ls 1.2.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: map transforms elements in an array by applying a unary mapping function

sha256:2de7346d30486435e7df2b48b160855ebc5da7bebfe0dd009e3b607fe86f2e89

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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-27

案例

HOW
目标
verify pkg:npm/prelude-ls@1.2.1
包
环境
node 22.23.2
创建时间
2026-08-27T15:45:50Z

契约

  1. map transforms elements in an array by applying a unary mapping function
  2. filter keeps elements satisfying a predicate and reject excludes elements satisfying a predicate
  3. partition splits an array into a pair of arrays of elements that pass and fail a predicate
  4. foldl reduces elements from the left with an accumulator and initial value, while foldr reduces from the right
  5. sum computes the arithmetic sum of numbers and product computes their product
  6. take extracts the first n elements and drop removes the first n elements from an array
  7. splitAt partitions an array at a specified index into a tuple of two sub-arrays
  8. takeWhile takes elements while a predicate holds true and dropWhile drops elements while a predicate holds true
  9. head returns the first element, tail returns all except the first, last returns the final element, and initial returns all except the last
  10. unique removes duplicate elements, intersection finds common elements, difference removes elements present in another list, and union merges lists without duplicates
  11. zip pairs corresponding elements from two lists and zipWith combines them using a binary function
  12. groupBy groups elements into an object keyed by the result of a grouping function and sortBy sorts elements by an extracted key
  13. pairsToObj constructs an object from key-value pairs and objToPairs extracts key-value pairs from an object
  14. capitalize, camelize, and dasherize format string casing, and words, unwords, lines, unlines split and join string sequences
  15. curry converts a multi-argument function into a curried function and flip reverses the order of the first two arguments
  16. isType validates the constructor type name of JavaScript values including String, Number, and Array

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

下载源代码构件 (tar.gz)

源代码

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/prelude-ls@1.2.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/prelude-ls@1.2.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:29b6756f064b622358cea71ee834b7506ccd726059b7106f882819d2ab198b09","constraints":{"executionContext":"node"},"contract":["map transforms elements in an array by applying a unary mapping function","filter keeps elements satisfying a predicate and reject excludes elements satisfying a predicate","partition splits an array into a pair of arrays of elements that pass and fail a predicate","foldl reduces elements from the left with an accumulator and initial value, while foldr reduces from the right","sum computes the arithmetic sum of numbers and product computes their product","take extracts the first n elements and drop removes the first n elements from an array","splitAt partitions an array at a specified index into a tuple of two sub-arrays","takeWhile takes elements while a predicate holds true and dropWhile drops elements while a predicate holds true","head returns the first element, tail returns all except the first, last returns the final element, and initial returns all except the last","unique removes duplicate elements, intersection finds common elements, difference removes elements present in another list, and union merges lists without duplicates","zip pairs corresponding elements from two lists and zipWith combines them using a binary function","groupBy groups elements into an object keyed by the result of a grouping function and sortBy sorts elements by an extracted key","pairsToObj constructs an object from key-value pairs and objToPairs extracts key-value pairs from an object","capitalize, camelize, and dasherize format string casing, and words, unwords, lines, unlines split and join string sequences","curry converts a multi-argument function into a curried function and flip reverses the order of the first two arguments","isType validates the constructor type name of JavaScript values including String, Number, and Array"],"goal":"verify pkg:npm/prelude-ls@1.2.1","kind":"HOW","packages":["pkg:npm/prelude-ls@1.2.1"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/prelude-ls@1.2.1"],"schemaVersion":1,"subject":"pkg:npm/prelude-ls@1.2.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-prelude-ls",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-prelude-ls",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "prelude-ls": "1.2.1"
      }
    },
    "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"
      }
    }
  }
}
package.json
{
  "name": "sample-prelude-ls",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for prelude-ls",
  "license": "MIT-0",
  "dependencies": {
    "prelude-ls": "1.2.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/prelude-ls@1.2.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/prelude-ls@1.2.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert');
const prelude = require('prelude-ls');

const {
  map,
  filter,
  reject,
  partition,
  foldl,
  foldr,
  sum,
  product,
  take,
  drop,
  splitAt,
  takeWhile,
  dropWhile,
  head,
  tail,
  last,
  initial,
  reverse,
  unique,
  intersection,
  difference,
  union,
  zip,
  zipWith,
  groupBy,
  sortBy,
  pairsToObj,
  objToPairs,
  keys,
  values,
  capitalize,
  camelize,
  dasherize,
  words,
  unwords,
  lines,
  unlines,
  curry,
  flip,
  isType,
} = prelude;

// 1. map transforms elements in an array by applying a unary mapping function
const mapped = map((x) => x * 2, [1, 2, 3]);
assert.deepStrictEqual(mapped, [2, 4, 6]);

// 2. filter keeps elements satisfying a predicate and reject excludes elements satisfying a predicate
const filtered = filter((x) => x % 2 === 0, [1, 2, 3, 4, 5]);
assert.deepStrictEqual(filtered, [2, 4]);
const rejected = reject((x) => x % 2 === 0, [1, 2, 3, 4, 5]);
assert.deepStrictEqual(rejected, [1, 3, 5]);

// 3. partition splits an array into a pair of arrays of elements that pass and fail a predicate
const partitioned = partition((x) => x > 2, [1, 2, 3, 4, 5]);
assert.deepStrictEqual(partitioned, [
  [3, 4, 5],
  [1, 2],
]);

// 4. foldl reduces elements from the left with an accumulator and initial value, while foldr reduces from the right
const foldedLeft = foldl((acc, x) => acc - x, 10, [1, 2, 3]);
assert.strictEqual(foldedLeft, 4);
const foldedRight = foldr((x, acc) => x - acc, 0, [1, 2, 3, 4]);
assert.strictEqual(foldedRight, -2);

// 5. sum computes the arithmetic sum of numbers and product computes their product
assert.strictEqual(sum([10, 20, 30, 5]), 65);
assert.strictEqual(sum([]), 0);
assert.strictEqual(product([2, 3, 4, 5]), 120);
assert.strictEqual(product([]), 1);

// 6. take extracts the first n elements and drop removes the first n elements from an array
assert.deepStrictEqual(take(2, [10, 20, 30, 40]), [10, 20]);
assert.deepStrictEqual(take(0, [10, 20, 30]), []);
assert.deepStrictEqual(drop(2, [10, 20, 30, 40]), [30, 40]);
assert.deepStrictEqual(drop(5, [10, 20]), []);

// 7. splitAt partitions an array at a specified index into a tuple of two sub-arrays
assert.deepStrictEqual(splitAt(2, ['a', 'b', 'c', 'd']), [
  ['a', 'b'],
  ['c', 'd'],
]);
assert.deepStrictEqual(splitAt(0, ['a', 'b']), [[], ['a', 'b']]);

// 8. takeWhile takes elements while a predicate holds true and dropWhile drops elements while a predicate holds true
assert.deepStrictEqual(takeWhile((x) => x < 4, [1, 2, 3, 5, 2, 1]), [1, 2, 3]);
assert.deepStrictEqual(dropWhile((x) => x < 4, [1, 2, 3, 5, 2, 1]), [5, 2, 1]);

// 9. head returns the first element, tail returns all except the first, last returns the final element, and initial returns all except the last
assert.strictEqual(head([10, 20, 30]), 10);
assert.deepStrictEqual(tail([10, 20, 30]), [20, 30]);
assert.strictEqual(last([10, 20, 30]), 30);
assert.deepStrictEqual(initial([10, 20, 30]), [10, 20]);
assert.deepStrictEqual(reverse([1, 2, 3]), [3, 2, 1]);

// 10. unique removes duplicate elements, intersection finds common elements, difference removes elements present in another list, and union merges lists without duplicates
assert.deepStrictEqual(unique([1, 2, 2, 3, 1, 4]), [1, 2, 3, 4]);
assert.deepStrictEqual(intersection([1, 2, 3], [2, 3, 4]), [2, 3]);
assert.deepStrictEqual(difference([1, 2, 3, 4], [2, 4]), [1, 3]);
assert.deepStrictEqual(union([1, 2], [2, 3, 4]), [1, 2, 3, 4]);

// 11. zip pairs corresponding elements from two lists and zipWith combines them using a binary function
assert.deepStrictEqual(zip(['x', 'y', 'z'], [1, 2, 3]), [
  ['x', 1],
  ['y', 2],
  ['z', 3],
]);
assert.deepStrictEqual(zipWith((a, b) => `${a}:${b}`, ['a', 'b'], [10, 20]), [
  'a:10',
  'b:20',
]);

// 12. groupBy groups elements into an object keyed by the result of a grouping function and sortBy sorts elements by an extracted key
const grouped = groupBy((s) => s.length, ['a', 'bb', 'c', 'ddd', 'ee']);
assert.deepStrictEqual(grouped, {
  '1': ['a', 'c'],
  '2': ['bb', 'ee'],
  '3': ['ddd'],
});
const sorted = sortBy((item) => item.score, [
  { id: 1, score: 30 },
  { id: 2, score: 10 },
  { id: 3, score: 20 },
]);
assert.deepStrictEqual(sorted, [
  { id: 2, score: 10 },
  { id: 3, score: 20 },
  { id: 1, score: 30 },
]);

// 13. pairsToObj constructs an object from key-value pairs and objToPairs extracts key-value pairs from an object
assert.deepStrictEqual(
  pairsToObj([
    ['foo', 1],
    ['bar', 2],
  ]),
  { foo: 1, bar: 2 }
);
assert.deepStrictEqual(objToPairs({ alpha: 10, beta: 20 }), [
  ['alpha', 10],
  ['beta', 20],
]);
assert.deepStrictEqual(keys({ a: 1, b: 2 }), ['a', 'b']);
assert.deepStrictEqual(values({ a: 1, b: 2 }), [1, 2]);

// 14. capitalize, camelize, and dasherize format string casing, and words, unwords, lines, unlines split and join string sequences
assert.strictEqual(capitalize('prelude'), 'Prelude');
assert.strictEqual(camelize('functional-programming-helper'), 'functionalProgrammingHelper');
assert.strictEqual(dasherize('functionalProgrammingHelper'), 'functional-programming-helper');
assert.deepStrictEqual(words('foo bar baz'), ['foo', 'bar', 'baz']);
assert.strictEqual(unwords(['foo', 'bar', 'baz']), 'foo bar baz');
assert.deepStrictEqual(lines('line1\nline2\nline3'), ['line1', 'line2', 'line3']);
assert.strictEqual(unlines(['line1', 'line2']), 'line1\nline2');

// 15. curry converts a multi-argument function into a curried function and flip reverses the order of the first two arguments
const add3 = (a, b, c) => a + b + c;
const curriedAdd3 = curry(add3);
assert.strictEqual(curriedAdd3(1)(2)(3), 6);
assert.strictEqual(curriedAdd3(1, 2)(3), 6);
assert.strictEqual(curriedAdd3(1)(2, 3), 6);

const subtract = (a, b) => a - b;
const flippedSubtract = flip(subtract);
assert.strictEqual(flippedSubtract(2, 10), 8);

// 16. isType validates the constructor type name of JavaScript values including String, Number, and Array
assert.strictEqual(isType('String', 'hello'), true);
assert.strictEqual(isType('String', 123), false);
assert.strictEqual(isType('Number', 42), true);
assert.strictEqual(isType('Array', [1, 2, 3]), true);
assert.strictEqual(isType('Object', { a: 1 }), true);
assert.strictEqual(isType('Function', () => {}), true);

console.log('Contract passed');

原始种子者

匿名