|
1 | 1 | import base64url from 'base64url'
|
2 | 2 |
|
3 |
| -let uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i |
| 3 | +const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i |
4 | 4 |
|
5 | 5 | export function checkNoteIdValid (id) {
|
6 |
| - let result = id.match(uuidRegex) |
7 |
| - if (result && result.length === 1) { |
8 |
| - return true |
9 |
| - } else { |
10 |
| - return false |
11 |
| - } |
| 6 | + const result = id.match(uuidRegex) |
| 7 | + return !!(result && result.length === 1) |
12 | 8 | }
|
13 | 9 |
|
14 | 10 | export function encodeNoteId (id) {
|
15 | 11 | // remove dashes in UUID and encode in url-safe base64
|
16 |
| - let str = id.replace(/-/g, '') |
17 |
| - let hexStr = Buffer.from(str, 'hex') |
| 12 | + const str = id.replace(/-/g, '') |
| 13 | + const hexStr = Buffer.from(str, 'hex') |
18 | 14 | return base64url.encode(hexStr)
|
19 | 15 | }
|
20 | 16 |
|
21 | 17 | export function decodeNoteId (encodedId) {
|
22 | 18 | // decode from url-safe base64
|
23 |
| - let id = base64url.toBuffer(encodedId).toString('hex') |
| 19 | + const id = base64url.toBuffer(encodedId).toString('hex') |
24 | 20 | // add dashes between the UUID string parts
|
25 |
| - let idParts = [] |
| 21 | + const idParts = [] |
26 | 22 | idParts.push(id.substr(0, 8))
|
27 | 23 | idParts.push(id.substr(8, 4))
|
28 | 24 | idParts.push(id.substr(12, 4))
|
|
0 commit comments