Comparing version 2.0.3 to 2.1.0
@@ -13,2 +13,40 @@ var hash = require('./hash') | ||
opts = opts || 0 | ||
var minDate, maxDate | ||
// keep older dateString function for backwards compatibility | ||
if ( | ||
!opts || | ||
(opts.minYear && opts.minYear) || | ||
(opts.minYear && !opts.max) || | ||
(!opts.min && opts.maxYear) | ||
) { | ||
return dateStringLegacy(input, opts) | ||
} | ||
if (opts.min) { | ||
minDate = new Date(opts.min) | ||
} else { | ||
var minYear = defaults(opts.minYear, MIN_YEAR) | ||
minDate = new Date(Date.UTC(minYear, 0, 1)) | ||
} | ||
if (opts.max) { | ||
maxDate = new Date(opts.max) | ||
} else { | ||
var maxYear = defaults(opts.maxYear, MAX_YEAR) | ||
maxDate = new Date(Date.UTC(maxYear, 11, 31, 23, 59, 59, 999)) | ||
} | ||
var min = minDate.getTime() | ||
var max = maxDate.getTime() | ||
var time = fit(id, min, max) | ||
return new Date(time).toISOString() | ||
} | ||
function dateStringLegacy(input, opts) { | ||
var id = hash(input) | ||
opts = opts || 0 | ||
var minYear = defaults(opts.minYear, MIN_YEAR) | ||
@@ -15,0 +53,0 @@ var maxYear = defaults(opts.maxYear, MAX_YEAR) |
435
index.d.ts
@@ -69,2 +69,4 @@ export type JSONPrimitive = null | number | string | boolean | ||
maxYear: number | ||
min: Date | string | ||
max: Date | string | ||
} | ||
@@ -186,5 +188,5 @@ | ||
export interface OneOfWeighted { | ||
<M extends WeightedMaker>(samples: M[]): ( | ||
input: Input | ||
) => WeightedMakerResult<M> | ||
<M extends WeightedMaker>( | ||
samples: M[] | ||
): (input: Input) => WeightedMakerResult<M> | ||
<M extends WeightedMaker>(input: Input, samples: M[]): WeightedMakerResult<M> | ||
@@ -198,5 +200,6 @@ } | ||
export interface SomeOf { | ||
<M extends Maker>(range: Range, samples: M[]): ( | ||
input: Input | ||
) => MakerResult<M>[] | ||
<M extends Maker>( | ||
range: Range, | ||
samples: M[] | ||
): (input: Input) => MakerResult<M>[] | ||
<M extends Maker>(input: Input, range: Range, samples: M[]): MakerResult<M>[] | ||
@@ -226,5 +229,6 @@ } | ||
<R>(joiner: string, makers: Maker[]): (input: Input) => string | ||
<M extends Maker, R>(joiner: (results: MakerResult<M>[]) => R, makers: M[]): ( | ||
input: Input | ||
) => R | ||
<M extends Maker, R>( | ||
joiner: (results: MakerResult<M>[]) => R, | ||
makers: M[] | ||
): (input: Input) => R | ||
} | ||
@@ -237,6 +241,6 @@ | ||
export interface Tuple { | ||
<Makers extends AnyMakers>(makers: Makers): ( | ||
input: Input | ||
) => TupleReturnType<Makers> | ||
<Makers extends AnyMakers>( | ||
makers: Makers | ||
): (input: Input) => TupleReturnType<Makers> | ||
<Makers extends AnyMakers>( | ||
input: Input, | ||
@@ -252,6 +256,6 @@ makers: Makers | ||
export interface Shape { | ||
<Makers extends { [s: string]: Maker<unknown> }>(makers: Makers): ( | ||
input: Input | ||
) => ShapeReturnType<Makers> | ||
<Makers extends { [s: string]: Maker<unknown> }>( | ||
makers: Makers | ||
): (input: Input) => ShapeReturnType<Makers> | ||
<Makers extends { [s: string]: Maker<unknown> }>( | ||
input: Input, | ||
@@ -274,169 +278,236 @@ makers: Makers | ||
export type TupleReturnType<Makers extends AnyMakers> = Makers extends Makers1< | ||
infer V1 | ||
> | ||
? [V1] | ||
: Makers extends Makers2<infer V1, infer V2> | ||
? [V1, V2] | ||
: Makers extends Makers3<infer V1, infer V2, infer V3> | ||
? [V1, V2, V3] | ||
: Makers extends Makers4<infer V1, infer V2, infer V3, infer V4> | ||
? [V1, V2, V3, V4] | ||
: Makers extends Makers5<infer V1, infer V2, infer V3, infer V4, infer V5> | ||
? [V1, V2, V3, V4, V5] | ||
: Makers extends Makers6< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6 | ||
> | ||
? [V1, V2, V3, V4, V5, V6] | ||
: Makers extends Makers7< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7] | ||
: Makers extends Makers8< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8] | ||
: Makers extends Makers9< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9] | ||
: Makers extends Makers10< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10] | ||
: Makers extends Makers11< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11] | ||
: Makers extends Makers12< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12] | ||
: Makers extends Makers13< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13] | ||
: Makers extends Makers14< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13, | ||
infer V14 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14] | ||
: Makers extends Makers15< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13, | ||
infer V14, | ||
infer V15 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15] | ||
: Makers extends Makers16< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13, | ||
infer V14, | ||
infer V15, | ||
infer V16 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16] | ||
: never | ||
export type TupleReturnType<Makers extends AnyMakers> = | ||
Makers extends Makers1<infer V1> | ||
? [V1] | ||
: Makers extends Makers2<infer V1, infer V2> | ||
? [V1, V2] | ||
: Makers extends Makers3<infer V1, infer V2, infer V3> | ||
? [V1, V2, V3] | ||
: Makers extends Makers4<infer V1, infer V2, infer V3, infer V4> | ||
? [V1, V2, V3, V4] | ||
: Makers extends Makers5< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5 | ||
> | ||
? [V1, V2, V3, V4, V5] | ||
: Makers extends Makers6< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6 | ||
> | ||
? [V1, V2, V3, V4, V5, V6] | ||
: Makers extends Makers7< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7] | ||
: Makers extends Makers8< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8] | ||
: Makers extends Makers9< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9] | ||
: Makers extends Makers10< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10] | ||
: Makers extends Makers11< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11] | ||
: Makers extends Makers12< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12 | ||
> | ||
? [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12] | ||
: Makers extends Makers13< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13 | ||
> | ||
? [ | ||
V1, | ||
V2, | ||
V3, | ||
V4, | ||
V5, | ||
V6, | ||
V7, | ||
V8, | ||
V9, | ||
V10, | ||
V11, | ||
V12, | ||
V13 | ||
] | ||
: Makers extends Makers14< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13, | ||
infer V14 | ||
> | ||
? [ | ||
V1, | ||
V2, | ||
V3, | ||
V4, | ||
V5, | ||
V6, | ||
V7, | ||
V8, | ||
V9, | ||
V10, | ||
V11, | ||
V12, | ||
V13, | ||
V14 | ||
] | ||
: Makers extends Makers15< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13, | ||
infer V14, | ||
infer V15 | ||
> | ||
? [ | ||
V1, | ||
V2, | ||
V3, | ||
V4, | ||
V5, | ||
V6, | ||
V7, | ||
V8, | ||
V9, | ||
V10, | ||
V11, | ||
V12, | ||
V13, | ||
V14, | ||
V15 | ||
] | ||
: Makers extends Makers16< | ||
infer V1, | ||
infer V2, | ||
infer V3, | ||
infer V4, | ||
infer V5, | ||
infer V6, | ||
infer V7, | ||
infer V8, | ||
infer V9, | ||
infer V10, | ||
infer V11, | ||
infer V12, | ||
infer V13, | ||
infer V14, | ||
infer V15, | ||
infer V16 | ||
> | ||
? [ | ||
V1, | ||
V2, | ||
V3, | ||
V4, | ||
V5, | ||
V6, | ||
V7, | ||
V8, | ||
V9, | ||
V10, | ||
V11, | ||
V12, | ||
V13, | ||
V14, | ||
V15, | ||
V16 | ||
] | ||
: never | ||
@@ -443,0 +514,0 @@ type AnyMakers = |
{ | ||
"name": "fictional", | ||
"description": "Generate fake data deterministically from a given input", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"type": "commonjs", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -360,2 +360,8 @@ # `fictional` | ||
Not providing `options` will default to `minYear=1980` and `maxYear=2019` for | ||
backwards compatibility. | ||
If you provide no options or `minYear` and `maxYear`, generated dates will be | ||
restricted to be between the 1st and 28th of any month. | ||
```js | ||
@@ -368,2 +374,14 @@ dateString('id-23') | ||
- **`min='2024-01-01T00:00:00Z'` and `max='2024-12-31T23:59:59:999Z'`:** the | ||
minimum and maximum possible date values. Values can be any string that can be | ||
parsed directly by javascript's Date constructor or a Date object itself. | ||
```js | ||
dateString('id-1', { | ||
min: new Date('2024-01-01T00:00:00Z'), | ||
max: new Date('2024-12-31T23:59:59.999Z') | ||
}) | ||
// => '2024-04-01T02:39:56.220Z' | ||
``` | ||
- **`minYear=1980` and `maxYear=2019`:** the minimum and maximum possible year | ||
@@ -370,0 +388,0 @@ values for returned dates |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
955378
8273
866