@ibiliaze/stringman 3.10.0 → 3.12.0
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.
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -4
- package/dist/order.d.ts +5 -0
- package/dist/order.js +74 -0
- package/dist/seat.js +2 -2
- package/package.json +2 -2
- package/src/index.ts +4 -4
- package/src/order.ts +72 -0
- package/src/seat.ts +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -158,7 +158,7 @@ export declare const ticket: {
|
|
|
158
158
|
dashed?: boolean;
|
|
159
159
|
}) => string;
|
|
160
160
|
validateTicketCode: (code: string) => boolean;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
};
|
|
162
|
+
export declare const order: {
|
|
163
|
+
createNumericOrderId: () => string;
|
|
164
164
|
};
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ticket = exports.luhn36 = exports.b36 = exports.invalidPw = exports.getPublicIP = exports.isVideoUrl = exports.getRandomString = exports.extractImageSrcs = exports.select = exports.query = exports.getCloudinaryPublicId = exports.dp = exports.megaTrim = exports.superTrim = void 0;
|
|
17
|
+
exports.order = exports.ticket = exports.luhn36 = exports.b36 = exports.invalidPw = exports.getPublicIP = exports.isVideoUrl = exports.getRandomString = exports.extractImageSrcs = exports.select = exports.query = exports.getCloudinaryPublicId = exports.dp = exports.megaTrim = exports.superTrim = void 0;
|
|
18
18
|
__exportStar(require("./seat"), exports);
|
|
19
19
|
const ticket_1 = require("./ticket");
|
|
20
|
+
const order_1 = require("./order");
|
|
20
21
|
/**
|
|
21
22
|
* Clean up extra whitespace in a string.
|
|
22
23
|
*
|
|
@@ -305,7 +306,5 @@ exports.ticket = {
|
|
|
305
306
|
getTicketId: ticket_1.getTicketId,
|
|
306
307
|
buildTicketCode: ticket_1.buildTicketCode,
|
|
307
308
|
validateTicketCode: ticket_1.validateTicketCode,
|
|
308
|
-
rndBlock: ticket_1.rndBlock,
|
|
309
|
-
fixtureBlock: ticket_1.fixtureBlock,
|
|
310
|
-
seatBlock: ticket_1.seatBlock,
|
|
311
309
|
};
|
|
310
|
+
exports.order = { createNumericOrderId: order_1.createNumericOrderId };
|
package/dist/order.d.ts
ADDED
package/dist/order.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// orderId-numeric.js
|
|
3
|
+
// Format: <unixMs(13)><counter(4)><random(3)> => 20 digits total
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createNumericOrderId = void 0;
|
|
6
|
+
let _lastMs = 0;
|
|
7
|
+
let _ctr = 0;
|
|
8
|
+
const randomDigits = (n) => {
|
|
9
|
+
try {
|
|
10
|
+
// Crypto-strong, unbiased digits
|
|
11
|
+
const out = [];
|
|
12
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
13
|
+
const buf = new Uint8Array(n);
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < n) {
|
|
16
|
+
const b = new Uint8Array(1);
|
|
17
|
+
crypto.getRandomValues(b);
|
|
18
|
+
const x = b[0];
|
|
19
|
+
if (x < 250) {
|
|
20
|
+
// 250 is 25*10, rejection sampling to avoid bias
|
|
21
|
+
out.push((x % 10).toString());
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Node.js fallback
|
|
28
|
+
const { randomBytes } = require('crypto');
|
|
29
|
+
let i = 0;
|
|
30
|
+
while (i < n) {
|
|
31
|
+
const b = randomBytes(1)[0];
|
|
32
|
+
if (b < 250) {
|
|
33
|
+
out.push((b % 10).toString());
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out.join('');
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.error(e);
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* createNumericOrderId
|
|
47
|
+
* @returns {string} 20-digit, digits-only, sortable ID
|
|
48
|
+
*/
|
|
49
|
+
const createNumericOrderId = () => {
|
|
50
|
+
try {
|
|
51
|
+
const now = Date.now(); // 13 digits
|
|
52
|
+
if (now === _lastMs) {
|
|
53
|
+
_ctr++;
|
|
54
|
+
if (_ctr > 9999) {
|
|
55
|
+
// If you somehow generate >10k IDs in the same ms, roll to next ms.
|
|
56
|
+
while (Date.now() === now) { } // busy-wait a fraction of a ms
|
|
57
|
+
_ctr = 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
_lastMs = now;
|
|
62
|
+
_ctr = 0;
|
|
63
|
+
}
|
|
64
|
+
const timePart = String(now); // 13
|
|
65
|
+
const ctrPart = String(_ctr).padStart(4, '0'); // 4
|
|
66
|
+
const randPart = randomDigits(3); // 3
|
|
67
|
+
return timePart + ctrPart + randPart; // 20 digits
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.error(e);
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.createNumericOrderId = createNumericOrderId;
|
package/dist/seat.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFromItemId = exports.getItemId = exports.seatMapKey = exports.getSeatColFromName = exports.getSeatRowFromName = void 0;
|
|
4
|
-
const getSeatRowFromName = (seatName) => seatName?.split(':')?.[0];
|
|
4
|
+
const getSeatRowFromName = (seatName) => seatName?.split(':')?.[0] || 'Unassigned seat';
|
|
5
5
|
exports.getSeatRowFromName = getSeatRowFromName;
|
|
6
|
-
const getSeatColFromName = (seatName) => seatName?.split(':')?.[1];
|
|
6
|
+
const getSeatColFromName = (seatName) => seatName?.split(':')?.[1] || 'Unassigned seat';
|
|
7
7
|
exports.getSeatColFromName = getSeatColFromName;
|
|
8
8
|
const seatMapKey = (row, col) => `${row}:${col}`;
|
|
9
9
|
exports.seatMapKey = seatMapKey;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiliaze/stringman",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"pub": "npm publish --access public",
|
|
10
|
-
"git": "git add .; git commit -m 'changes'; git tag -a v3.
|
|
10
|
+
"git": "git add .; git commit -m 'changes'; git tag -a v3.12.0 -m 'v3.12.0'; git push origin v3.12.0; git push",
|
|
11
11
|
"push": "npm run build; npm run git; npm run pub"
|
|
12
12
|
},
|
|
13
13
|
"author": "Ibi Hasanli",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './seat';
|
|
2
|
-
import { buildTicketCode,
|
|
2
|
+
import { buildTicketCode, getTicketId, validateTicketCode } from './ticket';
|
|
3
|
+
import { createNumericOrderId } from './order';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Clean up extra whitespace in a string.
|
|
@@ -281,7 +282,6 @@ export const ticket = {
|
|
|
281
282
|
getTicketId,
|
|
282
283
|
buildTicketCode,
|
|
283
284
|
validateTicketCode,
|
|
284
|
-
rndBlock,
|
|
285
|
-
fixtureBlock,
|
|
286
|
-
seatBlock,
|
|
287
285
|
};
|
|
286
|
+
|
|
287
|
+
export const order = { createNumericOrderId };
|
package/src/order.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// orderId-numeric.js
|
|
2
|
+
// Format: <unixMs(13)><counter(4)><random(3)> => 20 digits total
|
|
3
|
+
|
|
4
|
+
let _lastMs = 0;
|
|
5
|
+
let _ctr = 0;
|
|
6
|
+
|
|
7
|
+
const randomDigits = (n: number) => {
|
|
8
|
+
try {
|
|
9
|
+
// Crypto-strong, unbiased digits
|
|
10
|
+
const out = [];
|
|
11
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
12
|
+
const buf = new Uint8Array(n);
|
|
13
|
+
let i = 0;
|
|
14
|
+
while (i < n) {
|
|
15
|
+
const b = new Uint8Array(1);
|
|
16
|
+
crypto.getRandomValues(b);
|
|
17
|
+
const x = b[0];
|
|
18
|
+
if (x < 250) {
|
|
19
|
+
// 250 is 25*10, rejection sampling to avoid bias
|
|
20
|
+
out.push((x % 10).toString());
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
// Node.js fallback
|
|
26
|
+
const { randomBytes } = require('crypto');
|
|
27
|
+
let i = 0;
|
|
28
|
+
while (i < n) {
|
|
29
|
+
const b = randomBytes(1)[0];
|
|
30
|
+
if (b < 250) {
|
|
31
|
+
out.push((b % 10).toString());
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out.join('');
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error(e);
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* createNumericOrderId
|
|
45
|
+
* @returns {string} 20-digit, digits-only, sortable ID
|
|
46
|
+
*/
|
|
47
|
+
export const createNumericOrderId = (): string => {
|
|
48
|
+
try {
|
|
49
|
+
const now = Date.now(); // 13 digits
|
|
50
|
+
|
|
51
|
+
if (now === _lastMs) {
|
|
52
|
+
_ctr++;
|
|
53
|
+
if (_ctr > 9999) {
|
|
54
|
+
// If you somehow generate >10k IDs in the same ms, roll to next ms.
|
|
55
|
+
while (Date.now() === now) {} // busy-wait a fraction of a ms
|
|
56
|
+
_ctr = 0;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
_lastMs = now;
|
|
60
|
+
_ctr = 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const timePart = String(now); // 13
|
|
64
|
+
const ctrPart = String(_ctr).padStart(4, '0'); // 4
|
|
65
|
+
const randPart = randomDigits(3); // 3
|
|
66
|
+
|
|
67
|
+
return timePart + ctrPart + randPart; // 20 digits
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error(e);
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
};
|
package/src/seat.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const getSeatRowFromName = (seatName: string) => seatName?.split(':')?.[0];
|
|
2
|
-
export const getSeatColFromName = (seatName: string) => seatName?.split(':')?.[1];
|
|
1
|
+
export const getSeatRowFromName = (seatName: string) => seatName?.split(':')?.[0] || 'Unassigned seat';
|
|
2
|
+
export const getSeatColFromName = (seatName: string) => seatName?.split(':')?.[1] || 'Unassigned seat';
|
|
3
3
|
|
|
4
4
|
export const seatMapKey = (row: number, col: number) => `${row}:${col}`;
|
|
5
5
|
|