Back to packages list

Vals using uuid

Description from the NPM package:
RFC4122 (v1, v4, and v5) UUIDs
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { saveFile } from "https://esm.town/v/omgwtfbrblolttyl/saveFile";
import { signToken } from "https://esm.town/v/omgwtfbrblolttyl/signToken";
type Poll = {
id?: string;
owner: {
email: string;
};
participants: {
email: string;
}[];
optionsList: {
id?: string;
}[];
};
export const createPollEndpoint = async (
req: express.Request,
res: express.Response,
) => {
const { v4: uuid } = await import("npm:uuid");
if (req.method !== "POST") {
return res.status(404).json({ msg: "Not found" });
}
const poll = req.body;
if (typeof poll !== "object") {
return res.status(400).json({ msg: "Bad request" });
}
// Create Id for poll
poll.id = uuid();
// Create ids for options
poll.optionsList = poll.optionsList
.map((opt) => ({
...opt,
id: uuid(),
}));
// Create tokens for participants
const mkToken = (user, extra: {
read?: string[];
write?: string[];
list?: string[];
meta?: Record<string, any>;
} = {}) =>
signToken({
read: [
`/polls/${poll.id}/poll.json`,
`/polls/${poll.id}/participants/*.json`,
`/polls/${poll.id}/rankings/*.json`,
...(extra.read || []),
],
write: [

uuid

The uuid module provides builders for different types of universally unique identifiers. These are kinds of identifiers that you can use instead of auto-incrementing integers. They're intended to contain so much randomness that the chances of a collision between two uuids is very low.

There are different versions of uuids available: typically people use v4 UUIDs, which are fully random.

Readme
1
2
3
4
export const uuidExample = (async () => {
const uuid = await import("npm:uuid");
return uuid.v4();
})();
1
Next