CodeSampleX

샘플

emoji-regex 9.2.2

검증된 샘플 — npm emoji-regex 9.2.2. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: emojiRegex exports a factory function returning a regular…

sha256:6b22911f11525e526ae40eb644c6939a897de04842e56083889de1b8b81efdf2

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 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-23

케이스

HOW
목표
verify pkg:npm/emoji-regex@9.2.2
패키지
생성일
2026-08-23T13:41:20Z

컨트랙트

  1. emojiRegex exports a factory function returning a regular expression
  2. hasEmoji returns true when string contains standard emojis and false for plain text
  3. extractEmojis extracts all emoji occurrences from text
  4. extractEmojis correctly extracts complex emoji sequences including modifiers and zero-width joiners
  5. replaceEmojis replaces emojis in text with a replacement string or custom replacer function
  6. countEmojis returns the number of emojis found in text
  7. RGI_Emoji subpath exports a factory function returning regex for RGI emoji sequences
  8. text subpath exports a factory function returning regex for text presentation emojis

파일

  • 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/emoji-regex@9.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/emoji-regex@9.2.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:2d3a60100aec5f5437ba91b77666fdcfa607a3d10dc5d833574db67d527a7ffe","contract":["emojiRegex exports a factory function returning a regular expression","hasEmoji returns true when string contains standard emojis and false for plain text","extractEmojis extracts all emoji occurrences from text","extractEmojis correctly extracts complex emoji sequences including modifiers and zero-width joiners","replaceEmojis replaces emojis in text with a replacement string or custom replacer function","countEmojis returns the number of emojis found in text","RGI_Emoji subpath exports a factory function returning regex for RGI emoji sequences","text subpath exports a factory function returning regex for text presentation emojis"],"goal":"verify pkg:npm/emoji-regex@9.2.2","kind":"HOW","packages":["pkg:npm/emoji-regex@9.2.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/emoji-regex@9.2.2"],"schemaVersion":1,"subject":"pkg:npm/emoji-regex@9.2.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-emoji-regex",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-emoji-regex",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "emoji-regex": "9.2.2"
      }
    },
    "node_modules/emoji-regex": {
      "version": "9.2.2",
      "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
      "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-emoji-regex",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for emoji-regex@9.2.2",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "emoji-regex": "9.2.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/emoji-regex@9.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/emoji-regex@9.2.2"
  ]
}
src/index.js
const emojiRegex = require('emoji-regex');
const rgiEmojiRegex = require('emoji-regex/RGI_Emoji.js');
const textEmojiRegex = require('emoji-regex/text.js');

/**
 * Creates a regular expression that matches all standard emoji symbols.
 *
 * @returns {RegExp} A new regular expression instance matching emojis.
 */
function createEmojiRegex() {
  return emojiRegex();
}

/**
 * Creates a regular expression that matches RGI (Recommended for General Interchange) emoji sequences.
 *
 * @returns {RegExp} A regular expression instance matching RGI emojis.
 */
function createRgiEmojiRegex() {
  return rgiEmojiRegex();
}

/**
 * Creates a regular expression that matches emojis in text presentation.
 *
 * @returns {RegExp} A regular expression instance matching text-presentation emojis.
 */
function createTextEmojiRegex() {
  return textEmojiRegex();
}

/**
 * Determines whether a string contains any emoji character.
 *
 * @param {string} text - The input string to check.
 * @returns {boolean} True if the string contains at least one emoji, otherwise false.
 */
function hasEmoji(text) {
  if (typeof text !== 'string') return false;
  return createEmojiRegex().test(text);
}

/**
 * Extracts all emoji characters and sequences found in the string.
 *
 * @param {string} text - The input string to extract emojis from.
 * @returns {string[]} An array of matched emoji strings.
 */
function extractEmojis(text) {
  if (typeof text !== 'string') return [];
  const regex = createEmojiRegex();
  const matches = [];
  for (const match of text.matchAll(regex)) {
    matches.push(match[0]);
  }
  return matches;
}

/**
 * Replaces all emoji occurrences in a string with a replacement string or callback.
 *
 * @param {string} text - The input string.
 * @param {string|Function} replacement - The replacement string or function.
 * @returns {string} The modified string with emojis replaced.
 */
function replaceEmojis(text, replacement = '') {
  if (typeof text !== 'string') return '';
  const regex = createEmojiRegex();
  return text.replace(regex, replacement);
}

/**
 * Counts the total number of emoji occurrences in the given text.
 *
 * @param {string} text - The input string.
 * @returns {number} Total count of emojis found.
 */
function countEmojis(text) {
  return extractEmojis(text).length;
}

module.exports = {
  emojiRegex,
  rgiEmojiRegex,
  textEmojiRegex,
  createEmojiRegex,
  createRgiEmojiRegex,
  createTextEmojiRegex,
  hasEmoji,
  extractEmojis,
  replaceEmojis,
  countEmojis
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  emojiRegex,
  rgiEmojiRegex,
  textEmojiRegex,
  createEmojiRegex,
  createRgiEmojiRegex,
  createTextEmojiRegex,
  hasEmoji,
  extractEmojis,
  replaceEmojis,
  countEmojis
} = require('../src/index.js');

async function testAll() {
  // 1. emojiRegex exports a factory function returning a regular expression
  assert.equal(typeof emojiRegex, 'function', 'emojiRegex default export must be a function');
  const standardRegex = createEmojiRegex();
  assert.ok(standardRegex instanceof RegExp, 'createEmojiRegex must return a RegExp instance');
  assert.ok(standardRegex.global, 'emoji regex must have the global flag enabled');

  // 2. hasEmoji returns true when string contains standard emojis and false for plain text
  assert.equal(hasEmoji('Hello 😊 World'), true, 'should detect standard emoji in text');
  assert.equal(hasEmoji('Hello World'), false, 'should return false for plain ascii text');
  assert.equal(hasEmoji('Numbers 12345 and punctuation !@#$'), false, 'should return false for symbols and numbers');
  assert.equal(hasEmoji(''), false, 'should return false for empty string');
  assert.equal(hasEmoji(null), false, 'should handle non-string values gracefully');

  // 3. extractEmojis extracts all emoji occurrences from text
  const simpleText = '🚀 Launching rocket to 🌙 moon!';
  const simpleExtracted = extractEmojis(simpleText);
  assert.deepEqual(simpleExtracted, ['🚀', '🌙'], 'should extract individual emojis in order');

  // 4. extractEmojis correctly extracts complex emoji sequences including modifiers and zero-width joiners
  const complexText = 'Doctor: 👩‍⚕️, rainbow flag: 🏳️‍🌈, dark skin tone: 👨🏿';
  const complexExtracted = extractEmojis(complexText);
  assert.deepEqual(
    complexExtracted,
    ['👩‍⚕️', '🏳️‍🌈', '👨🏿'],
    'should extract complex emoji sequences with ZWJ and modifier characters intact'
  );

  // 5. replaceEmojis replaces emojis in text with a replacement string or custom replacer function
  const replacedWithTag = replaceEmojis('Hello 👋 World 🌍!', '[EMOJI]');
  assert.equal(replacedWithTag, 'Hello [EMOJI] World [EMOJI]!', 'should replace emojis with placeholder string');

  const stripped = replaceEmojis('Hello 🚀 World 🌟!');
  assert.equal(stripped, 'Hello  World !', 'should remove emojis when replacement defaults to empty string');

  const customReplaced = replaceEmojis('Rating: ⭐⭐⭐', (match) => `(${match})`);
  assert.equal(customReplaced, 'Rating: (⭐)(⭐)(⭐)', 'should support replacer function');

  // 6. countEmojis returns the number of emojis found in text
  assert.equal(countEmojis('🎉 Congratulations 🥳 on your achievement! 👏'), 3, 'should count 3 emojis correctly');
  assert.equal(countEmojis('No emojis here.'), 0, 'should return 0 when no emojis are present');
  assert.equal(countEmojis('👩‍👩‍👧‍👦'), 1, 'should count multi-codepoint family emoji as 1 emoji');

  // 7. RGI_Emoji subpath exports a factory function returning regex for RGI emoji sequences
  assert.equal(typeof rgiEmojiRegex, 'function', 'RGI_Emoji export must be a function');
  const rgiRegex = createRgiEmojiRegex();
  assert.ok(rgiRegex instanceof RegExp, 'createRgiEmojiRegex must return a RegExp instance');
  assert.ok(rgiRegex.test('🧑‍🚀'), 'RGI regex should match valid astronaut emoji');

  // 8. text subpath exports a factory function returning regex for text presentation emojis
  assert.equal(typeof textEmojiRegex, 'function', 'text export must be a function');
  const textRegex = createTextEmojiRegex();
  assert.ok(textRegex instanceof RegExp, 'createTextEmojiRegex must return a RegExp instance');

  console.log('All emoji-regex contract assertions passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

오리진 시더

익명