refactoring on session generator

This commit is contained in:
goenning 2023-05-11 14:19:18 +01:00
parent f2ad54efd5
commit 47d063b181
4 changed files with 17 additions and 9 deletions

View file

@ -1,3 +1,7 @@
## 0.1.1
- Refactor on session generator
## 0.1.0
- Move to Rollup 3

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "@aptabase/web",
"version": "0.1.0",
"version": "0.1.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@aptabase/web",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-replace": "5.0.2",

View file

@ -1,6 +1,6 @@
{
"name": "@aptabase/web",
"version": "0.1.0",
"version": "0.1.1",
"private": false,
"type": "module",
"description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",

View file

@ -1,16 +1,20 @@
export function newSessionId() {
if (typeof crypto !== "undefined" && crypto && window.crypto.randomUUID) {
return window.crypto.randomUUID();
if (typeof crypto !== "undefined" && crypto && crypto.randomUUID) {
return crypto.randomUUID();
}
return `${randomString(8)}-${randomString(4)}-${randomString(
4
)}-${randomString(4)}-${randomString(12)}`;
return [
randomStr(8),
randomStr(4),
randomStr(4),
randomStr(4),
randomStr(12),
].join("-");
}
const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
function randomString(len: number) {
function randomStr(len: number) {
let result = "";
for (let i = 0; i < len; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));