{"_id":"@ciaksoy/hhmmss","name":"@ciaksoy/hhmmss","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ciaksoy/hhmmss","version":"1.0.0","description":"Convert seconds to HH:MM:SS format","main":"index.ts","scripts":{"test":"jest"},"repository":{"type":"git","url":"git+https://github.com/ciaksoy/hhmmss.git"},"keywords":["hhmmss","seconds","format"],"author":{"name":"Cihan Aksoy"},"license":"MIT","bugs":{"url":"https://github.com/ciaksoy/hhmmss/issues"},"homepage":"https://github.com/ciaksoy/hhmmss#readme","devDependencies":{"@types/jest":"^29.5.12","jest":"^29.7.0","ts-jest":"^29.2.2"},"_id":"@ciaksoy/hhmmss@1.0.0","gitHead":"1ed3ae91a640c0d14c52778adaaf89cb97baa09f","_nodeVersion":"20.12.0","_npmVersion":"10.5.0","dist":{"integrity":"sha512-VtOFVx/BMK2xBjkTP1Jm6P/FVn0MZMD6bzsiPT3UdCTPfuQpj5gaV0SLSWPEZTt+xy1gBEqYahleoj4+fAFyLg==","shasum":"cdf926060904fd46c673deeacfda5e642239f63b","tarball":"https://registry.npmjs.org/@ciaksoy/hhmmss/-/hhmmss-1.0.0.tgz","fileCount":7,"unpackedSize":8223,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGG4SFNFfFHcmVr/HpArifL2Go2jEMepaRj5xPn/KOZvAiEA3Aa9iJS+4DmfjdupXNebKMJOdCBZhE8qYigV3gDKidw="}]},"_npmUser":{"name":"ciaksoy","email":"mcihanaksoy@gmail.com"},"directories":{},"maintainers":[{"name":"ciaksoy","email":"mcihanaksoy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hhmmss_1.0.0_1720742118462_0.09551807729071404"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-11T23:55:18.352Z","1.0.0":"2024-07-11T23:55:18.645Z","modified":"2024-07-11T23:55:18.992Z"},"maintainers":[{"name":"ciaksoy","email":"mcihanaksoy@gmail.com"}],"description":"Convert seconds to HH:MM:SS format","homepage":"https://github.com/ciaksoy/hhmmss#readme","keywords":["hhmmss","seconds","format"],"repository":{"type":"git","url":"git+https://github.com/ciaksoy/hhmmss.git"},"author":{"name":"Cihan Aksoy"},"bugs":{"url":"https://github.com/ciaksoy/hhmmss/issues"},"license":"MIT","readme":"\r\nThis function converts a given number of seconds into a formatted time string. It supports various time formats, including hours, minutes, and seconds, and adjusts the output based on the provided format string.\r\n\r\n## Function Signature\r\n\r\n```typescript\r\nexport default function(fromSeconds: number, format: string): string;\r\n```\r\n\r\n## Parameters\r\n\r\n-   **fromSeconds** (`number`): The time in seconds that you want to convert.\r\n-   **format** (`string`): The format string that specifies how the time should be formatted. The format can include placeholders for hours (`HH`), minutes (`MM`), and seconds (`SS`).\r\n\r\n## Description\r\n\r\nThe `formatTime` function takes an input time in seconds and formats it according to the specified format string. The function supports the following placeholders in the format string:\r\n\r\n-   `HH`: Hours\r\n-   `MM`: Minutes\r\n-   `SS`: Seconds\r\n\r\n### Example Usage\r\n\r\n```javascript\r\nimport formatTime from './formatTime';\r\n```\r\n\r\n```javascript\r\nconst time1 = formatTime(3661, 'HH:MM:SS'); // \"01:01:01\" \r\nconst time2 = formatTime(61, 'MM:SS'); // \"01:01\" \r\nconst time3 = formatTime(59, 'SS'); // \"59\" \r\nconst time4 = formatTime(3661, 'MM:SS'); // \"61:01\" \r\nconst time5 = formatTime(3661, 'SS'); // \"3661\" \r\nconst time6 = formatTime(3661, '(HH:)MM:SS'); // \"01:01:01\" \r\nconst time7 = formatTime(361, '(HH:)MM:SS'); // \"06:01\" \r\nconst time8 = formatTime(61, '(MM:)SS'); // \"01:01\" \r\nconst time9 = formatTime(1, '(MM:)SS'); // \"01\" \r\nconst time10 = formatTime(3661, '(HH:)(MM:)SS'); // \"01:01:01\" \r\nconst time11 = formatTime(61, '(HH:)(MM:)SS'); // \"01:01\" \r\nconst time12 = formatTime(1, '(HH:)(MM:)SS'); // \"01\" \r\nconst time13 = formatTime(60, 'MM:SS'); // \"01:00\" \r\nconst time14 = formatTime(3600, 'HH:MM:SS'); // \"01:00:00\" \r\nconst time15 = formatTime(0, 'HH:MM:SS'); // \"00:00:00\" \r\nconst time16 = formatTime(0, '(HH:)(MM:)SS'); // \"00\"\r\n```\r\n\r\n### Features\r\n\r\n-   **Dynamic Adjustment**: If the format string does not include hours (`HH`), the hours are added to the minutes. Similarly, if the format string does not include minutes (`MM`), the minutes are added to the seconds.\r\n-   **Flexible Formatting**: The format string can include optional placeholders within parentheses. If the value for a placeholder is zero, the placeholder and its parentheses are removed from the output.\r\n\r\n## Implementation Details\r\n\r\n1.  **Calculation**: The function first calculates the hours, minutes, and seconds from the input `fromSeconds`.\r\n2.  **Adjustment**: The function adjusts the minutes and seconds based on the absence of hours and minutes in the format string.\r\n3.  **Replacement**: The function creates a replacements object with zero-padded string representations of hours, minutes, and seconds.\r\n4.  **Formatting**: The function processes the format string to handle optional placeholders within parentheses and replaces the placeholders with the corresponding values from the replacements object.\r\n\r\n### Edge Cases\r\n\r\n-   If the input seconds are less than 60, and the format string includes hours or minutes, the output will properly display `00` for those components.\r\n-   If the input seconds are exactly 0, the output will be `00:00:00` or equivalent based on the format string.\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please open an issue or submit a pull request with your improvements or bug fixes.","readmeFilename":"README.md"}