1 |
|
2 | module.exports.isUuid = function (uuid) {
|
3 | if (!uuid) return false;
|
4 | uuid = uuid.toString().toLowerCase();
|
5 | return /[0-9a-f]{8}\-?[0-9a-f]{4}\-?4[0-9a-f]{3}\-?[89ab][0-9a-f]{3}\-?[0-9a-f]{12}/.test(uuid)
|
6 | }
|
7 |
|
8 |
|
9 | module.exports.isCookieCid = function (cid) {
|
10 | return /^[0-9]+\.[0-9]+$/.test(cid)
|
11 | }
|
12 |
|
13 |
|
14 | module.exports.ensureValidCid = function (uuid) {
|
15 | if (!this.isUuid(uuid)) {
|
16 | if (!this.isCookieCid(uuid)) {
|
17 | return false;
|
18 | }
|
19 | return uuid;
|
20 | }
|
21 |
|
22 | uuid = uuid.replace(/\-/g, "");
|
23 | return "" +
|
24 | uuid.substring(0, 8) + "-" +
|
25 | uuid.substring(8, 12) + "-" +
|
26 | uuid.substring(12, 16) + "-" +
|
27 | uuid.substring(16, 20) + "-" +
|
28 | uuid.substring(20);
|
29 | }
|