Download src/utils/users.js from Thrisha04/Chat: direct link, hf CLI and curl.
- Browser
- Download file 999 Bytes
-
https://huggingface.co/Thrisha04/Chat/resolve/main/src/utils/users.js
- Command line
-
hf download hf://Thrisha04/Chat/src/utils/users.js
-
curl -L -o users.js https://huggingface.co/Thrisha04/Chat/resolve/main/src/utils/users.js
999 Bytes
| const users = []; | |
| const addUser = ({ id, username, room }) => { | |
| username = username.trim().toLowerCase(); | |
| room = room.trim().toLowerCase(); | |
| if (!username || !room) { | |
| return { | |
| error: "Username and room are required!" | |
| }; | |
| } | |
| const existingUser = users.find(user => { | |
| return user.room === room && user.username === username; | |
| }); | |
| if (existingUser) { | |
| return { | |
| error: "Username is in use!" | |
| }; | |
| } | |
| const user = { id, username, room }; | |
| users.push(user); | |
| return { user }; | |
| }; | |
| const removeUser = id => { | |
| const index = users.findIndex(user => user.id === id); | |
| if (index !== -1) { | |
| return users.splice(index, 1)[0]; | |
| } | |
| }; | |
| const getUser = id => { | |
| return users.find(user => user.id === id); | |
| }; | |
| const getUsersInRoom = room => { | |
| room = room.trim().toLowerCase(); | |
| return users.filter(user => user.room === room); | |
| }; | |
| module.exports = { | |
| addUser, | |
| removeUser, | |
| getUser, | |
| getUsersInRoom | |
| }; | |