From 792eddb9fb9ffef9bf03de4bcbef4e2b7e98be86 Mon Sep 17 00:00:00 2001 From: Mike Barrett Date: Tue, 27 May 2014 20:45:04 +0100 Subject: [PATCH] misc tweaks --- README.md | 18 +++++++++--------- package.json | 4 ++-- timestring.js | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6c1e5f8..2c5bc77 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#timestring +#Timestring Attempts to parse a human readable time string into a time based value. @@ -11,7 +11,7 @@ var time = str.parseTime(); console.log(time); // will log 4500 ``` -In the example above `str` is just a plain old `String` object. A new method to the `String` objects prototype named `parseTime`. This method parses the string and returns a time based value. +In the example above `str` is just a plain old `String` object. A new method is added to the `String` objects prototype named `parseTime`. This method parses the string and returns a time based value. **By default the returned time value will be in seconds.** @@ -44,7 +44,7 @@ console.log(time); // will log 4500 ##Keywords -timestring will parse the following keywords into time values: +Timestring will parse the following keywords into time values: 1. `s, sec, secs, second, seconds` - will parse to seconds 2. `m, min, mins, minute, minutes` - will parse to minutes @@ -124,7 +124,7 @@ var time = (new Timestring(settings)).parse(str, 'h'); console.log(time); // will log 1 ``` -In the example of above `hoursPerDay` is being set to `1`. When the time string is being parsed, the return value is being specified as hours. Normally `1d` would parse to `24` hours (as by deafult there are 24 hours in a day) but because `hoursPerDay` has been set to `1`, `1d` will now only parse to `1` hour. +In the example above `hoursPerDay` is being set to `1`. When the time string is being parsed, the return value is being specified as hours. Normally `1d` would parse to `24` hours (as by deafult there are 24 hours in a day) but because `hoursPerDay` has been set to `1`, `1d` will now only parse to `1` hour. This would be useful for specific application needs. @@ -156,16 +156,16 @@ console.log(daysThisWeek); // will log 5 ##Installation -### Browser +###Browser All you need to do to get timestring working in the browser is download / clone this repo and make sure you include the `timestring.js` script on your page: ```html ``` -### Node.js +###Node -Timestring is also node compatible. To install for a project, navigate to the projects root folder and in your terminal and type the following: +To install for a node application, navigate to the projects root folder and in your terminal type the following: ``` npm install timestring @@ -173,10 +173,10 @@ npm install timestring You may need to use `sudo` if you get errors. -In your node application you need to require the timestirng module: +In your node application you need to require the timestring module: ```js var Timestring = require('timestring'); ``` -Once you have done this, you will beable to use timestring in node, the same way you do in the browser! +Once you have done this, you will be able to use timestring in your node application, the same way you do in the browser! diff --git a/package.json b/package.json index 2bc0410..d34ebf9 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "functional", "time" ], - "author" : "Mike Barrett ", + "author" : "Michael David Barrett ", "repository" : { "type": "git", "url": "git://github.com/mike182uk/timestring.git" }, "main" : "timestring.js", - "version" : "1.0.1" + "version" : "1.0.2" } diff --git a/timestring.js b/timestring.js index 06f18d4..fe53b7b 100644 --- a/timestring.js +++ b/timestring.js @@ -1,5 +1,4 @@ (function(){ - "use strict"; var Timestring = function(settings) { @@ -83,10 +82,11 @@ .match(/[-+]?[0-9]+[a-z]+/g); // match time groups (digit followed by time unit - i.e 5d 15m = 2 time groups) if (groups !== null) { - for( var i = 0; i < groups.length; i++ ) { - var g = groups[i], - value = g.match(/[0-9]+/g)[0], - unit = g.match(/[a-z]+/g)[0]; + for(var i = 0; i < groups.length; i++) { + var g = groups[i]; + var value = g.match(/[0-9]+/g)[0]; + var unit = g.match(/[a-z]+/g)[0]; + totalSeconds += getSeconds(value, unit); } } @@ -95,12 +95,12 @@ return (returnUnit) ? convert(totalSeconds, returnUnit) : totalSeconds; } - // add convenience method to string proto + // add convenience method to string prototype String.prototype.parseTime = function (unit, settings) { return (new Timestring(settings)).parse(this, unit); } - // export Timestring object for either the browser or node.js + // export Timestring object for either the browser or node if (typeof module !== 'undefined' && module.exports) { module.exports = Timestring; }