Sample
@cacheable/utils 2.5.0: shorthandToMilliseconds
Verified sample for npm @cacheable/utils 2.5.0: shorthandToMilliseconds. The contract ran on node 22 · linux debian/x64 · docker and passed.
sha256:1289c6a94cd7e47c8d4cb977f1eeb456a0393dad666c9ad79f801a8bc55ab20a
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 npm
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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-05 |
Case
HOW- Goal
- verify shorthandToMilliseconds in pkg:npm/%40cacheable/utils@2.5.0
- Packages
- Symbols
-
- shorthandToMilliseconds
- Created
- 2026-09-05T16:36:46Z
Contract
- shorthandToMilliseconds returns undefined when input is undefined or non-string and non-number
- shorthandToMilliseconds returns the numeric value directly when input is a number
- shorthandToMilliseconds parses numeric strings into milliseconds
- shorthandToMilliseconds parses shorthand duration strings with units ms, s, m, h, hr, and d into milliseconds
- shorthandToMilliseconds parses fractional duration strings with units
- shorthandToMilliseconds throws an Error with descriptive message when string format is unsupported
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Source
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 shorthandToMilliseconds in pkg:npm/%40cacheable/utils@2.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40cacheable/utils@2.5.0
Demonstrate these symbols/APIs:
- shorthandToMilliseconds
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:9692ffc80740a75144c81b602b7bbbc783cfc9c739b189fd59bc3b2498835f0b","contract":["shorthandToMilliseconds returns undefined when input is undefined or non-string and non-number","shorthandToMilliseconds returns the numeric value directly when input is a number","shorthandToMilliseconds parses numeric strings into milliseconds","shorthandToMilliseconds parses shorthand duration strings with units ms, s, m, h, hr, and d into milliseconds","shorthandToMilliseconds parses fractional duration strings with units","shorthandToMilliseconds throws an Error with descriptive message when string format is unsupported"],"goal":"verify shorthandToMilliseconds in pkg:npm/%40cacheable/utils@2.5.0","kind":"HOW","packages":["pkg:npm/%40cacheable/utils@2.5.0"],"schemaVersion":1,"symbols":["shorthandToMilliseconds"]},"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/%40cacheable/utils@2.5.0"],"schemaVersion":1,"subject":"pkg:npm/%40cacheable/utils@2.5.0","symbols":["shorthandToMilliseconds"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-cacheable-utils",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-cacheable-utils",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@cacheable/utils": "2.5.0"
}
},
"node_modules/@cacheable/utils": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/@cacheable/utils/-/utils-2.5.0.tgz",
"integrity": "sha512-buipgOVDkkPXNR5+xBpDw7Zk2n1EvU7qBJCNUcL7rhQ//kfpOXPAvQ511Os0vpLYJ1pZnvudNytkQt2hst3wqA==",
"license": "MIT",
"dependencies": {
"hashery": "^1.5.1",
"keyv": "^5.6.0"
}
},
"node_modules/@keyv/serialize": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.1.1.tgz",
"integrity": "sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==",
"license": "MIT"
},
"node_modules/hashery": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/hashery/-/hashery-1.5.1.tgz",
"integrity": "sha512-iZyKG96/JwPz1N55vj2Ie2vXbhu440zfUfJvSwEqEbeLluk7NnapfGqa7LH0mOsnDxTF85Mx8/dyR6HfqcbmbQ==",
"license": "MIT",
"dependencies": {
"hookified": "^1.15.0"
},
"engines": {
"node": ">=20"
}
},
"node_modules/hookified": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/hookified/-/hookified-1.15.1.tgz",
"integrity": "sha512-MvG/clsADq1GPM2KGo2nyfaWVyn9naPiXrqIe4jYjXNZQt238kWyOGrsyc/DmRAQ+Re6yeo6yX/yoNCG5KAEVg==",
"license": "MIT"
},
"node_modules/keyv": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz",
"integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==",
"license": "MIT",
"dependencies": {
"@keyv/serialize": "^1.1.1"
}
}
}
}
{
"name": "sample-cacheable-utils",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of @cacheable/utils shorthandToMilliseconds",
"type": "module",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"@cacheable/utils": "2.5.0"
}
}
{
"schemaVersion": 1,
"goal": "verify shorthandToMilliseconds in pkg:npm/%40cacheable/utils@2.5.0",
"kind": "HOW",
"packages": [
"pkg:npm/%40cacheable/utils@2.5.0"
],
"symbols": [
"shorthandToMilliseconds"
]
}
import { shorthandToMilliseconds } from '@cacheable/utils';
/**
* Convert shorthand time string or number to milliseconds.
* @param {string | number} [shorthand]
* @returns {number | undefined}
*/
export function parseDuration(shorthand) {
return shorthandToMilliseconds(shorthand);
}
export { shorthandToMilliseconds };
import assert from 'node:assert';
import { shorthandToMilliseconds, parseDuration } from '../src/index.js';
// 1. shorthandToMilliseconds returns undefined when input is undefined or non-string and non-number
assert.strictEqual(shorthandToMilliseconds(), undefined);
assert.strictEqual(shorthandToMilliseconds(undefined), undefined);
assert.strictEqual(shorthandToMilliseconds(null), undefined);
assert.strictEqual(shorthandToMilliseconds(true), undefined);
assert.strictEqual(shorthandToMilliseconds({}), undefined);
assert.strictEqual(parseDuration(undefined), undefined);
// 2. shorthandToMilliseconds returns the numeric value directly when input is a number
assert.strictEqual(shorthandToMilliseconds(0), 0);
assert.strictEqual(shorthandToMilliseconds(1500), 1500);
assert.strictEqual(shorthandToMilliseconds(-500), -500);
assert.strictEqual(parseDuration(3000), 3000);
// 3. shorthandToMilliseconds parses numeric strings into milliseconds
assert.strictEqual(shorthandToMilliseconds('0'), 0);
assert.strictEqual(shorthandToMilliseconds('2500'), 2500);
assert.strictEqual(parseDuration('1000'), 1000);
// 4. shorthandToMilliseconds parses shorthand duration strings with units ms, s, m, h, hr, and d into milliseconds
assert.strictEqual(shorthandToMilliseconds('500ms'), 500);
assert.strictEqual(shorthandToMilliseconds('2s'), 2000);
assert.strictEqual(shorthandToMilliseconds('5m'), 300000);
assert.strictEqual(shorthandToMilliseconds('1h'), 3600000);
assert.strictEqual(shorthandToMilliseconds('2hr'), 7200000);
assert.strictEqual(shorthandToMilliseconds('1d'), 86400000);
assert.strictEqual(shorthandToMilliseconds('10MS'), 10);
assert.strictEqual(shorthandToMilliseconds('10 S'), 10000);
// 5. shorthandToMilliseconds parses fractional duration strings with units
assert.strictEqual(shorthandToMilliseconds('1.5s'), 1500);
assert.strictEqual(shorthandToMilliseconds('0.5m'), 30000);
assert.strictEqual(shorthandToMilliseconds('2.5h'), 9000000);
assert.strictEqual(shorthandToMilliseconds('0.5d'), 43200000);
// 6. shorthandToMilliseconds throws an Error with descriptive message when string format is unsupported
assert.throws(
() => shorthandToMilliseconds('invalid'),
/Unsupported time format: "invalid"\. Use 'ms', 's', 'm', 'h', 'hr', or 'd'\./
);
assert.throws(
() => shorthandToMilliseconds('10years'),
/Unsupported time format: "10years"\. Use 'ms', 's', 'm', 'h', 'hr', or 'd'\./
);
console.log('All shorthandToMilliseconds contract assertions passed.');
Origin Seeder
anonymous