refactor: fix lint on public/js/utils.js

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2019-08-04 23:26:17 +08:00
parent fffefcc5f8
commit 4a9b6ceca9
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
1 changed files with 7 additions and 11 deletions

View File

@ -1,28 +1,24 @@
import base64url from 'base64url'
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
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
export function checkNoteIdValid (id) {
let result = id.match(uuidRegex)
if (result && result.length === 1) {
return true
} else {
return false
}
const result = id.match(uuidRegex)
return !!(result && result.length === 1)
}
export function encodeNoteId (id) {
// remove dashes in UUID and encode in url-safe base64
let str = id.replace(/-/g, '')
let hexStr = Buffer.from(str, 'hex')
const str = id.replace(/-/g, '')
const hexStr = Buffer.from(str, 'hex')
return base64url.encode(hexStr)
}
export function decodeNoteId (encodedId) {
// decode from url-safe base64
let id = base64url.toBuffer(encodedId).toString('hex')
const id = base64url.toBuffer(encodedId).toString('hex')
// add dashes between the UUID string parts
let idParts = []
const idParts = []
idParts.push(id.substr(0, 8))
idParts.push(id.substr(8, 4))
idParts.push(id.substr(12, 4))