forked from freeall/currency-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (55 loc) · 1.32 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
var first = require('first-match');
var nub = require('nub');
var data = require('./data');
var publishDate = require('./iso-4217-publish-date');
var code = function(code) {
code = code.toUpperCase();
return first(data, function(c) {
return c.code === code;
});
};
var country = function(country) {
country = country.toLowerCase();
return data.filter(function(c) {
return (c.countries.map(function(c) { return c.toLowerCase(); } ) || []).indexOf(country) > -1;
});
};
var number = function(number) {
return first(data, function(c) {
return c.number === String(number);
});
};
var codes = function() {
return data.map(function(c) {
return c.code;
});
};
var numbers = function() {
var items = data.map(function(c) {
return c.number;
});
// handle cases where number is undefined (e.g. XFU and XBT)
return items.filter(function(n) {
if (n) {
return n;
}
});
};
var countries = function() {
var m = data
.filter(function(c) {
return c.countries;
})
.map(function(c) {
return c.countries;
});
return nub(Array.prototype.concat.apply([], m));
};
exports.code = code;
exports.country = country;
exports.number = number;
exports.codes = codes;
exports.numbers = numbers;
exports.countries = countries;
exports.publishDate = publishDate;
exports.data = data;