Skip to content

Commit

Permalink
flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
davay42 committed Jan 24, 2023
1 parent 8896a1b commit 134148a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
5 changes: 2 additions & 3 deletions docs/.vitepress/composables/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { reactive, computed, toRef, onMounted } from "vue";
import { useRefHistory } from '@vueuse/core'
import { useRefHistory, useIntervalFn } from '@vueuse/core'


export const state = reactive({
Expand All @@ -22,7 +22,6 @@ export const state = reactive({
loop: 0,
setPair(pair) {
state.pair = pair
clearInterval(state.loop)
}
})

Expand All @@ -38,7 +37,7 @@ export function useState() {
})
})
onMounted(() => {
state.loop = setInterval(() => {
state.loop = useIntervalFn(() => {
state.generatePair()
}, 2000)
})
Expand Down
41 changes: 19 additions & 22 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


const cache = {}; // stores already generated avatars

export interface AvatarOptions {
Expand Down Expand Up @@ -63,7 +61,7 @@ export function gunAvatar({

// FUNCTIONS

function parsePub(pub: string) {
export function parsePub(pub: string) {
const split = pub.split(".");
const decoded = split.map((single) => decodeUrlSafeBase64(single));
return {
Expand All @@ -73,7 +71,7 @@ function parsePub(pub: string) {
}
}

function validatePub(pub: string): boolean {
export function validatePub(pub: string): boolean {
if (
pub
&& typeof pub == 'string'
Expand All @@ -86,6 +84,23 @@ function validatePub(pub: string): boolean {
}
}

export function decodeUrlSafeBase64(st: string): number[] {
const symbols =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
const symbolArray = symbols.split("");
let arr = [];
let i = 0;
for (let letter of st) {
arr[i++] = symbolArray.indexOf(letter) / 64;
}
return arr;
}

export function chunkIt(list: number[], chunkSize = 3) {
return [...Array(Math.ceil(list.length / chunkSize))].map(() =>
list.splice(0, chunkSize)
);
}

function drawGradient(
{
Expand Down Expand Up @@ -166,22 +181,4 @@ function drawCircles(data: number[], ctx: CanvasRenderingContext2D, size: number
ctx.fill();
}
});
}

function decodeUrlSafeBase64(st: string): number[] {
const symbols =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
const symbolArray = symbols.split("");
let arr = [];
let i = 0;
for (let letter of st) {
arr[i++] = symbolArray.indexOf(letter) / 64;
}
return arr;
}

function chunkIt(list: number[], chunkSize = 3) {
return [...Array(Math.ceil(list.length / chunkSize))].map(() =>
list.splice(0, chunkSize)
);
}

0 comments on commit 134148a

Please sign in to comment.