2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-14 23:31:44 -04:00
|
|
|
function newNoteId() {
|
2017-10-28 12:12:20 -04:00
|
|
|
return randomString(12);
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
2017-10-28 12:12:20 -04:00
|
|
|
const ALPHA_NUMERIC = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
|
2017-10-28 13:19:12 -04:00
|
|
|
function randomString(length) {
|
2017-10-14 23:31:44 -04:00
|
|
|
let result = '';
|
|
|
|
|
|
|
|
for (let i = length; i > 0; --i) {
|
2017-10-28 12:12:20 -04:00
|
|
|
result += ALPHA_NUMERIC[Math.floor(Math.random() * ALPHA_NUMERIC.length)];
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function nowTimestamp() {
|
2017-10-15 17:07:34 -04:00
|
|
|
return Math.floor(Date.now() / 1000);
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function toBase64(plainText) {
|
|
|
|
return Buffer.from(plainText).toString('base64');
|
|
|
|
}
|
|
|
|
|
|
|
|
function fromBase64(encodedText) {
|
|
|
|
return Buffer.from(encodedText, 'base64');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-10-28 12:12:20 -04:00
|
|
|
randomString,
|
2017-10-14 23:31:44 -04:00
|
|
|
nowTimestamp,
|
|
|
|
newNoteId,
|
|
|
|
toBase64,
|
|
|
|
fromBase64
|
|
|
|
};
|