Skip to content

Commit

Permalink
docs: fix inconsistencies #3; fix flatmap to make it mildly simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelvesavuori committed Mar 5, 2024
1 parent 64c7043 commit f7a0638
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The general shape it uses is:
"type": "string"
}
},
"required": ["name"]
"required": ["username"]
}
```

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mikrovalid",
"description": "MikroValid is the JSON validator that cuts out all the bullshit.",
"version": "1.0.7",
"version": "1.0.8",
"author": "Mikael Vesavuori",
"license": "MIT",
"main": "./lib/index.js",
Expand Down
14 changes: 7 additions & 7 deletions src/domain/MikroValid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ export class MikroValid {
* takes care of the rest.
*
* @example
* import { MikroValid } from './MikroValid';
* import { MikroValid } from 'mikrovalid';
*
* const mikrovalid = new MikroValid();
*
* const schema = {
* properties: {
* personal: {
* name: 'string',
* name: { type: 'string' },
* required: ['name']
* },
* work: {
* office: 'string',
* currency: 'string',
* salary: 'number',
* office: { type: 'string' },
* currency: { type: 'string' },
* salary: { type: 'number' },
* required: ['office']
* },
* required: ['personal', 'work']
Expand All @@ -47,7 +47,7 @@ export class MikroValid {
* }
* };
*
* const { valid, errors } = mikrovalid.test(schema, input);
* const { success, errors } = mikrovalid.test(schema, input);
*
* console.log('Was the test successful?', success);
*/
Expand All @@ -69,7 +69,7 @@ export class MikroValid {
*/
private compileErrors(results: Result[], errors: ValidationError[]): ValidationError[] {
const resultErrors = results.filter((result: Result) => result.success === false);
return [...errors, resultErrors].flatMap((error: Result | Result[]) => error);
return [...errors, ...resultErrors].flatMap((error: Result) => error);
}

/**
Expand Down
22 changes: 7 additions & 15 deletions tests/MikroValid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,25 +886,17 @@ test('It should work with the demo example', (t) => {
const schema = {
properties: {
personal: {
name: {
type: 'string'
},
name: { type: 'string' },
required: ['name']
},
work: {
office: {
type: 'string'
},
currency: {
type: 'string'
},
salary: {
type: 'number'
},
office: { type: 'string' },
currency: { type: 'string' },
salary: { type: 'number' },
required: ['office']
}
},
required: ['personal', 'work']
},
required: ['personal', 'work']
}
};

const input = {
Expand Down

0 comments on commit f7a0638

Please sign in to comment.