Skip to content

Commit

Permalink
feat: add enablePatterns config option (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oprysk authored May 2, 2024
1 parent 4c43449 commit e587ae0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/samplers/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function timeSample(min, max) {
return commonDateTimeSample({ min, max, omitTime: false, omitDate: true }).slice(1);
}

function defaultSample(min, max, _propertyName, pattern) {
if (pattern) {
function defaultSample(min, max, _propertyName, pattern, enablePatterns = false) {
if (pattern && enablePatterns) {
return faker.regexSample(pattern);
}
let res = ensureMinLength('string', min);
Expand Down Expand Up @@ -136,5 +136,6 @@ export function sampleString(schema, options, spec, context) {
schema.maxLength,
propertyName,
schema.pattern,
options?.enablePatterns
);
}
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Options {
readonly skipReadOnly?: boolean;
readonly skipWriteOnly?: boolean;
readonly quiet?: boolean;
readonly enablePatterns?: boolean
}

export function sample(schema: JSONSchema7, options?: Options, document?: object): unknown;
2 changes: 1 addition & 1 deletion test/unit/string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('sampleString', () => {
.forEach((regexp) => {
res = sampleString(
{pattern: regexp.source},
null,
{enablePatterns: true},
null,
{propertyName: 'fooId'},
);
Expand Down

0 comments on commit e587ae0

Please sign in to comment.