SocialvoidJS/socialvoid/deps.node.ts

27 lines
712 B
TypeScript
Raw Normal View History

2021-10-10 10:58:15 +02:00
import * as OTPAuth from "otpauth";
export { writeFileSync as writeTextFileSync } from "fs";
import { readFileSync } from "fs";
2021-10-10 12:07:13 +02:00
import { randomBytes } from "crypto";
import jsSHA from "jssha";
2021-10-10 14:00:20 +02:00
import fetch from "node-fetch";
2021-10-10 14:17:46 +02:00
import FormData from "form-data";
2021-10-10 14:00:20 +02:00
2021-11-18 13:01:55 +01:00
// @ts-ignore: Node-side error
2021-10-10 14:00:20 +02:00
globalThis.fetch = fetch;
2021-11-18 13:01:55 +01:00
// @ts-ignore: Node-side error
2021-10-10 14:17:46 +02:00
globalThis.FormData = FormData;
2021-10-10 10:58:15 +02:00
export const isBrowser = typeof window !== "undefined";
2021-10-10 12:07:13 +02:00
2021-10-10 14:40:45 +02:00
export const os = isBrowser ? "Browser" : process.platform;
2021-10-10 10:58:15 +02:00
export const readTextFileSync = (file: string) => {
2021-10-29 10:08:21 +02:00
return readFileSync(file).toString();
2021-10-10 10:58:15 +02:00
};
2021-10-10 12:07:13 +02:00
export const getRandomValues = (size: number) => {
2021-10-29 10:08:21 +02:00
return randomBytes(size).buffer;
2021-10-10 12:07:13 +02:00
};
2021-10-10 18:02:22 +02:00
export { jsSHA, OTPAuth };