mirror of
https://github.com/expo/node-apn.git
synced 2026-11-15 08:58:07 -10:00
It was announced at WWDC 2015 (Session 720) that large device tokens are coming soon: > Let's look at what's ahead. Coming next year are large device tokens. Device > tokens today are 32 bytes. > > And next year, in 2016, they may be growing up to 100 bytes. So if you make > any assumptions about the size of device tokens in your code, or in your > server APIs, now is a good time to revisit those assumptions. Large device > tokens coming in 2016. Thanks for the reminder @maccheck
26 lines
466 B
JavaScript
26 lines
466 B
JavaScript
"use strict";
|
|
/**
|
|
* 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;
|