* Validates a device token * * Will convert to string and removes invalid characters as required.
(input)
| 5 | * Will convert to string and removes invalid characters as required. |
| 6 | */ |
| 7 | function token(input) { |
| 8 | let token; |
| 9 | |
| 10 | if (typeof input === "string") { |
| 11 | token = input; |
| 12 | } else if (Buffer.isBuffer(input)) { |
| 13 | token = input.toString("hex"); |
| 14 | } |
| 15 | |
| 16 | token = token.replace(/[^0-9a-f]/gi, ""); |
| 17 | |
| 18 | if (token.length === 0) { |
| 19 | throw new Error("Token has invalid length"); |
| 20 | } |
| 21 | |
| 22 | return token; |
| 23 | } |
| 24 | |
| 25 | module.exports = token; |
no outgoing calls
no test coverage detected
searching dependent graphs…