/**
* Generates a simple WHERE clause for TypeORM based on query and fields.
*
* @template T - The entity type.
* @param {string} query - The search query.
* @param {string} fields - A comma-separated list of fields to search in.
* @param {FindOptionsWhere<T>} [defaultWhere={}] - Default WHERE conditions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const getCardType = (num) => { | |
| let type = 'unknow'; | |
| if (num.match('^3[47]\\d{0,13}')) { | |
| type = 'amex'; | |
| } else if (num.match('^(?:6011|65\\d{0,2}|64[4-9]\\d?)\\d{0,12}')) { | |
| type = 'discover'; | |
| } else if (num.match('^3(?:0([0-5]|9)|[689]\\d?)\\d{0,11}')) { | |
| type = 'diners'; | |
| } else if (num.match('^(5[1-5]\\d{0,2}|22[2-9]\\d{0,1}|2[3-7]\\d{0,2})\\d{0,12}')) { | |
| type = 'mastercard'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const validateCard = ((arr) => { | |
| return (num) => { | |
| let len = num.length; | |
| let bit = 1; | |
| let sum = 0; | |
| let val; | |
| while (len) { | |
| val = parseInt(num.charAt(--len), 10); | |
| // eslint-disable-next-line no-bitwise,no-cond-assign | |
| sum += (bit ^= 1) ? arr[val] : val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Luhn = { | |
| // length of our number (check digit included) | |
| length: 10, | |
| pow2: [0, 2, 4, 6, 8, 1, 3, 5, 7, 9], | |
| // compute check digit | |
| checksum: function (x) { | |
| var sum = 0; | |
| var n; | |
| var odd = false; | |
| for (var i = x.length - 1; i >= 0; --i) { |
OlderNewer