CodeSampleX

示例

linkify-it 5.0.2

已验证示例 — npm linkify-it 5.0.2. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: LinkifyIt exports constructor function callable with or without new

sha256:079e9c4f53110b565552fc6676347d161a16bfdd2804a38d9afc3843bc727063

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-15

案例

HOW
目标
verify pkg:npm/linkify-it@5.0.2
包
环境
node 22.23.2
创建时间
2026-09-15T02:58:12Z

契约

  1. LinkifyIt exports constructor function callable with or without new
  2. LinkifyIt.prototype.test validates URL presence in text and rejects non-URLs
  3. LinkifyIt.prototype.pretest quickly filters candidate text for possible links
  4. LinkifyIt.prototype.testSchemaAt validates schema prefix at specific string index
  5. LinkifyIt.prototype.match finds all links with offsets and normalized URLs
  6. LinkifyIt.prototype.matchAtStart detects link only when positioned at string start
  7. LinkifyIt.prototype.add registers custom protocol schema definitions with custom validation rules
  8. LinkifyIt.prototype.set toggles parser options including fuzzyEmail and fuzzyLink
  9. LinkifyIt.prototype.tlds registers additional top-level domains for recognition

文件

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

下载源代码构件 (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/linkify-it@5.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/linkify-it@5.0.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:fadc8963990c93409c05e098994a34e2362c0164cc55759a91cdd8dd1056bcc2","contract":["LinkifyIt exports constructor function callable with or without new","LinkifyIt.prototype.test validates URL presence in text and rejects non-URLs","LinkifyIt.prototype.pretest quickly filters candidate text for possible links","LinkifyIt.prototype.testSchemaAt validates schema prefix at specific string index","LinkifyIt.prototype.match finds all links with offsets and normalized URLs","LinkifyIt.prototype.matchAtStart detects link only when positioned at string start","LinkifyIt.prototype.add registers custom protocol schema definitions with custom validation rules","LinkifyIt.prototype.set toggles parser options including fuzzyEmail and fuzzyLink","LinkifyIt.prototype.tlds registers additional top-level domains for recognition"],"goal":"verify pkg:npm/linkify-it@5.0.2","kind":"HOW","packages":["pkg:npm/linkify-it@5.0.2"],"schemaVersion":1,"symbols":["LinkifyIt","LinkifyIt.prototype.test","LinkifyIt.prototype.pretest","LinkifyIt.prototype.testSchemaAt","LinkifyIt.prototype.match","LinkifyIt.prototype.matchAtStart","LinkifyIt.prototype.add","LinkifyIt.prototype.set","LinkifyIt.prototype.tlds"]},"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/linkify-it@5.0.2"],"schemaVersion":1,"subject":"pkg:npm/linkify-it@5.0.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-linkify-it",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-linkify-it",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "linkify-it": "5.0.2"
      }
    },
    "node_modules/linkify-it": {
      "version": "5.0.2",
      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.2.tgz",
      "integrity": "sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/puzrin"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/markdown-it"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "uc.micro": "^2.0.0"
      }
    },
    "node_modules/uc.micro": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
      "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-linkify-it",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/linkify-it@5.0.2",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "linkify-it": "5.0.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/linkify-it@5.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/linkify-it@5.0.2"
  ]
}
src/index.js
'use strict';

const LinkifyIt = require('linkify-it');

/**
 * Creates and returns a configured LinkifyIt instance.
 *
 * @param {object} [schemas] - Optional custom schema definitions.
 * @param {object} [options] - Optional configuration options.
 * @returns {LinkifyIt} A new LinkifyIt instance.
 */
function createLinkifier(schemas, options) {
  return new LinkifyIt(schemas, options);
}

/**
 * Finds all links in the given text.
 *
 * @param {string} text - The text to scan for links.
 * @param {object} [options] - Optional configuration overrides.
 * @returns {Array<object>|null} Array of Match objects or null if none found.
 */
function extractLinks(text, options) {
  const linkifier = new LinkifyIt(null, options);
  return linkifier.match(text);
}

module.exports = {
  LinkifyIt,
  createLinkifier,
  extractLinks
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { LinkifyIt, createLinkifier, extractLinks } = require('../src/index.js');
const rawLinkifyIt = require('linkify-it');

// 1. Module export verification and constructor invocation
assert.strictEqual(typeof LinkifyIt, 'function', 'LinkifyIt must be a constructor function');
assert.strictEqual(LinkifyIt, rawLinkifyIt, 'Exported LinkifyIt must match package export');
assert.strictEqual(typeof createLinkifier, 'function', 'createLinkifier helper must be a function');
assert.strictEqual(typeof extractLinks, 'function', 'extractLinks helper must be a function');

const instanceWithNew = new LinkifyIt();
assert.ok(instanceWithNew instanceof LinkifyIt, 'new LinkifyIt() should create an instance');
const instanceWithoutNew = LinkifyIt();
assert.ok(instanceWithoutNew instanceof LinkifyIt, 'LinkifyIt() without new should create an instance');

// 2. LinkifyIt.prototype.test validates URL presence
const linkify = new LinkifyIt();
assert.strictEqual(linkify.test('Check out https://example.com/docs'), true, 'Valid URL should return true');
assert.strictEqual(linkify.test('No link here at all'), false, 'Non-URL text should return false');
assert.strictEqual(linkify.test(''), false, 'Empty string should return false');

// 3. LinkifyIt.prototype.pretest quickly filters candidate text
assert.strictEqual(linkify.pretest('Check out https://example.com'), true, 'Pretest on URL text should return true');
assert.strictEqual(linkify.pretest('just plain text'), false, 'Pretest on plain text should return false');

// 4. LinkifyIt.prototype.testSchemaAt validates schema prefix at specific string index
const testText = 'prefix http://example.com suffix';
const pos = testText.indexOf('http://') + 'http:'.length;
assert.strictEqual(linkify.testSchemaAt(testText, 'http:', pos), 13, 'testSchemaAt should return length of matched tail');
assert.strictEqual(linkify.testSchemaAt(testText, 'http:', 0), 0, 'testSchemaAt at invalid position should return 0');

// 5. LinkifyIt.prototype.match finds all links with offsets and normalized URLs
const sampleText = 'First link https://example.com/a and second http://example.com/b done';
const matches = linkify.match(sampleText);
assert.ok(Array.isArray(matches), 'match should return an array');
assert.strictEqual(matches.length, 2, 'match should find exactly two links');
assert.strictEqual(matches[0].schema, 'https:', 'First match schema must be https:');
assert.strictEqual(matches[0].url, 'https://example.com/a', 'First match url must be normalized');
assert.strictEqual(matches[0].raw, 'https://example.com/a', 'First match raw text must match');
assert.strictEqual(matches[0].index, 11, 'First match index must be correct');
assert.strictEqual(matches[1].schema, 'http:', 'Second match schema must be http:');
assert.strictEqual(matches[1].url, 'http://example.com/b', 'Second match url must be normalized');
assert.strictEqual(linkify.match('no link in this string'), null, 'match should return null when no links exist');

// 6. LinkifyIt.prototype.matchAtStart detects link only at string start
const startMatch = linkify.matchAtStart('https://example.com trailing text');
assert.ok(startMatch !== null, 'matchAtStart should return match for link at start');
assert.strictEqual(startMatch.url, 'https://example.com', 'matchAtStart url should match');
const laterMatch = linkify.matchAtStart('leading text https://example.com');
assert.strictEqual(laterMatch, null, 'matchAtStart should return null when link is not at start');

// 7. LinkifyIt.prototype.add registers custom protocol schema definitions
const customLinkify = new LinkifyIt();
customLinkify.add('git:', 'http:');
assert.strictEqual(customLinkify.test('clone git://example.com/repo.git'), true, 'Custom git schema should be recognized');
const customMatches = customLinkify.match('git://example.com/repo.git');
assert.ok(customMatches !== null && customMatches.length === 1, 'Custom schema should match');
assert.strictEqual(customMatches[0].schema, 'git:', 'Custom schema should match git:');
assert.strictEqual(customMatches[0].url, 'git://example.com/repo.git', 'Custom schema url should match');

// 8. LinkifyIt.prototype.set toggles parser options
const optLinkify = new LinkifyIt();
assert.strictEqual(optLinkify.test('contact test@example.com'), true, 'Fuzzy email enabled by default');
optLinkify.set({ fuzzyEmail: false });
assert.strictEqual(optLinkify.test('contact test@example.com'), false, 'Fuzzy email disabled via set()');
assert.strictEqual(optLinkify.test('visit example.com'), true, 'Fuzzy link enabled by default');
optLinkify.set({ fuzzyLink: false });
assert.strictEqual(optLinkify.test('visit example.com'), false, 'Fuzzy link disabled via set()');

// 9. LinkifyIt.prototype.tlds registers additional top-level domains
const tldLinkify = new LinkifyIt();
assert.strictEqual(tldLinkify.test('visit site.mycustomdomaintest'), false, 'Unknown TLD should not be recognized');
tldLinkify.tlds('mycustomdomaintest');
assert.strictEqual(tldLinkify.test('visit site.mycustomdomaintest'), true, 'Added TLD should be recognized');

// 10. Helper functions verification
const helperInstance = createLinkifier();
assert.ok(helperInstance instanceof LinkifyIt, 'createLinkifier helper should return LinkifyIt instance');
const extracted = extractLinks('Check https://example.com and http://example.org');
assert.ok(Array.isArray(extracted) && extracted.length === 2, 'extractLinks should extract all links');
assert.strictEqual(extracted[0].url, 'https://example.com');
assert.strictEqual(extracted[1].url, 'http://example.org');

console.log('All linkify-it contract assertions passed.');

原始种子者

匿名