Spaces:
Runtime error
Runtime error
machineuser
commited on
Commit
•
5556095
1
Parent(s):
8b20a2e
Sync widgets demo
Browse files- shared/package.json +8 -0
- shared/pnpm-lock.yaml +5 -0
- shared/src/base64FromBytes.ts +11 -0
- shared/src/index.ts +3 -0
- shared/src/isBackend.ts +6 -0
- shared/src/isFrontend.ts +3 -0
- shared/tsconfig.json +14 -0
shared/package.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@huggingface/shared",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"private": true,
|
5 |
+
"main": "src/index.ts",
|
6 |
+
"source": "src/index.ts",
|
7 |
+
"types": "./src/index.ts"
|
8 |
+
}
|
shared/pnpm-lock.yaml
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
lockfileVersion: '6.0'
|
2 |
+
|
3 |
+
settings:
|
4 |
+
autoInstallPeers: true
|
5 |
+
excludeLinksFromLockfile: false
|
shared/src/base64FromBytes.ts
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export function base64FromBytes(arr: Uint8Array): string {
|
2 |
+
if (globalThis.Buffer) {
|
3 |
+
return globalThis.Buffer.from(arr).toString("base64");
|
4 |
+
} else {
|
5 |
+
const bin: string[] = [];
|
6 |
+
arr.forEach((byte) => {
|
7 |
+
bin.push(String.fromCharCode(byte));
|
8 |
+
});
|
9 |
+
return globalThis.btoa(bin.join(""));
|
10 |
+
}
|
11 |
+
}
|
shared/src/index.ts
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
export * from './base64FromBytes';
|
2 |
+
export * from './isBackend';
|
3 |
+
export * from './isFrontend';
|
shared/src/isBackend.ts
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
2 |
+
|
3 |
+
const isWebWorker =
|
4 |
+
typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
|
5 |
+
|
6 |
+
export const isBackend = !isBrowser && !isWebWorker;
|
shared/src/isFrontend.ts
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import { isBackend } from "./isBackend";
|
2 |
+
|
3 |
+
export const isFrontend = !isBackend;
|
shared/tsconfig.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"compilerOptions": {
|
3 |
+
"esModuleInterop": true,
|
4 |
+
"noEmit": false,
|
5 |
+
"module": "ESNext",
|
6 |
+
"target": "ESNext",
|
7 |
+
"moduleResolution": "Node",
|
8 |
+
"noImplicitAny": true,
|
9 |
+
"strict": true,
|
10 |
+
"strictNullChecks": true,
|
11 |
+
"skipLibCheck": true,
|
12 |
+
"composite": true
|
13 |
+
}
|
14 |
+
}
|