{"_id":"@anonymort/ms-long","_rev":"1-177dbc5725c9fc2827ca8c1f9008f3a0","name":"@anonymort/ms-long","description":"Extended time conversion utility supporting large values and multiple units","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@anonymort/ms-long","version":"1.0.0","keywords":["ms","milliseconds","time","duration","convert","parse","format"],"author":{"name":"Your Name"},"license":"MIT","_id":"@anonymort/ms-long@1.0.0","maintainers":[{"name":"anonymort","email":"anonymort@protonmail.com"}],"dist":{"shasum":"e2a638e973b23b8bb517982d15d7e74949195987","tarball":"https://registry.npmjs.org/@anonymort/ms-long/-/ms-long-1.0.0.tgz","fileCount":8,"integrity":"sha512-7EGtvDwycDluFcx1ULtuUSbrEWdwHN78b0kqFGZhO8SdKFwXj1EC4xBYL0wTs4uKvPoPdzgNVztBskXhPuN4Qw==","signatures":[{"sig":"MEQCIHTqHg2AMO3KRmAgn3CMEM1rnenOfQj90ma2x0lFa9uuAiAqcNskfV8Wa7IPIh2e/rRz2QxDYwwN2J+KgUF5LgOh1A==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8807},"main":"dist/ms-long.js","types":"dist/ms-long.d.ts","scripts":{"test":"jest","build":"tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"anonymort","email":"anonymort@protonmail.com"},"_npmVersion":"9.6.5","description":"Extended time conversion utility supporting large values and multiple units","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.0","ts-jest":"^27.0.0","typescript":"^4.5.0","@types/jest":"^27.0.0"},"_npmOperationalInternal":{"tmp":"tmp/ms-long_1.0.0_1720172241095_0.16308621071838658","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"@anonymort/ms-long","version":"2.0.0","description":"Extended time conversion utility supporting large values and multiple units","main":"dist/ms-long.js","types":"dist/ms-long.d.ts","scripts":{"build":"tsc","test":"jest","prepublishOnly":"npm run build"},"keywords":["ms","milliseconds","time","duration","convert","parse","format","bigint","scientific"],"author":{"name":"Your Name"},"license":"MIT","devDependencies":{"@types/jest":"^27.0.0","jest":"^27.0.0","ts-jest":"^27.0.0","typescript":"^4.5.0"},"engines":{"node":">=14.0.0"},"gitHead":"f629d5a181df14a3c4eecab2fe8577ff542c5abb","_id":"@anonymort/ms-long@2.0.0","_nodeVersion":"20.14.0","_npmVersion":"9.6.5","dist":{"integrity":"sha512-6lM0QF9Y6IhBysjqiRn/JW8oWlRnGyNCFoV5QG71yMyGQUObpoCzPLYzCVMTJE3ucGECKYOOe6gqXRbimXVkpw==","shasum":"3bf68694790fdea63d7adb6df3bd5fad67e91cac","tarball":"https://registry.npmjs.org/@anonymort/ms-long/-/ms-long-2.0.0.tgz","fileCount":8,"unpackedSize":13180,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDB2YjbzdF0dgLQrLOLcF8GUTdLsWhtICAcgmAECQHfigIgLgQb9tyFzr2OszkE3M7PyP+oVFZmam690V+1hyJuMSM="}]},"_npmUser":{"name":"anonymort","email":"anonymort@protonmail.com"},"directories":{},"maintainers":[{"name":"anonymort","email":"anonymort@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ms-long_2.0.0_1720173698923_0.47543281006714233"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-05T09:37:21.021Z","modified":"2024-07-05T10:01:39.231Z","1.0.0":"2024-07-05T09:37:21.234Z","2.0.0":"2024-07-05T10:01:39.083Z"},"maintainers":[{"name":"anonymort","email":"anonymort@protonmail.com"}],"author":{"name":"Your Name"},"keywords":["ms","milliseconds","time","duration","convert","parse","format","bigint","scientific"],"license":"MIT","readme":"# ms-long\n\nAn extended time conversion utility that builds upon the popular `ms` library, supporting extremely large time values and multiple units, including those needed for scientific projects.\n\n## Features\n\n- Parse time strings to milliseconds (using BigInt for large values)\n- Format milliseconds to human-readable strings\n- Support for extremely large time values (up to eras - billions of years)\n- Combine multiple time units in a single string (e.g., \"1 hour 30 minutes\")\n- More precise calculations, accounting for leap years\n- TypeScript support with improved type safety\n- Separate `parse` and `format` functions for flexible usage\n- Support for decades, centuries, millennia, epochs, and eras\n- Custom time scales for scientific fields\n- Support for BigInt to handle extremely large numbers\n- Scientific notation support for input values\n\n## Installation\n\n```bash\nnpm install @anonymort/ms-long\n```\n\n## Usage\n\n```typescript\nimport msLong, { parse, format } from '@anonymort/ms-long';\n\n// Parse time strings\nconsole.log(msLong('2 hours 30 minutes')); // 9000000n\n\n// Format milliseconds\nconsole.log(msLong(9000000n)); // '2h 30m'\nconsole.log(msLong(9000000n, { long: true })); // '2 hours 30 minutes'\n\n// Parse complex time strings with large units\nconsole.log(parse('2 epochs 1 era')); // 1002000000000000000000n\n\n// Format large values\nconsole.log(format(1002000000000000000000n, { long: true })); \n// '1 era 2 epochs'\n\n// Use scientific notation\nconsole.log(parse('1.5e9 years')); // 47304000000000000000000n\n\n// Custom time scales\nconst customUnits = {\n  galacticYear: 230000000000n * 365n * 24n * 60n * 60n * 1000n, // ~230 million years\n};\n\nconsole.log(parse('2 galacticYears', customUnits)); // 14515200000000000000000n\n\nconsole.log(format(14515200000000000000000n, { long: true, customUnits }));\n// '2 galacticYears'\n```\n\n## API\n\n### msLong(value: string | number | bigint, options?: { long?: boolean; customUnits?: Record<string, bigint> }): string | bigint\n\nThe main function that can both parse and format time values.\n\n- When given a string, it parses it to milliseconds (as BigInt).\n- When given a number or BigInt, it formats it to a time string.\n- The `long` option determines whether to use long format (e.g., \"2 hours\" vs \"2h\").\n- The `customUnits` option allows for defining custom time units.\n\n### parse(value: string, customUnits?: Record<string, bigint>): bigint\n\nParses a time string to milliseconds (as BigInt). Supports multiple units and extremely large time values.\n\n### format(ms: bigint | number, options?: { long?: boolean; customUnits?: Record<string, bigint> }): string\n\nFormats milliseconds (as BigInt or number) to a time string. Can handle extremely large values and provides precise output for large durations.\n\n## Supported Units\n\n- Millisecond(s)\n- Second(s)\n- Minute(s)\n- Hour(s)\n- Day(s)\n- Week(s)\n- Month(s)\n- Year(s)\n- Decade(s)\n- Century(ies)\n- Millennium(a)\n- Epoch(s) (millions of years)\n- Era(s) (billions of years)\n\nCustom units can be defined as needed.\n\n## Scientific and Large-Scale Time Handling\n\n- Supports parsing and formatting of time spans up to billions of years\n- Uses BigInt for precise calculations with extremely large numbers\n- Allows scientific notation input (e.g., \"1.5e9 years\")\n- Custom time scales can be defined for specific scientific applications\n\n## Differences from original `ms` library\n\n- Supports much larger time values (up to eras - billions of years)\n- Allows combining multiple units in a single string\n- More precise calculations for large time values using BigInt\n- Separate `parse` and `format` functions exposed\n- Written in TypeScript for improved type safety\n- Throws more informative errors for invalid inputs\n- Includes 'decade', 'century', 'millennium', 'epoch', and 'era' as time units\n- Supports custom time scales and units\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","readmeFilename":"README.md"}