lovely. got a couple of partial implementations....
update git ignore kaas remove large file syncy sync
This commit is contained in:
parent
89f526e9d9
commit
98cd4d630c
24 changed files with 586 additions and 76 deletions
|
@ -1,15 +1,46 @@
|
|||
export const splitAt = (subject: string, index: number): readonly [string, string] => {
|
||||
if (index < 0) {
|
||||
return [subject, ''];
|
||||
}
|
||||
import { Accessor, createEffect, createSignal, on } from "solid-js";
|
||||
|
||||
if (index > subject.length) {
|
||||
return [subject, ''];
|
||||
}
|
||||
export const splitAt = (
|
||||
subject: string,
|
||||
index: number,
|
||||
): readonly [string, string] => {
|
||||
if (index < 0) {
|
||||
return [subject, ""];
|
||||
}
|
||||
|
||||
return [subject.slice(0, index), subject.slice(index + 1)];
|
||||
if (index > subject.length) {
|
||||
return [subject, ""];
|
||||
}
|
||||
|
||||
return [subject.slice(0, index), subject.slice(index + 1)];
|
||||
};
|
||||
|
||||
export const toSlug = (subject: string) => {
|
||||
return subject.toLowerCase().replaceAll(' ', '-');
|
||||
};
|
||||
export const toSlug = (subject: string) =>
|
||||
subject.toLowerCase().replaceAll(" ", "-");
|
||||
export const toHex = (subject: number) => subject.toString(16).padStart(2, "0");
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
export const hash = (
|
||||
algorithm: AlgorithmIdentifier,
|
||||
subject: Accessor<string | null | undefined>,
|
||||
) => {
|
||||
const [hash, setHash] = createSignal<string>();
|
||||
|
||||
createEffect(
|
||||
on(subject, async (subject) => {
|
||||
if (subject === null || subject === undefined || subject.length === 0) {
|
||||
setHash(undefined);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const buffer = new Uint8Array(
|
||||
await crypto.subtle.digest(algorithm, encoder.encode(subject)),
|
||||
);
|
||||
|
||||
setHash(Array.from(buffer).map(toHex).join(""));
|
||||
}),
|
||||
);
|
||||
|
||||
return hash;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue