1 | 1 | 'use strict'; |
2 | | |
3 | | // ----- dependencies |
4 | | // --------------------------------------- |
5 | 1 | var card = require('s-valid').card; |
6 | | |
7 | | |
8 | | // ----- exported function |
9 | | // --------------------------------------- |
10 | 1 | module.exports = function creditcard(input) { |
11 | | |
12 | 27 | if (typeof input !== 'string') { |
13 | 2 | throw(new TypeError('Card input must be a string')); |
14 | | } |
15 | | |
16 | 25 | for (var type in card) { |
17 | 156 | if (card.hasOwnProperty(type) && type !== 'generic') { |
18 | 153 | if (card[type](input)) { |
19 | 22 | return type; |
20 | | } |
21 | | } |
22 | | } |
23 | | |
24 | 3 | if (card.generic(input)) { |
25 | 1 | return 'other'; |
26 | | } |
27 | | |
28 | 2 | return 'none'; |
29 | | |
30 | | }; |