{"name":"to-time","version":"1.0.0","description":"Utility for converting textual time periods to time units","main":"src/index.js","directories":{"test":"test"},"scripts":{"test-source":"mocha ./test/spec","test-build":"mocha ./test/specBuild","test":"npm run test-source && npm run test-build","coverage":"istanbul cover _mocha","lint":"eslint -c .eslintrc.json --ignore-path ./.eslintignore .","build":"browserify --standalone to-time -t [ babelify --presets [ es2015 ] ] src/index.js -o lib/to-time.js","build-min":"browserify --standalone to-time -t [ babelify --presets [ es2015 ] ] src/index.js | ./node_modules/.bin/uglifyjs --compress --screw-ie8 > lib/to-time.min.js"},"author":{"name":"Matan Hafuta"},"license":"MIT","devDependencies":{"babel-core":"^6.13.2","babel-preset-es2015":"^6.13.2","babelify":"^7.3.0","browserify":"^13.1.0","chai":"^3.5.0","chai-as-promised":"^5.3.0","eslint":"^3.2.2","istanbul":"^0.4.4","mocha":"^3.0.1","uglify-js":"^2.7.0"},"repository":{"type":"git","url":"git+https://github.com/hafuta/to-time.git"},"dependencies":{"bignumber.js":"^2.4.0"},"gitHead":"2eaa276ad0bc83d110b60815ca2acd819ead44b6","bugs":{"url":"https://github.com/hafuta/to-time/issues"},"homepage":"https://github.com/hafuta/to-time#readme","_id":"to-time@1.0.0","_shasum":"7c9375c76925bfd655e9b0398baa0d5597a6b7db","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.5.0","_npmUser":{"name":"hafuta","email":"matan@hafuta.com"},"dist":{"shasum":"7c9375c76925bfd655e9b0398baa0d5597a6b7db","tarball":"http://registry-npm.ywwl.com/to-time/download/to-time-1.0.0.tgz","integrity":"sha512-1SN57auDCAOTPdSZBFnJcucED/TyI6dyu0O71FDycfkVa9rJzc/lUM7NJniyGX9lt0Vhb4fcLGMku0JhdgEbfA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICfk6Xn/fkKhWFvg5K0cHd2CxllLTpGwU5AjrhXqBWFjAiBB3qGWazwCzlJzpm7zQlR+XhwHibNhAJOf9eyb5kC2ug=="}],"size":40982,"noattachment":false,"key":"/to-time/-/to-time-1.0.0.tgz"},"maintainers":[{"name":"hafuta","email":"matan@hafuta.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/to-time-1.0.0.tgz_1475462367343_0.8397808780428022"},"readme":"# to-time\n[![Build Status](https://travis-ci.org/hafuta/to-time.svg?branch=master)](https://travis-ci.org/hafuta/to-time) [![npm version](https://badge.fury.io/js/to-time.svg)](https://badge.fury.io/js/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\nFirst install the package and save it to package.json using npm:\n```sh\nnpm install --save to-time\n```\n\nTo require in the browser:\n\nBoth files located in _lib_ directory already include the bignumber.js dependency and there is no need to include this module in the browser.\n```html\n<!-- access using window.toTime -->\n<script src=\"node_modules/to-time/lib/to-time.min.js\"></script>\n```\n\nTo require when using NodeJS:\n```node\nconst toTime = require('to-time');\n```\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 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## To Do\n- [ ]  Add Karma for testing in browser environment (Currently testing server side using Mocha)\n\n\n## License\nMIT\n","publish_time":1475462369216,"_cnpm_publish_time":1475462369216,"dist-tags":{"latest":"3.0.2"}}