/
jsonValue.ts
23 lines (21 loc) · 899 Bytes
/
jsonValue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
import { string } from './string';
import { jsonConstraintsBuilder, JsonSharedConstraints, JsonValue } from './_internals/helpers/JsonConstraintsBuilder';
import { anything } from './anything';
export { JsonSharedConstraints, JsonValue };
/**
* For any JSON compliant values
*
* Keys and string values rely on {@link string}
*
* As `JSON.parse` preserves `-0`, `jsonValue` can also have `-0` as a value.
* `jsonValue` must be seen as: any value that could have been built by doing a `JSON.parse` on a given string.
*
* @param constraints - Constraints to be applied onto the generated instance
*
* @remarks Since 2.20.0
* @public
*/
export function jsonValue(constraints: JsonSharedConstraints = {}): Arbitrary<JsonValue> {
return anything(jsonConstraintsBuilder(string(), constraints)) as Arbitrary<JsonValue>;
}