@jcbuisson/express-x-client 1.5.6 → 1.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +11 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-client",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "type": "module",
5
5
  "description": "Client library for ExpressX framework",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -1,6 +1,15 @@
1
1
 
2
- import { v4 } from 'uuid'
2
+ function generateUID(length) {
3
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
4
+ let uid = '';
3
5
 
6
+ for (let i = 0; i < length; i++) {
7
+ const randomIndex = Math.floor(Math.random() * characters.length)
8
+ uid += characters.charAt(randomIndex)
9
+ }
10
+ return uid
11
+ }
12
+
4
13
  export default function expressXClient(socket, options={}) {
5
14
  if (options.debug === undefined) options.debug = false
6
15
 
@@ -127,7 +136,7 @@ export default function expressXClient(socket, options={}) {
127
136
  if (retries === 0) throw new Error(`Timeout waiting for reconnection`)
128
137
 
129
138
  // create a promise which will resolve or reject by an event 'client-response'
130
- const uid = v4()
139
+ const uid = generateUID(20)
131
140
  const promise = new Promise((resolve, reject) => {
132
141
  waitingPromisesByUid[uid] = [resolve, reject]
133
142
  // a 5s timeout may also reject the promise