Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

cycles

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cycles - npm Package Compare versions

Comparing version
1.0.2
to
1.1.0
+17
-14
cli.js

@@ -7,17 +7,18 @@ #!/usr/bin/env node

var cli = meow({
help: [
'Usage',
' $ cycles',
' $ cycles <Bedtime>',
' $ cycles --wake <Time to wake up>',
'',
'Options',
' -w, --wake <Time to wake up>'
]
}, {
var cli = meow([
'Usage',
' $ cycles',
' $ cycles <Bedtime>',
' $ cycles --wake <Time to wake up>',
'',
'Options',
' -d, --duration <Cycle duration>',
' -w, --wake <Time to wake up>'
], {
string: [
'duration',
'wake'
],
alias: {
d: 'duration',
w: 'wake'

@@ -27,2 +28,4 @@ }

var duration = parseInt(cli.flags.duration, 10) || 90;
function log(obj, str, reverse) {

@@ -42,6 +45,6 @@ var arr = Object.keys(obj).map(function (el) {

if (cli.flags.wake) {
log(cycles.wake(cli.flags.wake), 'Fall asleep at a certain time to feel more refreshed in the morning.', true);
return;
log(cycles.wake(cli.flags.wake, {duration: duration}), 'Fall asleep at a certain time to feel more refreshed in the morning.', true);
process.exit();
}
log(cycles.sleep(cli.input[0] || ''), 'Wake up at the end of a cycle to feel more refreshed in the morning.');
log(cycles.sleep(cli.input[0] || '', {duration: duration}), 'Wake up at the end of a cycle to feel more refreshed in the morning.');
'use strict';
var inRange = require('in-range');
var objectAssign = require('object-assign');
module.exports.sleep = function (str) {
module.exports.sleep = function (str, opts) {
if (typeof str === 'object') {
opts = str;
str = '';
}
var arr = String(str).split(':');

@@ -9,2 +15,8 @@ var date = new Date();

opts = objectAssign({duration: 90}, opts);
if (typeof opts.duration !== 'number') {
throw new TypeError('Expected a number as duration');
}
if (arr.length > 1 && inRange(parseInt(arr[0], 10), 23) && inRange(parseInt(arr[1], 10), 59)) {

@@ -14,6 +26,6 @@ date.setHours(arr[0], arr[1], 0);

date.setMinutes(date.getMinutes() + 90);
date.setMinutes(date.getMinutes() + opts.duration);
for (var i = 2; i < 8; i++) {
date.setMinutes(date.getMinutes() + 90);
date.setMinutes(date.getMinutes() + opts.duration);
ret[i] = date.toString().match(/\d{2}:\d{2}/)[0];

@@ -25,3 +37,3 @@ }

module.exports.wake = function (str) {
module.exports.wake = function (str, opts) {
var arr = String(str).split(':');

@@ -31,2 +43,8 @@ var date = new Date();

opts = objectAssign({duration: 90}, opts);
if (typeof opts.duration !== 'number') {
throw new TypeError('Expected a number as duration');
}
if (arr.length < 2 || !inRange(parseInt(arr[0], 10), 23) || !inRange(parseInt(arr[1], 10), 59)) {

@@ -36,6 +54,6 @@ throw new Error('Expected a 24 hour clock string');

date.setHours(arr[0], arr[1] - 90, 0);
date.setHours(arr[0], arr[1] - opts.duration, 0);
for (var i = 2; i < 8; i++) {
date.setMinutes(date.getMinutes() - 90);
date.setMinutes(date.getMinutes() - opts.duration);
ret[i] = date.toString().match(/\d{2}:\d{2}/)[0];

@@ -42,0 +60,0 @@ }

{
"name": "cycles",
"version": "1.0.2",
"version": "1.1.0",
"description": "Calculate sleep cycles to wake up more refreshed.",

@@ -17,3 +17,3 @@ "license": "MIT",

"scripts": {
"test": "xo && mocha"
"test": "xo && ava"
},

@@ -40,8 +40,9 @@ "files": [

"in-range": "^1.0.0",
"meow": "^3.3.0"
"meow": "^3.3.0",
"object-assign": "^4.0.1"
},
"devDependencies": {
"mocha": "^2.2.5",
"xo": "^0.5.2"
"ava": "*",
"xo": "*"
}
}

@@ -29,2 +29,3 @@ # cycles [![Build Status](https://travis-ci.org/gillstrom/cycles.svg?branch=master)](https://travis-ci.org/gillstrom/cycles)

Options
-d, --duration <Cycle duration>
-w, --wake <Time to wake up>

@@ -62,2 +63,14 @@ ```

*/
cycles.wake('06:55', {duration: 60});
/*
{
2: '04:55',
3: '03:55',
4: '02:55',
5: '01:55',
6: '00:55',
7: '23:55'
}
*/
```

@@ -68,3 +81,3 @@

### cycles.sleep([time])
### cycles.sleep([time], [opts])

@@ -76,6 +89,19 @@ #### time

Returns an object with times for 2 to 7 sleep cycles.
Returns an object with times to wake up for 2 to 7 sleep cycles.
### cycles.wake(times)
#### opts
Type: `object`
Options to pass to the function
##### opts.duration
Type: `number`
Default: `90`
Set the cycle duration.
### cycles.wake(times, [opts])
#### time

@@ -86,7 +112,20 @@

Returns an object with times for 2 to 7 sleep cycles.
Returns an object with times to fall asleep for 2 to 7 sleep cycles.
#### opts
Type: `object`
Options to pass to the function
##### opts.duration
Type: `number`
Default: `90`
Set the cycle duration.
## License
MIT © [Andreas Gillström](http://github.com/gillstrom)