Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download web/app/utils/bag.ts from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/web/app/utils/bag.ts
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/web/app/utils/bag.ts
-
curl -L -o bag.ts https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/web/app/utils/bag.ts
1.31 kB
| export default class Bag<T> { | |
| private items = new Map<string, Array<T>>() | |
| serialize(): Record<string, Array<T>> { | |
| const result: Record<string, Array<T>> = {} | |
| this.items.forEach((value: T[], key) => { | |
| result[key] = value | |
| }) | |
| return result | |
| } | |
| static fromObject<T>(items: Record<string, Array<T>>): Bag<T> { | |
| const result = new Bag<T>() | |
| Object.entries(items).forEach(([key, values]) => { | |
| result.addMany(key, values) | |
| }) | |
| return result | |
| } | |
| add(key: string, value: T): this { | |
| let messages: Array<T> | undefined = this.items.get(key) | |
| if (messages === undefined) { | |
| messages = [] | |
| } | |
| if (!messages.includes(value)) { | |
| messages.push(value) | |
| } | |
| this.items.set(key, messages) | |
| return this | |
| } | |
| addMany(key: string, values: Array<T>): this { | |
| values.forEach((value: T) => { | |
| this.add(key, value) | |
| }) | |
| return this | |
| } | |
| has(key: string): boolean { | |
| return this.items.has(key) | |
| } | |
| first(key: string): T | undefined { | |
| if (this.has(key)) { | |
| return this.get(key)[0] ?? undefined | |
| } | |
| return undefined | |
| } | |
| get(key: string): Array<T> { | |
| const result = this.items.get(key) | |
| if (result === undefined) { | |
| return [] | |
| } | |
| return result | |
| } | |
| size(): number { | |
| return this.items.size | |
| } | |
| } | |