Skip to content

Commit e587ae0

Browse files
authored
feat: add enablePatterns config option (#163)
1 parent 4c43449 commit e587ae0

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/samplers/string.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ function timeSample(min, max) {
4343
return commonDateTimeSample({ min, max, omitTime: false, omitDate: true }).slice(1);
4444
}
4545

46-
function defaultSample(min, max, _propertyName, pattern) {
47-
if (pattern) {
46+
function defaultSample(min, max, _propertyName, pattern, enablePatterns = false) {
47+
if (pattern && enablePatterns) {
4848
return faker.regexSample(pattern);
4949
}
5050
let res = ensureMinLength('string', min);
@@ -136,5 +136,6 @@ export function sampleString(schema, options, spec, context) {
136136
schema.maxLength,
137137
propertyName,
138138
schema.pattern,
139+
options?.enablePatterns
139140
);
140141
}

src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface Options {
55
readonly skipReadOnly?: boolean;
66
readonly skipWriteOnly?: boolean;
77
readonly quiet?: boolean;
8+
readonly enablePatterns?: boolean
89
}
910

1011
export function sample(schema: JSONSchema7, options?: Options, document?: object): unknown;

test/unit/string.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('sampleString', () => {
135135
.forEach((regexp) => {
136136
res = sampleString(
137137
{pattern: regexp.source},
138-
null,
138+
{enablePatterns: true},
139139
null,
140140
{propertyName: 'fooId'},
141141
);

0 commit comments

Comments
 (0)