forked from github-tools/github-release-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
120 lines (107 loc) · 2.48 KB
/
utils.js
File metadata and controls
120 lines (107 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
var chalk = require('chalk');
/**
* Print a task name in a custom format
*
* @since 0.5.0
* @public
*
* @param {string} name The name of the task
*/
function printTask(name) {
process.stdout.write(chalk.blue(name + ' task:\n===================================\n'));
}
/**
* Outputs the task status
*
* @since 0.5.0
* @public
*
* @param {string} taskName The task name
*
* @return {Function} The function to be fired when is loaded
*/
function task(taskName) {
var time = process.hrtime();
process.stdout.write(chalk.green(taskName) + ': .');
var si = setInterval(function() {
process.stdout.write('.');
}, 100);
return function(message) {
var diff = process.hrtime(time);
process.stdout.write(message || '' + chalk.yellow(' (' + ((diff[0] * 1e9 + diff[1]) * 1e-9).toFixed(2) + ' secs)\n'));
clearInterval(si);
};
}
/**
* Check if e value is between a min and a max
*
* @since 0.5.0
* @public
*
* @param {number} value
* @param {number} min
* @param {number} max
*
* @return {Boolean}
*/
function isInRange(value, min, max) {
return !Math.floor((value - min) / (max - min));
}
/**
* Transforms a dasherize string into a camel case one.
*
* @since 0.3.2
* @public
*
* @param {string} value The dasherize string
*
* @return {string} The camel case string
*/
function dashToCamelCase(value) {
return value
.toLowerCase()
.replace(/-([a-z])/g, function(match) {
return match[1].toUpperCase();
});
}
/**
* Create a literal object of the node module options
*
* @since 0.1.0
* @public
*
* @param {Array} args The array of arguments (the module arguments start from index 2)
*
* @return {Object} The object containg the key/value options
*/
function getBashOptions(args) {
var settings = {};
for (var i = 2; i < args.length; i++) {
var paramArray = args[i].split('=');
var key = paramArray[0].replace('--', '');
var value = paramArray[1];
settings[dashToCamelCase(key)] = value || true;
}
return settings;
}
/**
* Format a date into a string
*
* @since 0.5.0
* @public
*
* @param {Date} date
* @return {string}
*/
function formatDate(date) {
return ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear();
}
module.exports = {
printTask: printTask,
task: task,
getBashOptions: getBashOptions,
dashToCamelCase: dashToCamelCase,
isInRange: isInRange,
formatDate: formatDate
};