@parse/node-apn
Version:
An interface to the Apple Push Notification service for Node.js
25 lines (19 loc) • 450 B
JavaScript
/**
* Validates a device token
*
* Will convert to string and removes invalid characters as required.
*/
function token(input) {
let token;
if (typeof input === 'string') {
token = input;
} else if (Buffer.isBuffer(input)) {
token = input.toString('hex');
}
token = token.replace(/[^0-9a-f]/gi, '');
if (token.length === 0) {
throw new Error('Token has invalid length');
}
return token;
}
module.exports = token;