Files
Andrew Naylor 6f5e14bcb6 Remove token length constraints
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
2016-08-09 21:31:11 +01:00

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;