Skip to content

Commit b45f7c7

Browse files
committed
feat: add utils functions
1 parent ac2e899 commit b45f7c7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/runtime/utils/formRules.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const formRules = {
2525
v ? v.length <= 600 || 'Must not be longer than 600 characters' : true,
2626
maxLength1200: (v: string) =>
2727
v ? v.length <= 1200 || 'Must not be longer than 1200 characters' : true,
28+
maxLength5000: (v: string) =>
29+
v ? v.length <= 5000 || 'Must not be longer than 5000 characters' : true,
30+
maxLength10000: (v: string) =>
31+
v ? v.length <= 10000 || 'Must not be longer than 10,000 characters' : true,
2832

2933
// Number
3034
isInteger: (v: string) => Number.isInteger(+v) || 'Must be an integer',

src/runtime/utils/util.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ export const addOrReplaceArrayItem = (
1414
if (i > -1) array[i] = element
1515
else array.push(element)
1616
}
17+
18+
/**
19+
* Returns a random integer between min (inclusive) and max (inclusive).
20+
* The value is no lower than min (or the next integer greater than min
21+
* if min isn't an integer) and no greater than max (or the next integer
22+
* lower than max if max isn't an integer).
23+
* Using Math.round() will give you a non-uniform distribution!
24+
*/
25+
// https://stackoverflow.com/questions/1527803/how-to-generate-random-whole-numbers-in-javascript-in-a-specific-range
26+
export const getRandomInt = (min: number, max: number) => {
27+
min = Math.ceil(min)
28+
max = Math.floor(max)
29+
return Math.floor(Math.random() * (max - min + 1)) + min
30+
}

0 commit comments

Comments
 (0)