-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (53 loc) · 1.74 KB
/
index.js
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
'use strict';
module.exports = function (inp, opts) {
if (Object.prototype.toString.call(inp) === '[object Object]') {
opts = inp;
inp = undefined;
}
if (inp !== undefined && Object.prototype.toString.call(inp) !== '[object Date]' && typeof inp !== 'number') {
return new TypeError('Expected a date object or a number');
}
if (typeof inp === 'number' && (inp < 0 || inp > 6)) {
return new RangeError('Expected the value of inp between 0-6');
}
opts = opts || {};
var data = {};
data.ne = {
full: ['आइतबार', 'सोमबार', 'मंगलबार', 'बुधबार', 'बिहिबार', 'शुक्रबार', 'शनिबार'],
short: ['आइत', 'सोम', 'मंगल', 'बुध', 'बिहि', 'शुक्र', 'शनि'],
min: ['आ', 'सो', 'मं', 'बु', 'बि', 'शु', 'श']
};
data.en = {
full: ['Aaitabaar', 'Sombaar', 'Mangalbaar', 'Budhabaar', 'Bihibaar', 'Shukrabaar', 'Shanibaar'],
short: ['Aaita', 'Som', 'Mangal', 'Budha', 'Bihi', 'Shukra', 'Shani'],
min: ['Aai', 'So', 'Man', 'Bu', 'Bi', 'Shu', 'Sha']
};
var lang = 'ne';
if (opts.lang === 'en') {
lang = 'en';
}
if (inp === undefined) {
inp = new Date().getDay();
}
if (Object.prototype.toString.call(inp) === '[object Date]') {
inp = inp.getDay();
}
if (!opts.type) {
var nepday = {
full: data[lang].full[inp],
short: data[lang].short[inp],
min: data[lang].min[inp]
};
return nepday;
}
switch (opts.type) {
case 'short':
return data[lang].short[inp];
case 'min':
return data[lang].min[inp];
default:
return data[lang].full[inp];
}
// should never be here :D
return null;
};