CodeSampleX

示例

luxon 3.6.1: Info

已验证示例 — npm luxon 3.6.1: Info. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: Info.months returns localized month names for specified length formats

sha256:565c62b3f299afcc86b437452aa2f52ce2c3ad914cccb7a3e6dcd72762184fb8

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

案例

HOW
目标
verify luxon.Info in pkg:npm/luxon@3.6.1
包
符号
  • luxon.Info
创建时间
2026-08-27T23:48:10Z

契约

  1. Info.months returns localized month names for specified length formats
  2. Info.weekdays returns localized weekday names starting on Monday
  3. Info.eras and Info.meridiems return localized era and meridiem strings
  4. Info.features reports runtime capabilities for relative and localeWeek formatting
  5. Info.isValidIANAZone validates standard and invalid IANA time zone identifiers
  6. Info.normalizeZone converts string identifiers into Zone objects and handles default zones
  7. Info.hasDST identifies whether a given time zone observes daylight saving time

文件

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 luxon.Info in pkg:npm/luxon@3.6.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/luxon@3.6.1
Demonstrate these symbols/APIs:
  - luxon.Info

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:cef74cb4497598bafe23f9dc227e62dcf9201ddf353df52dd849f38e897a7bf7","contract":["Info.months returns localized month names for specified length formats","Info.weekdays returns localized weekday names starting on Monday","Info.eras and Info.meridiems return localized era and meridiem strings","Info.features reports runtime capabilities for relative and localeWeek formatting","Info.isValidIANAZone validates standard and invalid IANA time zone identifiers","Info.normalizeZone converts string identifiers into Zone objects and handles default zones","Info.hasDST identifies whether a given time zone observes daylight saving time"],"goal":"verify luxon.Info in pkg:npm/luxon@3.6.1","kind":"HOW","packages":["pkg:npm/luxon@3.6.1"],"schemaVersion":1,"symbols":["luxon.Info"]},"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/luxon@3.6.1"],"schemaVersion":1,"subject":"pkg:npm/luxon@3.6.1","symbols":["luxon.Info"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { Info } from 'luxon';

export { Info };

/**
 * Returns formatted month names for a given format and options.
 *
 * @param {string} [format='long'] - 'long', 'short', 'narrow', 'numeric', '2-digit'
 * @param {object} [options={}] - Options including locale and numberingSystem
 * @returns {string[]} Array of month names
 */
export function getMonths(format = 'long', options = {}) {
  return Info.months(format, options);
}

/**
 * Returns formatted weekday names for a given format and options.
 *
 * @param {string} [format='long'] - 'long', 'short', 'narrow', 'numeric'
 * @param {object} [options={}] - Options including locale and numberingSystem
 * @returns {string[]} Array of weekday names (Monday to Sunday)
 */
export function getWeekdays(format = 'long', options = {}) {
  return Info.weekdays(format, options);
}

/**
 * Returns era names for a given format and options.
 *
 * @param {string} [format='short'] - 'long', 'short', 'narrow'
 * @param {object} [options={}] - Options including locale
 * @returns {string[]} Array of era names
 */
export function getEras(format = 'short', options = {}) {
  return Info.eras(format, options);
}

/**
 * Returns meridiem tokens for a given locale.
 *
 * @param {object} [options={}] - Options including locale
 * @returns {string[]} Array of meridiem strings (e.g. ['AM', 'PM'])
 */
export function getMeridiems(options = {}) {
  return Info.meridiems(options);
}

/**
 * Returns available feature flags in the current environment.
 *
 * @returns {object} Feature flags object
 */
export function getFeatures() {
  return Info.features();
}

/**
 * Checks if a zone identifier is a valid IANA time zone.
 *
 * @param {string} zone - IANA time zone identifier
 * @returns {boolean} True if valid IANA zone
 */
export function isIANAZone(zone) {
  return Info.isValidIANAZone(zone);
}

/**
 * Normalizes a time zone identifier or Zone object into a Zone instance.
 *
 * @param {string|object} zone - Zone identifier or Zone object
 * @returns {object} Normalized Zone instance
 */
export function normalizeZone(zone) {
  return Info.normalizeZone(zone);
}

/**
 * Checks if a time zone observes Daylight Saving Time (DST).
 *
 * @param {string} [zone='system'] - Zone identifier
 * @returns {boolean} True if the zone observes DST
 */
export function hasDST(zone = 'system') {
  return Info.hasDST(zone);
}

export default {
  Info,
  getMonths,
  getWeekdays,
  getEras,
  getMeridiems,
  getFeatures,
  isIANAZone,
  normalizeZone,
  hasDST,
};
package-lock.json
{
  "name": "sample-luxon-info",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-luxon-info",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "luxon": "3.6.1"
      }
    },
    "node_modules/luxon": {
      "version": "3.6.1",
      "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.6.1.tgz",
      "integrity": "sha512-tJLxrKJhO2ukZ5z0gyjY1zPh3Rh88Ej9P7jNrZiHMUXHae1yvI2imgOZtL1TO8TW6biMMKfTtAOoEJANgtWBMQ==",
      "license": "MIT",
      "engines": {
        "node": ">=12"
      }
    }
  }
}
package.json
{
  "name": "sample-luxon-info",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "luxon": "3.6.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify luxon.Info in pkg:npm/luxon@3.6.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/luxon@3.6.1"
  ],
  "symbols": [
    "luxon.Info"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Info,
  getMonths,
  getWeekdays,
  getEras,
  getMeridiems,
  getFeatures,
  isIANAZone,
  normalizeZone,
  hasDST,
} from '../index.mjs';

// Contract 1: Info.months returns localized month names for specified length formats
{
  const longMonths = getMonths('long', { locale: 'en' });
  assert.strictEqual(Array.isArray(longMonths), true);
  assert.strictEqual(longMonths.length, 12);
  assert.strictEqual(longMonths[0], 'January');
  assert.strictEqual(longMonths[11], 'December');

  const shortMonths = getMonths('short', { locale: 'en' });
  assert.strictEqual(shortMonths.length, 12);
  assert.strictEqual(shortMonths[0], 'Jan');
  assert.strictEqual(shortMonths[6], 'Jul');

  const numericMonths = getMonths('numeric', { locale: 'en' });
  assert.strictEqual(numericMonths.length, 12);
  assert.strictEqual(numericMonths[0], '1');
  assert.strictEqual(numericMonths[11], '12');
}

// Contract 2: Info.weekdays returns localized weekday names starting on Monday
{
  const longWeekdays = getWeekdays('long', { locale: 'en' });
  assert.strictEqual(Array.isArray(longWeekdays), true);
  assert.strictEqual(longWeekdays.length, 7);
  assert.strictEqual(longWeekdays[0], 'Monday');
  assert.strictEqual(longWeekdays[6], 'Sunday');

  const shortWeekdays = getWeekdays('short', { locale: 'en' });
  assert.strictEqual(shortWeekdays.length, 7);
  assert.strictEqual(shortWeekdays[0], 'Mon');
  assert.strictEqual(shortWeekdays[4], 'Fri');
  assert.strictEqual(shortWeekdays[6], 'Sun');
}

// Contract 3: Info.eras and Info.meridiems return localized era and meridiem strings
{
  const eras = getEras('short', { locale: 'en' });
  assert.strictEqual(Array.isArray(eras), true);
  assert.strictEqual(eras.length, 2);
  assert.strictEqual(eras[0], 'BC');
  assert.strictEqual(eras[1], 'AD');

  const meridiems = getMeridiems({ locale: 'en' });
  assert.strictEqual(Array.isArray(meridiems), true);
  assert.strictEqual(meridiems.length, 2);
  assert.strictEqual(meridiems[0], 'AM');
  assert.strictEqual(meridiems[1], 'PM');
}

// Contract 4: Info.features reports runtime capabilities for relative and localeWeek formatting
{
  const features = getFeatures();
  assert.strictEqual(typeof features, 'object');
  assert.strictEqual(typeof features.relative, 'boolean');
  assert.strictEqual(typeof features.localeWeek, 'boolean');
  assert.strictEqual(features.relative, true);
}

// Contract 5: Info.isValidIANAZone validates standard and invalid IANA time zone identifiers
{
  assert.strictEqual(isIANAZone('UTC'), true);
  assert.strictEqual(isIANAZone('America/New_York'), true);
  assert.strictEqual(isIANAZone('Europe/London'), true);
  assert.strictEqual(isIANAZone('Asia/Tokyo'), true);
  assert.strictEqual(isIANAZone('Invalid/Zone_Name'), false);
  assert.strictEqual(isIANAZone(''), false);
  assert.strictEqual(isIANAZone(null), false);
}

// Contract 6: Info.normalizeZone converts string identifiers into Zone objects and handles default zones
{
  const utcZone = normalizeZone('UTC');
  assert.strictEqual(typeof utcZone, 'object');
  assert.strictEqual(utcZone.name, 'UTC');
  assert.strictEqual(utcZone.isValid, true);

  const systemZone = normalizeZone('system');
  assert.strictEqual(typeof systemZone, 'object');
  assert.strictEqual(systemZone.isValid, true);

  const defaultZone = normalizeZone(null);
  assert.strictEqual(typeof defaultZone, 'object');
  assert.strictEqual(defaultZone.isValid, true);
}

// Contract 7: Info.hasDST identifies whether a given time zone observes daylight saving time
{
  assert.strictEqual(hasDST('UTC'), false);
  assert.strictEqual(hasDST('America/New_York'), true);
}

console.log('Contract tests passed successfully.');

原始种子者

匿名