@travetto/schema-faker 4.1.1 → 5.0.0-rc.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/LICENSE +1 -1
- package/package.json +2 -2
- package/src/faker.ts +4 -6
package/LICENSE
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/schema-faker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-rc.0",
|
|
4
4
|
"description": "Data generation for schema-registered objects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@faker-js/faker": "^8.4.1",
|
|
29
|
-
"@travetto/schema": "^
|
|
29
|
+
"@travetto/schema": "^5.0.0-rc.0"
|
|
30
30
|
},
|
|
31
31
|
"travetto": {
|
|
32
32
|
"displayName": "Schema Faker"
|
package/src/faker.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { faker } from '@faker-js/faker';
|
|
2
2
|
|
|
3
|
-
import { Class } from '@travetto/base';
|
|
3
|
+
import { Class, TimeUtil } from '@travetto/base';
|
|
4
4
|
import { BindUtil, SchemaRegistry, FieldConfig, CommonRegExp } from '@travetto/schema';
|
|
5
5
|
|
|
6
|
-
const DAY_IN_MS = 24 * 60 * 60 * 1000;
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Provide a faker utility for generating content
|
|
10
8
|
*/
|
|
@@ -55,8 +53,8 @@ export class SchemaFaker {
|
|
|
55
53
|
|
|
56
54
|
static #between(fromDays: number, toDays: number): Date {
|
|
57
55
|
return faker.date.between({
|
|
58
|
-
from:
|
|
59
|
-
to:
|
|
56
|
+
from: TimeUtil.fromNow(fromDays, 'd'),
|
|
57
|
+
to: TimeUtil.fromNow(toDays, 'd')
|
|
60
58
|
});
|
|
61
59
|
}
|
|
62
60
|
|
|
@@ -120,7 +118,7 @@ export class SchemaFaker {
|
|
|
120
118
|
const max = cfg.max && typeof cfg.max.n !== 'number' ? cfg.max.n : undefined;
|
|
121
119
|
|
|
122
120
|
if (min !== undefined || max !== undefined) {
|
|
123
|
-
return faker.date.between({ from: min ||
|
|
121
|
+
return faker.date.between({ from: min || TimeUtil.fromNow(-50, 'd'), to: max || new Date() });
|
|
124
122
|
} else {
|
|
125
123
|
for (const [re, fn] of this.#namesToType.date) {
|
|
126
124
|
if (re.test(name)) {
|