{"name":"to-time","version":"3.0.0","author":{"name":"Matan Hafuta"},"license":"MIT","_id":"to-time@3.0.0","maintainers":[{"name":"hafuta","email":"matan@hafuta.com"}],"homepage":"https://github.com/hafuta/to-time#readme","bugs":{"url":"https://github.com/hafuta/to-time/issues"},"nyc":{"exclude":["test/**"],"include":["src/**/*.js"],"reporter":["text","html"]},"dist":{"shasum":"30e22ad81ea841014530c72d9d688fe22e1a6831","tarball":"http://registry-npm.ywwl.com/to-time/download/to-time-3.0.0.tgz","fileCount":11,"integrity":"sha512-LShcO0ADay5uxr49spGkTyTmzh1NnZ4zSczInZt+sM12r2GXaSPhBLMZJpXB8BGd/ZdEq2XNTOlzuqACw+t5KA==","signatures":[{"sig":"MEUCIQDYUlDdWHu/jq1K2ba1+Rta8C+nT87tQQM0L+TOLPOMwAIgBlnJ4GP8nVzwEu1v3umZlnwpPU+CaavezDQpLxUYBhQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/to-time@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":178087,"size":43512,"noattachment":false,"key":"/to-time/-/to-time-3.0.0.tgz"},"main":"./dist/index.cjs","types":"./types/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./types/index.d.ts","import":"./dist/index.mjs","default":"./dist/index.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json"},"gitHead":"2388626a46fa23cbfb92904c60b84703a3097b29","scripts":{"lint":"eslint .","test":"npm run test-source && npm run test-build","build":"rollup -c rollup.config.mjs","pretest":"npm run build","coverage":"nyc npm run test-source","build-min":"npm run build","test-build":"mocha ./test/specBuild.js ./test/specBuildEsm.mjs ./test/specUmd.js","test-source":"mocha ./test/spec","prepublishOnly":"npm run build"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9bf8feda-8e50-44b6-8230-1d8bcb5c20a1"}},"overrides":{"diff":"^8.0.4","serialize-javascript":"^7.0.5"},"repository":{"url":"git+https://github.com/hafuta/to-time.git","type":"git"},"_npmVersion":"11.12.1","description":"Utility for converting textual time periods to time units","directories":{"test":"test"},"sideEffects":false,"_nodeVersion":"22.14.0","dependencies":{"bignumber.js":"^9.1.2"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^17.1.0","chai":"^4.5.0","mocha":"^11.7.5","eslint":"^9.39.4","rollup":"^4.34.9","globals":"^16.5.0","@eslint/js":"^9.39.4","@rollup/plugin-terser":"^0.4.4","@rollup/plugin-commonjs":"^28.0.2","@stylistic/eslint-plugin":"^4.4.1","@rollup/plugin-node-resolve":"^16.0.0"},"_npmOperationalInternal":{"tmp":"tmp/to-time_3.0.0_1774732939608_0.8509906871893977","host":"s3://npm-registry-packages-npm-production"},"readme":"# to-time\n[![CI](https://img.shields.io/github/actions/workflow/status/hafuta/to-time/ci.yml?branch=master)](https://github.com/hafuta/to-time/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/to-time)](https://www.npmjs.com/package/to-time)\n\nUtility for converting textual time periods to time units (milliseconds, seconds, minutes, hours, etc..).\n\n**Due to the lack of precision in floating point numbers arithmetic and the need of keeping the results precise the utility is using the [bignumber.js](https://github.com/MikeMcl/bignumber.js/) library for arithmetic operations on numbers.**\n\n## Install\n\n```sh\nnpm install to-time\n```\n\n**Node.js 20.19+** is required (see `engines` in `package.json`).\n\n## Importing\n\nThe package is built as **dual ESM / CommonJS** and defines an [`exports`](https://nodejs.org/api/packages.html#exports) map in `package.json`. Use the package name `to-time` only—tools resolve it to `dist/index.mjs` (ESM) or `dist/index.cjs` (CJS). TypeScript types are exposed through the same entry.\n\n### Node.js and bundlers (ESM)\n\n```javascript\nimport toTime from 'to-time';\n```\n\nUse this in projects with `\"type\": \"module\"` in `package.json`, in `.mjs` files, or when your bundler targets ESM.\n\n### Node.js and bundlers (CommonJS)\n\n```javascript\nconst toTime = require('to-time');\n```\n\n### TypeScript\n\n```typescript\nimport toTime from 'to-time';\n```\n\nThe same import works with `moduleResolution` set to `node16`, `nodenext`, or `bundler` (recommended for modern tooling).\n\n### Browser (UMD)\n\nFor a plain script tag without a bundler, use the UMD build under `lib/`. **BigNumber.js is bundled** into these files; you do not need a separate script for it.\n\n```html\n<script src=\"node_modules/to-time/lib/to-time.min.js\"></script>\n<!-- exposes global: window.toTime -->\n```\n\nA non-minified file is also published: `node_modules/to-time/lib/to-time.js`.\n\n## Usage\nConverting from textual time period to time units\n\n```javascript\ntoTime('1 hour').seconds(); //3600\n//same as:\ntoTime('1h').seconds(); //3600\n\ntoTime('1 Year 365 Days 4 Hours').hours(); //17524\n//same as:\ntoTime('1y 365d 4h').hours(); //17524\n```\n\nUseful for usage in methods such as setInterval and setTimeout which consume the second argument in milliseconds, it is much clearer for someone who will read the code.\n```javascript\n//Instead of using 43200000 milliseconds (equivalent to 12 hours) we can do the following\nsetInterval(() => {\n  //Do something here\n}, toTime('12h').ms());\n\n//Instead of using 5400000 milliseconds (equivalent to 1.5 hour)\nsetTimeout(() => {\n  //Do something here\n}, toTime.fromHours(1.5).ms());\n```\n\n##### Allowed suffixes (all case-insensetive)\n\n* Year, Years, Y\n* Week, Weeks, W\n* Day, Days, D\n* Hour, Hours, H\n* Minute, Minutes, M\n* Second, Seconds, S\n* Millisecond, Milliseconds, MS\n\n\n#### Initializing using factory methods\nIt is also possible to create a TimeFrame instance by calling the static factory methods.\nThe result will be a TimeFrame object similar to the one that is created by invoking the function with a textual time period.\n```javascript\ntoTime.fromHours(4).addMinutes(30).hours(); //4.5\ntoTime.fromYears(4).addWeeks(4).days(); //1488\n```\n###### Available factory methods\n* fromMilliseconds\n* fromSeconds\n* fromMinutes\n* fromHours\n* fromDays\n* fromWeeks\n* fromYears\n\n\n#### Appenders methods\nIt is possible to add additional units to the TimeFrame object by invoking one of the appender methods on the returned instance:\n\n```javascript\ntoTime('0.5 hour').addMinutes(30).seconds(); //3600\ntoTime.fromHours(2).addMinutes(30).minutes(); //150\n```\n\n###### Available appenders:\n* addMilliseconds\n* addSeconds\n* addMinutes\n* addHours\n* addDays\n* addWeeks\n* addYears\n\n#### Getters methods\nThe getter methods are used to get the value of the TimeFrame object in a specific time unit.\n* milliseconds : Number\n* ms (alias to milliseconds)\n* minutes : Number\n* hours : Number\n* days : Number\n* weeks : Number\n* years : Number\n* humanize : String\n\n#### Converting the TimeFrame object to human readable format\nIt is also possible to use to-time in order to convert time units into human readable format.\nExample:\n```javascript\nconst frame = toTime.fromMilliseconds(500005050505005);\nframe.humanize(); //15855 Years, 2 Weeks, 6 Days, 11 Hours, 48 Minutes, 25 Seconds, 5 Milliseconds\n```\n\n## Contributing\n\n##### Running tests\n\n* Make sure to write tests, run new & existing tests using:\n  ```shell\n  npm run test\n  ```\n  \n* Check for source code & tests code styling by running eslint:\n  ```shell\n  npm run lint\n  ```\n\n* If tests are passing and eslint doesn't return any error -> Create pull request\n\n## License\nMIT\n","publish_time":1774732939810,"_cnpm_publish_time":1774732939810,"dist-tags":{"latest":"3.0.2"}}