Skip to content

Commit

Permalink
add support for useful but non-standard "function" type
Browse files Browse the repository at this point in the history
  • Loading branch information
canterberry committed Sep 18, 2024
1 parent e4c637d commit 174d925
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 39 deletions.
87 changes: 50 additions & 37 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsj",
"version": "0.2.0",
"version": "0.3.0",
"description": "Simple, fast, minimal JSON Schema validation.",
"type": "module",
"module": "src/index.mjs",
Expand All @@ -26,6 +26,6 @@
},
"devDependencies": {
"c8": "^10.1.2",
"eslint": "^9.9.0"
"eslint": "^9.10.0"
}
}
2 changes: 2 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { anyOf } from './anyOf.mjs';
import { defaultState } from './defaults.mjs';
import { validateArray } from './validators/array.mjs';
import { validateBoolean } from './validators/boolean.mjs';
import { validateFunction } from './validators/function.mjs';
import { validateInteger } from './validators/integer.mjs';
import { validateNull } from './validators/null.mjs';
import { validateNumber } from './validators/number.mjs';
Expand All @@ -13,6 +14,7 @@ import { validateString } from './validators/string.mjs';
const byType = Object.freeze({
array: validateArray,
boolean: validateBoolean,
function: validateFunction,
integer: validateInteger,
null: validateNull,
number: validateNumber,
Expand Down
1 change: 1 addition & 0 deletions src/test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './validators/array.test.mjs';
import './validators/boolean.test.mjs';
import './validators/function.test.mjs';
import './validators/integer.test.mjs';
import './validators/null.test.mjs';
import './validators/number.test.mjs';
Expand Down
5 changes: 5 additions & 0 deletions src/validators/function.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { assertType } from '../assertType.mjs';

export const validateFunction = () => (object, state) => {
assertType('function', object, state);
};
7 changes: 7 additions & 0 deletions src/validators/function.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import assert from 'node:assert/strict';
import { validateFunction } from './function.mjs';

const state = { depth: 0, instanceLocation: '', keywordLocation: '', onError(error) { throw error; } };

assert.doesNotThrow(() => validateFunction()(() => true, state));
assert.throws(() => validateFunction()('!', state));

0 comments on commit 174d925

Please sign in to comment.