convert const function to function
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
// get X days ago with user provided date
|
||||
export const daysAgo = (numOfDays, date = new Date()) => {
|
||||
export function daysAgo(numOfDays, date = new Date()) {
|
||||
const daysAgo = new Date(date.getTime());
|
||||
daysAgo.setDate(date.getDate() - numOfDays);
|
||||
|
||||
return daysAgo;
|
||||
};
|
||||
}
|
||||
|
||||
// get X hours ago with user provided date
|
||||
export const hoursAgo = (numOfHours, date = new Date()) => {
|
||||
export function hoursAgo(numOfHours, date = new Date()) {
|
||||
const hoursAgo = new Date(date.getTime());
|
||||
hoursAgo.setHours(date.getHours() - numOfHours);
|
||||
|
||||
return hoursAgo;
|
||||
};
|
||||
}
|
||||
|
||||
// convert date to unix timestamp
|
||||
export const dateToUnix = (_date?: Date) => {
|
||||
export function dateToUnix(_date?: Date) {
|
||||
const date = _date || new Date();
|
||||
|
||||
return Math.floor(date.getTime() / 1000);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import useSWR from 'swr';
|
||||
|
||||
const fetcher = () => getActiveAccount();
|
||||
|
||||
export const useActiveAccount = () => {
|
||||
export function useActiveAccount() {
|
||||
const { data, error, isLoading } = useSWR('activeAcount', fetcher);
|
||||
|
||||
return {
|
||||
@@ -12,4 +12,4 @@ export const useActiveAccount = () => {
|
||||
isLoading,
|
||||
isError: error,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const fetcher = async ([, id]) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const useChannelProfile = (id: string, channelPubkey: string) => {
|
||||
export function useChannelProfile(id: string, channelPubkey: string) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const { data: cache, isLoading } = useSWR(['channel-cache-profile', id], fetcher);
|
||||
@@ -53,4 +53,4 @@ export const useChannelProfile = (id: string, channelPubkey: string) => {
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { nip04 } from 'nostr-tools';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
export const useDecryptMessage = (userKey: string, userPriv: string, data: any) => {
|
||||
export function useDecryptMessage(userKey: string, userPriv: string, data: any) {
|
||||
const [content, setContent] = useState(null);
|
||||
|
||||
const extractSenderKey = useCallback(() => {
|
||||
@@ -25,4 +25,4 @@ export const useDecryptMessage = (userKey: string, userPriv: string, data: any)
|
||||
}, [decrypt]);
|
||||
|
||||
return content ? content : null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
|
||||
const getOnLineStatus = () =>
|
||||
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
|
||||
|
||||
export const useNetworkStatus = () => {
|
||||
export function useNetworkStatus() {
|
||||
const [status, setStatus] = useState(getOnLineStatus());
|
||||
|
||||
const setOnline = () => setStatus(true);
|
||||
@@ -20,4 +20,4 @@ export const useNetworkStatus = () => {
|
||||
}, []);
|
||||
|
||||
return status;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const fetcher = async (pubkey: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const useProfile = (pubkey: string) => {
|
||||
export function useProfile(pubkey: string) {
|
||||
const { data, error, isLoading } = useSWR(pubkey, fetcher);
|
||||
|
||||
return {
|
||||
@@ -30,4 +30,4 @@ export const useProfile = (pubkey: string) => {
|
||||
isLoading,
|
||||
isError: error,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const getURLs = new RegExp(
|
||||
'gmi'
|
||||
);
|
||||
|
||||
export const noteParser = (event: Event) => {
|
||||
export function noteParser(event: Event) {
|
||||
const references = parseReferences(event);
|
||||
const content: { original: string; parsed: any; notes: string[]; images: string[]; videos: string[] } = {
|
||||
original: event.content,
|
||||
@@ -54,4 +54,4 @@ export const noteParser = (event: Event) => {
|
||||
});
|
||||
|
||||
return content;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
export const shortenKey = (pubkey: string) => {
|
||||
export function shortenKey(pubkey: string) {
|
||||
const npub = nip19.npubEncode(pubkey);
|
||||
return npub.substring(0, 16).concat('...');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import destr from 'destr';
|
||||
|
||||
// convert NIP-02 to array of pubkey
|
||||
export const nip02ToArray = (tags: any) => {
|
||||
export function nip02ToArray(tags: any) {
|
||||
const arr = [];
|
||||
tags.forEach((item) => {
|
||||
arr.push(item[1]);
|
||||
});
|
||||
|
||||
return arr;
|
||||
};
|
||||
}
|
||||
|
||||
// convert array to NIP-02 tag list
|
||||
export const arrayToNIP02 = (arr: string[]) => {
|
||||
export function arrayToNIP02(arr: string[]) {
|
||||
const nip02_arr = [];
|
||||
arr.forEach((item) => {
|
||||
nip02_arr.push(['p', item]);
|
||||
});
|
||||
|
||||
return nip02_arr;
|
||||
};
|
||||
}
|
||||
|
||||
// convert array object to pure array
|
||||
export const arrayObjToPureArr = (arr: any) => {
|
||||
export function arrayObjToPureArr(arr: any) {
|
||||
const pure_arr = [];
|
||||
arr.forEach((item) => {
|
||||
pure_arr.push(item.content);
|
||||
});
|
||||
|
||||
return pure_arr;
|
||||
};
|
||||
}
|
||||
|
||||
// get parent id from event tags
|
||||
export const getParentID = (arr: string[], fallback: string) => {
|
||||
export function getParentID(arr: string[], fallback: string) {
|
||||
const tags = destr(arr);
|
||||
let parentID = fallback;
|
||||
|
||||
@@ -48,10 +48,10 @@ export const getParentID = (arr: string[], fallback: string) => {
|
||||
}
|
||||
|
||||
return parentID;
|
||||
};
|
||||
}
|
||||
|
||||
// check id present in event tags
|
||||
export const isTagsIncludeID = (id: string, arr: string[]) => {
|
||||
export function isTagsIncludeID(id: string, arr: string[]) {
|
||||
const tags = destr(arr);
|
||||
|
||||
if (tags.length > 0) {
|
||||
@@ -61,10 +61,10 @@ export const isTagsIncludeID = (id: string, arr: string[]) => {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// get parent id from event tags
|
||||
export const getQuoteID = (arr: string[]) => {
|
||||
export function getQuoteID(arr: string[]) {
|
||||
const tags = destr(arr);
|
||||
let quoteID = null;
|
||||
|
||||
@@ -81,13 +81,13 @@ export const getQuoteID = (arr: string[]) => {
|
||||
}
|
||||
|
||||
return quoteID;
|
||||
};
|
||||
}
|
||||
|
||||
// sort events by timestamp
|
||||
export const sortEvents = (arr: any) => {
|
||||
export function sortEvents(arr: any) {
|
||||
arr.sort((a, b) => {
|
||||
return a.created_at - b.created_at;
|
||||
});
|
||||
|
||||
return arr;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user