{"name":"to-time","version":"0.1.3","description":"Utility for converting textual time periods to time units","main":"lib/index.js","directories":{"test":"test"},"scripts":{"test":"mocha ./test","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":{"browserify":"^13.0.1","babel-core":"^6.10.4","mocha":"^2.5.3","chai":"^3.5.0","istanbul":"^0.4.4","babel-preset-es2015":"^6.9.0","babelify":"^7.3.0","uglify-js":"^2.7.0"},"repository":{"type":"git","url":"git+https://github.com/hafuta/to-time.git"},"dependencies":{"bignumber.js":"^2.4.0"},"gitHead":"84ec1b706400e6b95840eff882fbab02f55f0691","bugs":{"url":"https://github.com/hafuta/to-time/issues"},"homepage":"https://github.com/hafuta/to-time#readme","_id":"to-time@0.1.3","_shasum":"d37aa2c4ba30b01de52aad44fd970ee53dcfbaab","_from":".","_npmVersion":"3.10.6","_nodeVersion":"6.3.0","_npmUser":{"name":"hafuta","email":"matan@hafuta.com"},"dist":{"shasum":"d37aa2c4ba30b01de52aad44fd970ee53dcfbaab","tarball":"http://registry-npm.ywwl.com/to-time/download/to-time-0.1.3.tgz","integrity":"sha512-0s52d6cqi44TAsGq8s0kWouBElSOYydROM0oDhsvHlpul/cDLKwN1iE6tDVLW2Z5CWWbmvnXkD4diLPZutoeJA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+/IVr/BzlU1hYMax1F6eZ/32sBSI63U+Kfm3Zxb21ZQIgCfQPTsQidZlmgGxWUSUUSr27KSBDkoCkS8wFri/li8o="}],"size":40780,"noattachment":false,"key":"/to-time/-/to-time-0.1.3.tgz"},"maintainers":[{"name":"hafuta","email":"matan@hafuta.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/to-time-0.1.3.tgz_1468683179674_0.3493667140137404"},"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":1468683182239,"_cnpm_publish_time":1468683182239,"dist-tags":{"latest":"3.0.2"}}