Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ npm install schema-utils
```

```js
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
import schema from "./path/to/schema.json";

const options = { option: true };
const configuration = { name: "Loader Name/Plugin Name/Name" };
Expand Down Expand Up @@ -82,8 +82,8 @@ Type: `Object`
Object with options.

```js
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
import schema from "./path/to/schema.json";

const options = { foo: "bar" };

Expand Down Expand Up @@ -122,8 +122,8 @@ Default: `"Object"`
Allow to setup name in validation errors.

```js
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
import schema from "./path/to/schema.json";

const options = { foo: "bar" };

Expand All @@ -143,8 +143,8 @@ Default: `"configuration"`
Allow to setup base data path in validation errors.

```js
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
import schema from "./path/to/schema.json";

const options = { foo: "bar" };

Expand All @@ -164,8 +164,8 @@ Default: `undefined`
Allow to reformat errors.

```js
import schema from "./path/to/schema.json";
import { validate } from "schema-utils";
import schema from "./path/to/schema.json";

const options = { foo: "bar" };

Expand Down Expand Up @@ -219,11 +219,10 @@ Invalid options object. MyPlugin has been initialized using an options object th
### `Loader`

```js
import schema from "path/to/schema.json";
import { getOptions } from "loader-utils";
import { validate } from "schema-utils";

import schema from "path/to/schema.json";

function loader(src, map) {
const options = getOptions(this);

Expand All @@ -241,9 +240,8 @@ export default loader;
### `Plugin`

```js
import { validate } from "schema-utils";

import schema from "path/to/schema.json";
import { validate } from "schema-utils";

class Plugin {
constructor(options) {
Expand Down
25 changes: 11 additions & 14 deletions declarations/ValidationError.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ export type ValidationErrorConfiguration =
import("./validate").ValidationErrorConfiguration;
export type PostFormatter = import("./validate").PostFormatter;
export type SchemaUtilErrorObject = import("./validate").SchemaUtilErrorObject;
export type EXPECTED_ANY = any;
declare class ValidationError extends Error {
/**
* @param {Array<SchemaUtilErrorObject>} errors array of error objects
* @param {SchemaUtilErrorObject[]} errors array of error objects
* @param {Schema} schema schema
* @param {ValidationErrorConfiguration} configuration configuration
*/
constructor(
errors: Array<SchemaUtilErrorObject>,
errors: SchemaUtilErrorObject[],
schema: Schema,
configuration?: ValidationErrorConfiguration,
);
/** @type {Array<SchemaUtilErrorObject>} */
errors: Array<SchemaUtilErrorObject>;
/** @type {SchemaUtilErrorObject[]} */
errors: SchemaUtilErrorObject[];
/** @type {Schema} */
schema: Schema;
/** @type {string} */
Expand All @@ -35,24 +36,20 @@ declare class ValidationError extends Error {
/**
* @param {Schema} schema schema
* @param {boolean} logic logic
* @param {Array<object>} prevSchemas prev schemas
* @param {object[]} prevSchemas prev schemas
* @returns {string} formatted schema
*/
formatSchema(
schema: Schema,
logic?: boolean,
prevSchemas?: Array<object>,
): string;
formatSchema(schema: Schema, logic?: boolean, prevSchemas?: object[]): string;
/**
* @param {Schema=} schemaPart schema part
* @param {(boolean | Array<string>)=} additionalPath additional path
* @param {(boolean | string[])=} additionalPath additional path
* @param {boolean=} needDot true when need dot
* @param {boolean=} logic logic
* @returns {string} schema part text
*/
getSchemaPartText(
schemaPart?: Schema | undefined,
additionalPath?: (boolean | Array<string>) | undefined,
additionalPath?: (boolean | string[]) | undefined,
needDot?: boolean | undefined,
logic?: boolean | undefined,
): string;
Expand All @@ -67,8 +64,8 @@ declare class ValidationError extends Error {
*/
formatValidationError(error: SchemaUtilErrorObject): string;
/**
* @param {Array<SchemaUtilErrorObject>} errors errors
* @param {SchemaUtilErrorObject[]} errors errors
* @returns {string} formatted errors
*/
formatValidationErrors(errors: Array<SchemaUtilErrorObject>): string;
formatValidationErrors(errors: SchemaUtilErrorObject[]): string;
}
8 changes: 4 additions & 4 deletions declarations/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export type JSONSchema7 = import("./validate").JSONSchema7;
export type ExtendedSchema = import("./validate").ExtendedSchema;
export type ValidationErrorConfiguration =
import("./validate").ValidationErrorConfiguration;
import { validate } from "./validate";
import { ValidationError } from "./validate";
import { enableValidation } from "./validate";
import { disableValidation } from "./validate";
import { enableValidation } from "./validate";
import { needValidate } from "./validate";
import { validate } from "./validate";
export {
validate,
ValidationError,
enableValidation,
disableValidation,
enableValidation,
needValidate,
validate,
};
12 changes: 6 additions & 6 deletions declarations/util/Range.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ declare class Range {
logic: boolean,
): string;
/**
* @param {Array<RangeValue>} values values
* @param {RangeValue[]} values values
* @param {boolean} logic is not logic applied
* @returns {RangeValue} computed value and it's exclusive flag
*/
static getRangeValue(values: Array<RangeValue>, logic: boolean): RangeValue;
/** @type {Array<RangeValue>} */
_left: Array<RangeValue>;
/** @type {Array<RangeValue>} */
_right: Array<RangeValue>;
static getRangeValue(values: RangeValue[], logic: boolean): RangeValue;
/** @type {RangeValue[]} */
_left: RangeValue[];
/** @type {RangeValue[]} */
_right: RangeValue[];
/**
* @param {number} value value
* @param {boolean=} exclusive true when exclusive, otherwise false
Expand Down
2 changes: 1 addition & 1 deletion declarations/util/hints.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function stringHints(schema: Schema, logic: boolean): string[];
export function numberHints(schema: Schema, logic: boolean): string[];
export function stringHints(schema: Schema, logic: boolean): string[];
export type Schema = import("../validate").Schema;
26 changes: 13 additions & 13 deletions declarations/validate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type ExtendedSchema = {
export type Extend = ExtendedSchema;
export type Schema = (JSONSchema4 | JSONSchema6 | JSONSchema7) & ExtendedSchema;
export type SchemaUtilErrorObject = ErrorObject & {
children?: Array<ErrorObject>;
children?: ErrorObject[];
};
export type PostFormatter = (
formattedError: string,
Expand All @@ -53,25 +53,25 @@ export type ValidationErrorConfiguration = {
postFormatter?: PostFormatter | undefined;
};
/**
* @param {Schema} schema schema
* @param {Array<object> | object} options options
* @param {ValidationErrorConfiguration=} configuration configuration
* @returns {void}
*/
export function validate(
schema: Schema,
options: Array<object> | object,
configuration?: ValidationErrorConfiguration | undefined,
): void;
export function disableValidation(): void;
/**
* @returns {void}
*/
export function enableValidation(): void;
/**
* @returns {void}
*/
export function disableValidation(): void;
/**
* @returns {boolean} true when need validate, otherwise false
*/
export function needValidate(): boolean;
/**
* @param {Schema} schema schema
* @param {object[] | object} options options
* @param {ValidationErrorConfiguration=} configuration configuration
* @returns {void}
*/
export function validate(
schema: Schema,
options: object[] | object,
configuration?: ValidationErrorConfiguration | undefined,
): void;
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('jest').Config} */
/** @type {import("jest").Config} */
const config = {
prettierPath: require.resolve("prettier-2"),
};
Expand Down
Loading
Loading