aboutsummaryrefslogtreecommitdiff
path: root/src/modules/date
diff options
context:
space:
mode:
authorBruno Leite <[email protected]>2024-10-10 13:08:57 -0300
committerGitHub <[email protected]>2024-10-10 18:08:57 +0200
commit5b1c8588f8a57be712e64434f7b17a8407a4f465 (patch)
tree0e59657cb03f9827b7165bbfc3053ec4867a1016 /src/modules/date
parent2f93d9da383638b6d232ff8b3cae827ea4c80150 (diff)
downloadfaker-5b1c8588f8a57be712e64434f7b17a8407a4f465.tar.xz
faker-5b1c8588f8a57be712e64434f7b17a8407a4f465.zip
feat(string): adds support for generating ULID (#2524)
Diffstat (limited to 'src/modules/date')
-rw-r--r--src/modules/date/index.ts19
1 files changed, 1 insertions, 18 deletions
diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts
index 53204a03..06890a5d 100644
--- a/src/modules/date/index.ts
+++ b/src/modules/date/index.ts
@@ -1,28 +1,11 @@
import type { Faker } from '../..';
import type { DateEntryDefinition } from '../../definitions';
import { FakerError } from '../../errors/faker-error';
+import { toDate } from '../../internal/date';
import { assertLocaleData } from '../../internal/locale-proxy';
import { SimpleModuleBase } from '../../internal/module-base';
/**
- * Converts a date passed as a `string`, `number` or `Date` to a valid `Date` object.
- *
- * @param date The date to convert.
- * @param name The reference name used for error messages. Defaults to `'refDate'`.
- *
- * @throws If the given date is invalid.
- */
-function toDate(date: string | Date | number, name: string = 'refDate'): Date {
- const converted = new Date(date);
-
- if (Number.isNaN(converted.valueOf())) {
- throw new FakerError(`Invalid ${name} date: ${date.toString()}`);
- }
-
- return converted;
-}
-
-/**
* Module to generate dates (without methods requiring localized data).
*/
export class SimpleDateModule extends SimpleModuleBase {