샘플
ms 2.0.0: format millisecond durations to short or verbose strings and parse duration strings with ms
검증된 샘플 — npm ms 2.0.0: format millisecond durations to short or verbose strings and parse duration strings with ms. node 22 · linux alpine/x64 · docker에서…
sha256:12e1cd1e7fb96215adf4fdfb55b0bf8130bc16041d5ef2e495cf9caae9509c19
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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- 목표
- format millisecond durations to short or verbose strings and parse duration strings with ms
- 패키지
- 심벌
-
- ms
- 생성일
- 2026-08-27T12:47:11Z
컨트랙트
- assert.strictEqual(ms('2 days'), 172800000);
- assert.strictEqual(ms('1d'), 86400000);
- assert.strictEqual(ms('10h'), 36000000);
- assert.strictEqual(ms('2.5 hrs'), 9000000);
- assert.strictEqual(ms('1m'), 60000);
- assert.strictEqual(ms('5s'), 5000);
- assert.strictEqual(ms('100'), 100);
- assert.strictEqual(ms('100ms'), 100);
- assert.strictEqual(ms('1y'), 31557600000);
- assert.strictEqual(ms(60000), '1m');
- assert.strictEqual(ms(2 * 60000), '2m');
- assert.strictEqual(ms(86400000), '1d');
- assert.strictEqual(ms(500), '500ms');
- assert.strictEqual(ms(60000, { long: true }), '1 minute');
- assert.strictEqual(ms(2 * 60000, { long: true }), '2 minutes');
- assert.strictEqual(ms(86400000, { long: true }), '1 day');
- assert.strictEqual(ms(2 * 86400000, { long: true }), '2 days');
- assert.strictEqual(ms('invalid'), undefined);
- assert.throws(() => ms(''), /val is not a non-empty string or a valid number/);
파일
- NOTES.md
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
소스
# ms Duration Formatting and Parsing
## Overview
`ms` provides conversion between human-readable duration strings (e.g. `'2 days'`, `'1d'`, `'10h'`, `'1m'`, `'5s'`) and millisecond integers, as well as formatting millisecond counts into either concise strings (e.g. `'1m'`, `'1d'`) or verbose strings (e.g. `'1 minute'`, `'2 minutes'`, `'1 day'`).
## Parsing Behavior
1. Parses time units: `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `years` and their abbreviations (`ms`, `s`, `m`, `h`, `d`, `y`).
2. Suffixless strings (e.g. `'100'`) default to milliseconds.
3. Unrecognized unit strings (e.g. `'invalid'`) return `undefined` rather than throwing.
4. Empty strings, invalid numbers, or non-string/non-number values throw an explicit Error.
## Formatting Behavior
1. Default format (`ms(n)`): Returns compact strings such as `'500ms'`, `'1m'`, `'2m'`, `'1d'`.
2. Long format (`ms(n, { long: true })`): Returns pluralized strings such as `'1 minute'`, `'2 minutes'`, `'1 day'`, `'2 days'`.
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: format millisecond durations to short or verbose strings and parse duration strings with ms
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/ms@2.0.0
Demonstrate these symbols/APIs:
- ms
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:8d4cc317034a11f9cb580d1be369a1f88f5de1be2143fefc1907a712864fb304","contract":["assert.strictEqual(ms('2 days'), 172800000);","assert.strictEqual(ms('1d'), 86400000);","assert.strictEqual(ms('10h'), 36000000);","assert.strictEqual(ms('2.5 hrs'), 9000000);","assert.strictEqual(ms('1m'), 60000);","assert.strictEqual(ms('5s'), 5000);","assert.strictEqual(ms('100'), 100);","assert.strictEqual(ms('100ms'), 100);","assert.strictEqual(ms('1y'), 31557600000);","assert.strictEqual(ms(60000), '1m');","assert.strictEqual(ms(2 * 60000), '2m');","assert.strictEqual(ms(86400000), '1d');","assert.strictEqual(ms(500), '500ms');","assert.strictEqual(ms(60000, { long: true }), '1 minute');","assert.strictEqual(ms(2 * 60000, { long: true }), '2 minutes');","assert.strictEqual(ms(86400000, { long: true }), '1 day');","assert.strictEqual(ms(2 * 86400000, { long: true }), '2 days');","assert.strictEqual(ms('invalid'), undefined);","assert.throws(() =\u003e ms(''), /val is not a non-empty string or a valid number/);"],"goal":"format millisecond durations to short or verbose strings and parse duration strings with ms","kind":"HOW","packages":["pkg:npm/ms@2.0.0"],"schemaVersion":1,"symbols":["ms"]},"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/ms@2.0.0"],"schemaVersion":1,"subject":"pkg:npm/ms@2.0.0","symbols":["ms"],"verifierAdapter":"node-typescript@1"}
{
"name": "ms-format-and-parse-durations",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ms-format-and-parse-durations",
"version": "1.0.0",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT"
}
}
}
{
"name": "ms-format-and-parse-durations",
"version": "1.0.0",
"type": "module",
"dependencies": {
"ms": "2.0.0"
}
}
{
"schemaVersion": 1,
"goal": "format millisecond durations to short or verbose strings and parse duration strings with ms",
"kind": "HOW",
"packages": [
"pkg:npm/ms@2.0.0"
],
"symbols": [
"ms"
]
}
import assert from 'node:assert/strict';
import ms from 'ms';
// 1. Parsing duration strings into milliseconds
assert.strictEqual(ms('2 days'), 172800000);
assert.strictEqual(ms('1d'), 86400000);
assert.strictEqual(ms('10h'), 36000000);
assert.strictEqual(ms('2.5 hrs'), 9000000);
assert.strictEqual(ms('1m'), 60000);
assert.strictEqual(ms('5s'), 5000);
assert.strictEqual(ms('100'), 100);
assert.strictEqual(ms('100ms'), 100);
assert.strictEqual(ms('1y'), 31557600000);
// 2. Formatting milliseconds into short duration strings
assert.strictEqual(ms(60000), '1m');
assert.strictEqual(ms(2 * 60000), '2m');
assert.strictEqual(ms(86400000), '1d');
assert.strictEqual(ms(500), '500ms');
// 3. Formatting milliseconds into verbose/long duration strings
assert.strictEqual(ms(60000, { long: true }), '1 minute');
assert.strictEqual(ms(2 * 60000, { long: true }), '2 minutes');
assert.strictEqual(ms(86400000, { long: true }), '1 day');
assert.strictEqual(ms(2 * 86400000, { long: true }), '2 days');
// 4. Invalid inputs: unrecognized string returns undefined; empty input or non-number throws
assert.strictEqual(ms('invalid'), undefined);
assert.throws(() => ms(''), /val is not a non-empty string or a valid number/);
오리진 시더
익명