샘플
@csstools/css-tokenizer 4.0.0: tokenize CSS string into tokens with @csstools/css-tokenizer
검증된 샘플 — npm @csstools/css-tokenizer 4.0.0: tokenize CSS string into tokens with @csstools/css-tokenizer. node 22 · linux alpine/x64 · docker에서 contract를 실행해…
sha256:9ba4cfafda73ef248e0f1d2d38ab25a1799478143493ba46e506bb5d0fdc71ff
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-28 |
케이스
HOW- 목표
- tokenize CSS string into tokens with @csstools/css-tokenizer
- 심벌
-
- tokenize
- 환경
- node 22.23.2
- 생성일
- 2026-08-28T10:10:19Z
컨트랙트
- tokenize is exported as a function from @csstools/css-tokenizer
- tokenize decomposes standard CSS declarations into CSSToken tuples containing type, raw representation, start and end offsets
- tokenize extracts structured token values for identifiers and dimensions with parsed units and numeric types
- tokenize with onParseError callback captures parser errors without throwing an unhandled exception
- stringify reconstructs valid CSS text from an array of tokens produced by tokenize
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
소스
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: tokenize CSS string into tokens with @csstools/css-tokenizer
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40csstools/css-tokenizer@4.0.0
Demonstrate these symbols/APIs:
- tokenize
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:a1757b70ebf19c36608b47fd8a858dc97956e6494bbbc4537bc781292fbcf9f0","contract":["tokenize is exported as a function from @csstools/css-tokenizer","tokenize decomposes standard CSS declarations into CSSToken tuples containing type, raw representation, start and end offsets","tokenize extracts structured token values for identifiers and dimensions with parsed units and numeric types","tokenize with onParseError callback captures parser errors without throwing an unhandled exception","stringify reconstructs valid CSS text from an array of tokens produced by tokenize"],"goal":"tokenize CSS string into tokens with @csstools/css-tokenizer","kind":"HOW","packages":["pkg:npm/%40csstools/css-tokenizer@4.0.0"],"schemaVersion":1,"symbols":["tokenize"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40csstools/css-tokenizer@4.0.0"],"schemaVersion":1,"subject":"pkg:npm/%40csstools/css-tokenizer@4.0.0","symbols":["tokenize"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-csstools-css-tokenizer",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-csstools-css-tokenizer",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@csstools/css-tokenizer": "4.0.0"
}
},
"node_modules/@csstools/css-tokenizer": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-4.0.0.tgz",
"integrity": "sha512-QxULHAm7cNu72w97JUNCBFODFaXpbDg+dP8b/oWFAZ2MTRppA3U00Y2L1HqaS4J6yBqxwa/Y3nMBaxVKbB/NsA==",
"license": "MIT",
"engines": {
"node": ">=20.19.0"
}
}
}
}
{
"name": "sample-csstools-css-tokenizer",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "Clean-room verification for @csstools/css-tokenizer tokenize",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"@csstools/css-tokenizer": "4.0.0"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "tokenize CSS string into tokens with @csstools/css-tokenizer",
"kind": "HOW",
"packages": [
"pkg:npm/%40csstools/css-tokenizer@4.0.0"
],
"symbols": [
"tokenize"
]
}
import {
tokenize,
tokenizer,
TokenType,
isToken,
isTokenIdent,
isTokenDimension,
stringify,
ParseError
} from '@csstools/css-tokenizer';
/**
* Tokenizes a CSS string into an array of CSSToken items.
* @param {string} css
* @param {object} [options]
* @returns {Array}
*/
export function tokenizeCSS(css, options = {}) {
return tokenize({ css, unicodeRangesAllowed: options.unicodeRangesAllowed }, options);
}
/**
* Filters an array of tokens by token type.
* @param {Array} tokens
* @param {string} type
* @returns {Array}
*/
export function filterTokensByType(tokens, type) {
return tokens.filter((token) => isToken(token) && token[0] === type);
}
/**
* Tokenizes CSS while collecting any parsing errors encountered.
* @param {string} css
* @returns {{ tokens: Array, errors: Array<ParseError> }}
*/
export function tokenizeWithErrors(css) {
const errors = [];
const tokens = tokenize(
{ css },
{
onParseError: (err) => {
errors.push(err);
}
}
);
return { tokens, errors };
}
/**
* Reconstructs CSS string representation from an array of tokens.
* @param {Array} tokens
* @returns {string}
*/
export function stringifyTokens(tokens) {
return stringify(...tokens);
}
export {
tokenize,
tokenizer,
TokenType,
isToken,
isTokenIdent,
isTokenDimension,
stringify,
ParseError
};
import assert from 'node:assert/strict';
import {
tokenize,
TokenType,
isToken,
isTokenIdent,
isTokenDimension,
stringify,
tokenizeCSS,
filterTokensByType,
tokenizeWithErrors,
stringifyTokens
} from '../src/index.js';
// 1. tokenize is exported as a function from @csstools/css-tokenizer
assert.equal(typeof tokenize, 'function', 'tokenize must be a function');
assert.equal(typeof tokenizeCSS, 'function', 'tokenizeCSS helper must be a function');
// 2. tokenize decomposes standard CSS declarations into CSSToken tuples containing type, raw representation, start and end offsets
const cssSample = 'color: red; margin: 10px;';
const tokens = tokenizeCSS(cssSample);
assert.ok(Array.isArray(tokens), 'tokens must be an array');
assert.ok(tokens.length > 0, 'tokens array must not be empty');
for (const token of tokens) {
assert.ok(isToken(token), 'each element must satisfy isToken');
assert.equal(typeof token[0], 'string', 'token[0] (type) must be string');
assert.equal(typeof token[1], 'string', 'token[1] (raw) must be string');
assert.equal(typeof token[2], 'number', 'token[2] (start) must be number');
assert.equal(typeof token[3], 'number', 'token[3] (end) must be number');
}
const firstToken = tokens[0];
assert.equal(firstToken[0], TokenType.Ident);
assert.equal(firstToken[1], 'color');
assert.equal(firstToken[2], 0);
assert.equal(firstToken[3], 4);
assert.deepEqual(firstToken[4], { value: 'color' });
assert.ok(isTokenIdent(firstToken), 'first token must satisfy isTokenIdent');
const lastToken = tokens[tokens.length - 1];
assert.equal(lastToken[0], TokenType.EOF);
// 3. tokenize extracts structured token values for identifiers and dimensions with parsed units and numeric types
const dimensionTokens = filterTokensByType(tokens, TokenType.Dimension);
assert.equal(dimensionTokens.length, 1, 'must find exactly one dimension token');
const dimToken = dimensionTokens[0];
assert.ok(isTokenDimension(dimToken), 'must satisfy isTokenDimension');
assert.equal(dimToken[1], '10px');
assert.equal(dimToken[4].value, 10);
assert.equal(dimToken[4].unit, 'px');
assert.equal(dimToken[4].type, 'integer');
const identTokens = filterTokensByType(tokens, TokenType.Ident);
const identValues = identTokens.map((t) => t[4].value);
assert.deepEqual(identValues, ['color', 'red', 'margin']);
// 4. tokenize with onParseError callback captures parser errors without throwing an unhandled exception
const malformedCSS = '"unclosed string\n';
const { tokens: errTokens, errors } = tokenizeWithErrors(malformedCSS);
assert.ok(Array.isArray(errTokens), 'errTokens must be an array');
assert.ok(Array.isArray(errors), 'errors must be an array');
assert.ok(errors.length > 0, 'must report at least one parse error for unclosed newline string');
assert.ok(errors[0].message.includes('string'), 'error message must indicate string parse error');
assert.equal(typeof errors[0].sourceStart, 'number', 'error must contain sourceStart offset');
assert.equal(typeof errors[0].sourceEnd, 'number', 'error must contain sourceEnd offset');
// 5. stringify reconstructs valid CSS text from an array of tokens produced by tokenize
const reconstructedCSS = stringifyTokens(tokens);
assert.equal(reconstructedCSS, cssSample, 'stringifyTokens must reconstruct original CSS string');
const directStringify = stringify(...tokens);
assert.equal(directStringify, cssSample, 'direct stringify must match original CSS string');
console.log('All contract assertions passed successfully.');
오리진 시더
익명