-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (34 loc) · 776 Bytes
/
index.js
File metadata and controls
38 lines (34 loc) · 776 Bytes
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
/**
* month <https://github.com/jonschlinkert/month>
*
* Copyright (c) 2015 Jon Schlinkert.
* Licensed under the MIT license.
*/
var repeat = require('repeat-string');
var isNumber = require('is-number');
var months = require('months');
module.exports = function month(val) {
var mo = new Date().getMonth();
if (typeof val === 'undefined') {
return mo;
}
// moment conventions
if (typeof val === 'string') {
if (val === 'M') {
return mo;
}
if (val === 'MM') {
return repeat('0', 2 - String(mo).length) + mo;
}
if (val === 'MMM') {
return months.abbr[mo];
}
if (val === 'MMMM') {
return months[mo];
}
}
if (isNumber(+val)) {
return months[val - 1];
}
return months.indexOf(val) + 1;
};