Browse Source

chore: bumps version to 0.0.1

e22m4u 3 weeks ago
parent
commit
87d4722a2c

+ 1070 - 0
dist/cjs/index.cjs

@@ -0,0 +1,1070 @@
+"use strict";
+var __defProp = Object.defineProperty;
+var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
+var __getOwnPropNames = Object.getOwnPropertyNames;
+var __hasOwnProp = Object.prototype.hasOwnProperty;
+var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
+var __export = (target, all) => {
+  for (var name in all)
+    __defProp(target, name, { get: all[name], enumerable: true });
+};
+var __copyProps = (to, from, except, desc) => {
+  if (from && typeof from === "object" || typeof from === "function") {
+    for (let key of __getOwnPropNames(from))
+      if (!__hasOwnProp.call(to, key) && key !== except)
+        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
+  }
+  return to;
+};
+var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
+
+// src/index.js
+var index_exports = {};
+__export(index_exports, {
+  DATA_TYPE_LIST: () => DATA_TYPE_LIST,
+  DataParser: () => DataParser,
+  DataParsingError: () => DataParsingError,
+  DataSchemaRegistry: () => DataSchemaRegistry,
+  DataSchemaResolver: () => DataSchemaResolver,
+  DataType: () => DataType,
+  DataValidationError: () => DataValidationError,
+  DataValidator: () => DataValidator,
+  arrayTypeParser: () => arrayTypeParser,
+  arrayTypeValidator: () => arrayTypeValidator,
+  booleanTypeParser: () => booleanTypeParser,
+  booleanTypeValidator: () => booleanTypeValidator,
+  getDataTypeFromValue: () => getDataTypeFromValue,
+  numberTypeParser: () => numberTypeParser,
+  numberTypeValidator: () => numberTypeValidator,
+  objectTypeParser: () => objectTypeParser,
+  objectTypeValidator: () => objectTypeValidator,
+  requiredValueValidator: () => requiredValueValidator,
+  stringTypeParser: () => stringTypeParser,
+  stringTypeValidator: () => stringTypeValidator,
+  validateDataSchema: () => validateDataSchema,
+  validateDataSchemaDefinition: () => validateDataSchemaDefinition
+});
+module.exports = __toCommonJS(index_exports);
+
+// src/data-type.js
+var DataType = {
+  ANY: "any",
+  STRING: "string",
+  NUMBER: "number",
+  BOOLEAN: "boolean",
+  ARRAY: "array",
+  OBJECT: "object"
+};
+var DATA_TYPE_LIST = Object.values(DataType);
+function getDataTypeFromValue(value) {
+  if (value == null) return DataType.ANY;
+  const baseType = typeof value;
+  if (baseType === "string") return DataType.STRING;
+  if (baseType === "number") return DataType.NUMBER;
+  if (baseType === "boolean") return DataType.BOOLEAN;
+  if (Array.isArray(value)) return DataType.ARRAY;
+  if (baseType === "object") return DataType.OBJECT;
+  return DataType.ANY;
+}
+__name(getDataTypeFromValue, "getDataTypeFromValue");
+
+// src/data-parser.js
+var import_js_service15 = require("@e22m4u/js-service");
+
+// src/data-validator.js
+var import_js_service9 = require("@e22m4u/js-service");
+var import_js_format7 = require("@e22m4u/js-format");
+
+// src/data-schema-resolver.js
+var import_js_service2 = require("@e22m4u/js-service");
+var import_js_format4 = require("@e22m4u/js-format");
+
+// src/validate-data-schema.js
+var import_js_format = require("@e22m4u/js-format");
+function validateDataSchema(schema, shallowMode = false, validatedSchemas = /* @__PURE__ */ new Set()) {
+  if (typeof shallowMode !== "boolean") {
+    throw new import_js_format.InvalidArgumentError(
+      'Argument "shallowMode" must be a Boolean, but %v was given.',
+      shallowMode
+    );
+  }
+  if (!(validatedSchemas instanceof Set)) {
+    throw new import_js_format.InvalidArgumentError(
+      'Argument "validatedSchemas" must be an instance of Set, but %v was given.',
+      validatedSchemas
+    );
+  }
+  if (validatedSchemas.has(schema)) {
+    return;
+  }
+  if (!schema || typeof schema !== "object" && typeof schema !== "function" && typeof schema !== "string" || Array.isArray(schema)) {
+    throw new import_js_format.InvalidArgumentError(
+      "Data schema must be an Object, a Function or a non-empty String, but %v was given.",
+      schema
+    );
+  }
+  if (typeof schema !== "object") {
+    return;
+  }
+  validatedSchemas.add(schema);
+  if (schema.type !== void 0) {
+    if (!schema.type || !DATA_TYPE_LIST.includes(schema.type)) {
+      throw new import_js_format.InvalidArgumentError(
+        'Schema option "type" must be one of values: %l, but %v was given.',
+        DATA_TYPE_LIST,
+        schema.type
+      );
+    }
+  }
+  if (schema.items !== void 0) {
+    if (!schema.items || typeof schema.items !== "object" && typeof schema.items !== "function" && typeof schema.items !== "string" || Array.isArray(schema.items)) {
+      throw new import_js_format.InvalidArgumentError(
+        'Schema option "items" must be an Object, a Function or a non-empty String, but %v was given.',
+        schema.items
+      );
+    }
+    if (schema.type !== DataType.ARRAY) {
+      throw new import_js_format.InvalidArgumentError(
+        'Schema option "items" is only allowed for the "array" type, but %v was given.',
+        schema.type
+      );
+    }
+    if (!shallowMode && typeof schema.items === "object") {
+      validateDataSchema(schema.items, shallowMode, validatedSchemas);
+    }
+  }
+  if (schema.properties !== void 0) {
+    if (!schema.properties || typeof schema.properties !== "object" && typeof schema.properties !== "function" && typeof schema.properties !== "string" || Array.isArray(schema.properties)) {
+      throw new import_js_format.InvalidArgumentError(
+        'Schema option "properties" must be an Object, a Function or a non-empty String, but %v was given.',
+        schema.properties
+      );
+    }
+    if (schema.type !== DataType.OBJECT) {
+      throw new import_js_format.InvalidArgumentError(
+        'Schema option "properties" is only allowed for the "object" type, but %v was given.',
+        schema.type
+      );
+    }
+    if (typeof schema.properties === "object") {
+      Object.values(schema.properties).forEach((propSchema) => {
+        if (propSchema === void 0) {
+          return;
+        }
+        if (!propSchema || typeof propSchema !== "object" && typeof propSchema !== "function" && typeof propSchema !== "string" || Array.isArray(propSchema)) {
+          throw new import_js_format.InvalidArgumentError(
+            "Property schema must be an Object, a Function or a non-empty String, but %v was given.",
+            propSchema
+          );
+        }
+        if (!shallowMode && typeof propSchema === "object") {
+          validateDataSchema(propSchema, shallowMode, validatedSchemas);
+        }
+      });
+    }
+  }
+  if (schema.required !== void 0 && typeof schema.required !== "boolean") {
+    throw new import_js_format.InvalidArgumentError(
+      'Schema option "required" must be a Boolean, but %v was given.',
+      schema.required
+    );
+  }
+}
+__name(validateDataSchema, "validateDataSchema");
+
+// src/data-schema-registry.js
+var import_js_service = require("@e22m4u/js-service");
+var import_js_format3 = require("@e22m4u/js-format");
+
+// src/validate-data-schema-definition.js
+var import_js_format2 = require("@e22m4u/js-format");
+function validateDataSchemaDefinition(schemaDef) {
+  if (!schemaDef || typeof schemaDef !== "object" || Array.isArray(schemaDef)) {
+    throw new import_js_format2.InvalidArgumentError(
+      "Schema definition must be an Object, but %v was given.",
+      schemaDef
+    );
+  }
+  if (!schemaDef.name || typeof schemaDef.name !== "string") {
+    throw new import_js_format2.InvalidArgumentError(
+      'Definition option "name" must be a non-empty String, but %v was given.',
+      schemaDef.name
+    );
+  }
+  if (!schemaDef.schema || typeof schemaDef.schema !== "object" && typeof schemaDef.schema !== "function" && typeof schemaDef.schema !== "string" || Array.isArray(schemaDef.schema)) {
+    throw new import_js_format2.InvalidArgumentError(
+      'Definition option "schema" must be an Object, a Function or a non-empty String, but %v was given.',
+      schemaDef.schema
+    );
+  }
+  validateDataSchema(schemaDef.schema);
+}
+__name(validateDataSchemaDefinition, "validateDataSchemaDefinition");
+
+// src/data-schema-registry.js
+var _DataSchemaRegistry = class _DataSchemaRegistry extends import_js_service.Service {
+  /**
+   * Definitions.
+   *
+   * @type {Map<string, object>}
+   */
+  _definitions = /* @__PURE__ */ new Map();
+  /**
+   * Define schema.
+   *
+   * @param {object} schemaDef
+   * @returns {this}
+   */
+  defineSchema(schemaDef) {
+    validateDataSchemaDefinition(schemaDef);
+    if (this._definitions.has(schemaDef.name)) {
+      throw new import_js_format3.InvalidArgumentError(
+        "Data schema %v is already registered.",
+        schemaDef.name
+      );
+    }
+    this._definitions.set(schemaDef.name, schemaDef);
+    return this;
+  }
+  /**
+   * Has schema.
+   *
+   * @param {string} schemaName
+   * @returns {boolean}
+   */
+  hasSchema(schemaName) {
+    return this._definitions.has(schemaName);
+  }
+  /**
+   * Get schema.
+   *
+   * @param {string} schemaName
+   * @returns {object}
+   */
+  getSchema(schemaName) {
+    const schemaDef = this._definitions.get(schemaName);
+    if (!schemaDef) {
+      throw new import_js_format3.InvalidArgumentError(
+        "Data schema %v is not found.",
+        schemaName
+      );
+    }
+    return schemaDef.schema;
+  }
+  /**
+   * Get definition.
+   *
+   * @param {string} schemaName
+   * @returns {object}
+   */
+  getDefinition(schemaName) {
+    const schemaDef = this._definitions.get(schemaName);
+    if (!schemaDef) {
+      throw new import_js_format3.InvalidArgumentError(
+        "Schema definition %v is not found.",
+        schemaName
+      );
+    }
+    return schemaDef;
+  }
+};
+__name(_DataSchemaRegistry, "DataSchemaRegistry");
+var DataSchemaRegistry = _DataSchemaRegistry;
+
+// src/data-schema-resolver.js
+var _DataSchemaResolver = class _DataSchemaResolver extends import_js_service2.Service {
+  /**
+   * Resolve schema.
+   *
+   * @param {object|Function|string} schema
+   * @returns {object}
+   */
+  resolve(schema) {
+    if (typeof schema === "function") {
+      schema = schema(this.container);
+      if (!schema || typeof schema !== "object" && typeof schema !== "string" || Array.isArray(schema)) {
+        throw new import_js_format4.InvalidArgumentError(
+          "Schema factory must return an Object or a non-empty String, but %v was given.",
+          schema
+        );
+      }
+    }
+    if (schema && typeof schema === "string") {
+      schema = this.getService(DataSchemaRegistry).getSchema(schema);
+      if (!schema || typeof schema !== "object" && typeof schema !== "function" && typeof schema !== "string" || Array.isArray(schema)) {
+        throw new import_js_format4.InvalidArgumentError(
+          "Named schema must be an Object, a Function or a non-empty String, but %v was given.",
+          schema
+        );
+      }
+      if (typeof schema === "string" || typeof schema === "function") {
+        return this.resolve(schema);
+      }
+    }
+    validateDataSchema(schema, true);
+    return schema;
+  }
+};
+__name(_DataSchemaResolver, "DataSchemaResolver");
+var DataSchemaResolver = _DataSchemaResolver;
+
+// src/data-validators/array-type-validator.js
+var import_js_service3 = require("@e22m4u/js-service");
+
+// src/utils/to-pascal-case.js
+function toPascalCase(input) {
+  if (!input) return "";
+  return input.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([0-9])([a-zA-Z])/g, "$1 $2").replace(/[-_]+|[^\p{L}\p{N}]/gu, " ").toLowerCase().replace(new RegExp("(?:^|\\s)(\\p{L})", "gu"), (_, letter) => letter.toUpperCase()).replace(/\s+/g, "");
+}
+__name(toPascalCase, "toPascalCase");
+
+// src/errors/data-parsing-error.js
+var import_js_format5 = require("@e22m4u/js-format");
+var _DataParsingError = class _DataParsingError extends import_js_format5.InvalidArgumentError {
+  /**
+   * Value.
+   *
+   * @type {*}
+   */
+  value;
+  /**
+   * Target type.
+   *
+   * @type {string}
+   */
+  targetType;
+  /**
+   * Source path.
+   *
+   * @type {string|undefined}
+   */
+  sourcePath;
+  /**
+   * Constructor.
+   *
+   * @param {*} value
+   * @param {string} targetType
+   * @param {string} [sourcePath]
+   */
+  constructor(value, targetType, sourcePath) {
+    const targetTypePc = toPascalCase(targetType);
+    let message = "";
+    if (sourcePath) {
+      message = (0, import_js_format5.format)(
+        "Unable to parse %v from %v as %s.",
+        value,
+        sourcePath,
+        targetTypePc
+      );
+    } else {
+      message = (0, import_js_format5.format)("Unable to parse %v as %s.", value, targetTypePc);
+    }
+    super(message);
+    this.value = value;
+    this.targetType = targetType;
+    this.sourcePath = sourcePath;
+  }
+};
+__name(_DataParsingError, "DataParsingError");
+var DataParsingError = _DataParsingError;
+
+// src/errors/data-validation-error.js
+var import_js_format6 = require("@e22m4u/js-format");
+var _DataValidationError = class _DataValidationError extends import_js_format6.InvalidArgumentError {
+};
+__name(_DataValidationError, "DataValidationError");
+var DataValidationError = _DataValidationError;
+
+// src/data-validators/array-type-validator.js
+var import_js_empty_values = require("@e22m4u/js-empty-values");
+function arrayTypeValidator(value, schema, options, container) {
+  if (schema.type !== DataType.ARRAY) {
+    return;
+  }
+  const emptyValues = container.get(import_js_empty_values.EmptyValuesService);
+  const dataType = schema.type || DataType.ANY;
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return;
+  }
+  if (Array.isArray(value)) {
+    return;
+  }
+  const sourcePath = options && options.sourcePath;
+  if (sourcePath) {
+    throw new DataValidationError(
+      "Value of %v must be an Array, but %v was given.",
+      sourcePath,
+      value
+    );
+  } else {
+    throw new DataValidationError(
+      "Value must be an Array, but %v was given.",
+      value
+    );
+  }
+}
+__name(arrayTypeValidator, "arrayTypeValidator");
+
+// src/data-validators/object-type-validator.js
+var import_js_service4 = require("@e22m4u/js-service");
+var import_js_empty_values2 = require("@e22m4u/js-empty-values");
+function objectTypeValidator(value, schema, options, container) {
+  if (schema.type !== DataType.OBJECT) {
+    return;
+  }
+  const emptyValues = container.get(import_js_empty_values2.EmptyValuesService);
+  const dataType = schema.type || DataType.ANY;
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return;
+  }
+  if (value !== null && typeof value === "object" && !Array.isArray(value)) {
+    return;
+  }
+  const sourcePath = options && options.sourcePath;
+  if (sourcePath) {
+    throw new DataValidationError(
+      "Value of %v must be an Object, but %v was given.",
+      sourcePath,
+      value
+    );
+  } else {
+    throw new DataValidationError(
+      "Value must be an Object, but %v was given.",
+      value
+    );
+  }
+}
+__name(objectTypeValidator, "objectTypeValidator");
+
+// src/data-validators/string-type-validator.js
+var import_js_service5 = require("@e22m4u/js-service");
+var import_js_empty_values3 = require("@e22m4u/js-empty-values");
+function stringTypeValidator(value, schema, options, container) {
+  if (schema.type !== DataType.STRING) {
+    return;
+  }
+  const emptyValues = container.get(import_js_empty_values3.EmptyValuesService);
+  const dataType = schema.type || DataType.ANY;
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return;
+  }
+  if (typeof value === "string") {
+    return;
+  }
+  const sourcePath = options && options.sourcePath;
+  if (sourcePath) {
+    throw new DataValidationError(
+      "Value of %v must be a String, but %v was given.",
+      sourcePath,
+      value
+    );
+  } else {
+    throw new DataValidationError(
+      "Value must be a String, but %v was given.",
+      value
+    );
+  }
+}
+__name(stringTypeValidator, "stringTypeValidator");
+
+// src/data-validators/number-type-validator.js
+var import_js_service6 = require("@e22m4u/js-service");
+var import_js_empty_values4 = require("@e22m4u/js-empty-values");
+function numberTypeValidator(value, schema, options, container) {
+  if (schema.type !== DataType.NUMBER) {
+    return;
+  }
+  const emptyValues = container.get(import_js_empty_values4.EmptyValuesService);
+  const dataType = schema.type || DataType.ANY;
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return;
+  }
+  if (typeof value === "number") {
+    return;
+  }
+  const sourcePath = options && options.sourcePath;
+  if (sourcePath) {
+    throw new DataValidationError(
+      "Value of %v must be a Number, but %v was given.",
+      sourcePath,
+      value
+    );
+  } else {
+    throw new DataValidationError(
+      "Value must be a Number, but %v was given.",
+      value
+    );
+  }
+}
+__name(numberTypeValidator, "numberTypeValidator");
+
+// src/data-validators/boolean-type-validator.js
+var import_js_service7 = require("@e22m4u/js-service");
+var import_js_empty_values5 = require("@e22m4u/js-empty-values");
+function booleanTypeValidator(value, schema, options, container) {
+  if (schema.type !== DataType.BOOLEAN) {
+    return;
+  }
+  const emptyValues = container.get(import_js_empty_values5.EmptyValuesService);
+  const dataType = schema.type || DataType.ANY;
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return;
+  }
+  if (typeof value === "boolean") {
+    return;
+  }
+  const sourcePath = options && options.sourcePath;
+  if (sourcePath) {
+    throw new DataValidationError(
+      "Value of %v must be a Boolean, but %v was given.",
+      sourcePath,
+      value
+    );
+  } else {
+    throw new DataValidationError(
+      "Value must be a Boolean, but %v was given.",
+      value
+    );
+  }
+}
+__name(booleanTypeValidator, "booleanTypeValidator");
+
+// src/data-validators/required-value-validator.js
+var import_js_service8 = require("@e22m4u/js-service");
+var import_js_empty_values6 = require("@e22m4u/js-empty-values");
+function requiredValueValidator(value, schema, options, container) {
+  if (schema.required !== true) {
+    return;
+  }
+  const emptyValues = container.get(import_js_empty_values6.EmptyValuesService);
+  const dataType = schema.type || DataType.ANY;
+  if (!emptyValues.isEmptyByType(dataType, value)) {
+    return;
+  }
+  const sourcePath = options && options.sourcePath;
+  if (sourcePath) {
+    throw new DataValidationError(
+      "Value of %v is required, but %v was given.",
+      sourcePath,
+      value
+    );
+  } else {
+    throw new DataValidationError(
+      "Value is required, but %v was given.",
+      value
+    );
+  }
+}
+__name(requiredValueValidator, "requiredValueValidator");
+
+// src/data-validator.js
+var _DataValidator = class _DataValidator extends import_js_service9.Service {
+  /**
+   * Validators.
+   *
+   * @type {Function[]}
+   */
+  _validators = [
+    stringTypeValidator,
+    booleanTypeValidator,
+    numberTypeValidator,
+    objectTypeValidator,
+    arrayTypeValidator,
+    requiredValueValidator
+  ];
+  /**
+   * Get validators.
+   *
+   * @returns {Function[]}
+   */
+  getValidators() {
+    return [...this._validators];
+  }
+  /**
+   * Set validators.
+   *
+   * @param {Function[]} list
+   * @returns {this}
+   */
+  setValidators(list) {
+    if (!Array.isArray(list)) {
+      throw new import_js_format7.InvalidArgumentError(
+        "Data validators must be an Array, but %v was given.",
+        list
+      );
+    }
+    list.forEach((validator) => {
+      if (typeof validator !== "function") {
+        throw new import_js_format7.InvalidArgumentError(
+          "Data validator must be a Function, but %v was given.",
+          validator
+        );
+      }
+    });
+    this._validators = [...list];
+    return this;
+  }
+  /**
+   * Define schema.
+   *
+   * @param {object} schemaDef
+   * @returns {this}
+   */
+  defineSchema(schemaDef) {
+    this.getService(DataSchemaRegistry).defineSchema(schemaDef);
+    return this;
+  }
+  /**
+   * Has schema.
+   *
+   * @param {string} schemaName
+   * @returns {boolean}
+   */
+  hasSchema(schemaName) {
+    return this.getService(DataSchemaRegistry).hasSchema(schemaName);
+  }
+  /**
+   * Get schema.
+   *
+   * @param {string} schemaName
+   * @returns {object}
+   */
+  getSchema(schemaName) {
+    return this.getService(DataSchemaRegistry).getSchema(schemaName);
+  }
+  /**
+   * Validate.
+   *
+   * @param {*} value
+   * @param {object|Function|string} schema
+   * @param {object} [options]
+   */
+  validate(value, schema, options) {
+    if (options !== void 0) {
+      if (options === null || typeof options !== "object" || Array.isArray(options)) {
+        throw new import_js_format7.InvalidArgumentError(
+          "Validation options must be an Object, but %v was given.",
+          options
+        );
+      }
+      if (options.sourcePath !== void 0) {
+        if (!options.sourcePath || typeof options.sourcePath !== "string") {
+          throw new import_js_format7.InvalidArgumentError(
+            'Option "sourcePath" must be a non-empty String, but %v was given.',
+            options.sourcePath
+          );
+        }
+      }
+      if (options.shallowMode !== void 0) {
+        if (typeof options.shallowMode !== "boolean") {
+          throw new import_js_format7.InvalidArgumentError(
+            'Option "shallowMode" must be a Boolean, but %v was given.',
+            options.shallowMode
+          );
+        }
+      }
+    }
+    const sourcePath = options && options.sourcePath || void 0;
+    const shallowMode = Boolean(options && options.shallowMode);
+    validateDataSchema(schema, true);
+    const schemaResolver = this.getService(DataSchemaResolver);
+    if (typeof schema !== "object") {
+      schema = schemaResolver.resolve(schema);
+    }
+    this._validators.forEach((validate) => {
+      validate(value, schema, options, this.container);
+    });
+    if (shallowMode) {
+      return;
+    }
+    if (Array.isArray(value) && schema.items !== void 0) {
+      value.forEach((item, index) => {
+        const itemPath = (sourcePath || "array") + `[${index}]`;
+        const itemOptions = { ...options, sourcePath: itemPath };
+        this.validate(item, schema.items, itemOptions);
+      });
+    } else if (value !== null && typeof value === "object" && schema.properties !== void 0) {
+      let propsSchema = schema.properties;
+      if (typeof propsSchema !== "object") {
+        const resolvedSchema = schemaResolver.resolve(propsSchema);
+        if (resolvedSchema.type !== DataType.OBJECT) {
+          throw new import_js_format7.InvalidArgumentError(
+            'Unable to get the "properties" option from the data schema of %v type.',
+            resolvedSchema.type || DataType.ANY
+          );
+        }
+        propsSchema = resolvedSchema.properties || {};
+      }
+      Object.keys(propsSchema).forEach((propName) => {
+        const propSchema = propsSchema[propName];
+        if (propSchema === void 0) {
+          return;
+        }
+        const propValue = value[propName];
+        const propPath = sourcePath ? sourcePath + `.${propName}` : propName;
+        const propOptions = { ...options, sourcePath: propPath };
+        this.validate(propValue, propSchema, propOptions);
+      });
+    }
+  }
+};
+__name(_DataValidator, "DataValidator");
+var DataValidator = _DataValidator;
+
+// src/data-parser.js
+var import_js_format8 = require("@e22m4u/js-format");
+
+// src/data-parsers/array-type-parser.js
+var import_js_service10 = require("@e22m4u/js-service");
+var import_js_empty_values7 = require("@e22m4u/js-empty-values");
+function arrayTypeParser(value, schema, options, container) {
+  if (schema.type !== DataType.ARRAY) {
+    return value;
+  }
+  if (Array.isArray(value)) {
+    return value;
+  }
+  if (typeof value === "string") {
+    value = value.trim();
+    let newValue;
+    try {
+      newValue = JSON.parse(value);
+    } catch {
+    }
+    if (Array.isArray(newValue)) {
+      return newValue;
+    }
+  }
+  const dataType = schema.type || DataType.ANY;
+  const emptyValues = container.get(import_js_empty_values7.EmptyValuesService);
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return value;
+  }
+  if (!options || !options.noParsingErrors) {
+    const sourcePath = options && options.sourcePath;
+    throw new DataParsingError(value, dataType, sourcePath);
+  }
+  return value;
+}
+__name(arrayTypeParser, "arrayTypeParser");
+
+// src/data-parsers/string-type-parser.js
+var import_js_service11 = require("@e22m4u/js-service");
+var import_js_empty_values8 = require("@e22m4u/js-empty-values");
+function stringTypeParser(value, schema, options, container) {
+  if (schema.type !== DataType.STRING) {
+    return value;
+  }
+  if (typeof value === "string") {
+    return value;
+  }
+  if (typeof value === "number") {
+    return String(value);
+  }
+  const dataType = schema.type || DataType.ANY;
+  const emptyValues = container.get(import_js_empty_values8.EmptyValuesService);
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return value;
+  }
+  if (!options || !options.noParsingErrors) {
+    const sourcePath = options && options.sourcePath;
+    throw new DataParsingError(value, dataType, sourcePath);
+  }
+  return value;
+}
+__name(stringTypeParser, "stringTypeParser");
+
+// src/data-parsers/number-type-parser.js
+var import_js_service12 = require("@e22m4u/js-service");
+var import_js_empty_values9 = require("@e22m4u/js-empty-values");
+function numberTypeParser(value, schema, options, container) {
+  if (schema.type !== DataType.NUMBER) {
+    return value;
+  }
+  if (typeof value === "number") {
+    return value;
+  }
+  if (value && typeof value === "string") {
+    if (value.length <= 20) {
+      const newValue = Number(value.trim());
+      if (!isNaN(newValue)) {
+        return newValue;
+      }
+    }
+  }
+  const dataType = schema.type || DataType.ANY;
+  const emptyValues = container.get(import_js_empty_values9.EmptyValuesService);
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return value;
+  }
+  if (!options || !options.noParsingErrors) {
+    const sourcePath = options && options.sourcePath;
+    throw new DataParsingError(value, dataType, sourcePath);
+  }
+  return value;
+}
+__name(numberTypeParser, "numberTypeParser");
+
+// src/data-parsers/object-type-parser.js
+var import_js_service13 = require("@e22m4u/js-service");
+var import_js_empty_values10 = require("@e22m4u/js-empty-values");
+function objectTypeParser(value, schema, options, container) {
+  if (schema.type !== DataType.OBJECT) {
+    return value;
+  }
+  if (value !== null && typeof value === "object" && !Array.isArray(value)) {
+    return value;
+  }
+  if (typeof value === "string") {
+    value = value.trim();
+    let newValue;
+    try {
+      newValue = JSON.parse(value);
+    } catch {
+    }
+    if (newValue !== null && typeof newValue === "object" && !Array.isArray(newValue)) {
+      return newValue;
+    }
+  }
+  const dataType = schema.type || DataType.ANY;
+  const emptyValues = container.get(import_js_empty_values10.EmptyValuesService);
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return value;
+  }
+  if (!options || !options.noParsingErrors) {
+    const sourcePath = options && options.sourcePath;
+    throw new DataParsingError(value, dataType, sourcePath);
+  }
+  return value;
+}
+__name(objectTypeParser, "objectTypeParser");
+
+// src/data-parsers/boolean-type-parser.js
+var import_js_service14 = require("@e22m4u/js-service");
+var import_js_empty_values11 = require("@e22m4u/js-empty-values");
+function booleanTypeParser(value, schema, options, container) {
+  if (schema.type !== DataType.BOOLEAN) {
+    return value;
+  }
+  if (typeof value === "boolean") {
+    return value;
+  }
+  if (typeof value === "string") {
+    value = value.trim();
+    if (value === "1") return true;
+    if (value === "0") return false;
+    if (value === "true") return true;
+    if (value === "false") return false;
+  } else if (typeof value === "number") {
+    if (value === 1) return true;
+    if (value === 0) return false;
+  }
+  const dataType = schema.type || DataType.ANY;
+  const emptyValues = container.get(import_js_empty_values11.EmptyValuesService);
+  if (emptyValues.isEmptyByType(dataType, value)) {
+    return value;
+  }
+  if (!options || !options.noParsingErrors) {
+    const sourcePath = options && options.sourcePath;
+    throw new DataParsingError(value, dataType, sourcePath);
+  }
+  return value;
+}
+__name(booleanTypeParser, "booleanTypeParser");
+
+// src/data-parser.js
+var _DataParser = class _DataParser extends import_js_service15.Service {
+  /**
+   * Parsers.
+   *
+   * @type {Function[]}
+   */
+  _parsers = [
+    stringTypeParser,
+    booleanTypeParser,
+    numberTypeParser,
+    arrayTypeParser,
+    objectTypeParser
+  ];
+  /**
+   * Get parsers.
+   *
+   * @returns {Function[]}
+   */
+  getParsers() {
+    return [...this._parsers];
+  }
+  /**
+   * Set parsers.
+   *
+   * @param {Function[]} list
+   * @returns {this}
+   */
+  setParsers(list) {
+    if (!Array.isArray(list)) {
+      throw new import_js_format8.InvalidArgumentError(
+        "Data parsers must be an Array, but %v was given.",
+        list
+      );
+    }
+    list.forEach((parser) => {
+      if (typeof parser !== "function") {
+        throw new import_js_format8.InvalidArgumentError(
+          "Data parser must be a Function, but %v was given.",
+          parser
+        );
+      }
+    });
+    this._parsers = [...list];
+    return this;
+  }
+  /**
+   * Define schema.
+   *
+   * @param {object} schemaDef
+   * @returns {this}
+   */
+  defineSchema(schemaDef) {
+    this.getService(DataSchemaRegistry).defineSchema(schemaDef);
+    return this;
+  }
+  /**
+   * Has schema.
+   *
+   * @param {string} schemaName
+   * @returns {boolean}
+   */
+  hasSchema(schemaName) {
+    return this.getService(DataSchemaRegistry).hasSchema(schemaName);
+  }
+  /**
+   * Get schema.
+   *
+   * @param {string} schemaName
+   * @returns {object}
+   */
+  getSchema(schemaName) {
+    return this.getService(DataSchemaRegistry).getSchema(schemaName);
+  }
+  /**
+   * Parse.
+   *
+   * @param {*} value
+   * @param {object|Function|string} schema
+   * @param {object} [options]
+   * @returns {*}
+   */
+  parse(value, schema, options) {
+    if (options !== void 0) {
+      if (options === null || typeof options !== "object" || Array.isArray(options)) {
+        throw new import_js_format8.InvalidArgumentError(
+          "Parsing options must be an Object, but %v was given.",
+          options
+        );
+      }
+      if (options.sourcePath !== void 0) {
+        if (!options.sourcePath || typeof options.sourcePath !== "string") {
+          throw new import_js_format8.InvalidArgumentError(
+            'Option "sourcePath" must be a non-empty String, but %v was given.',
+            options.sourcePath
+          );
+        }
+      }
+      if (options.shallowMode !== void 0) {
+        if (typeof options.shallowMode !== "boolean") {
+          throw new import_js_format8.InvalidArgumentError(
+            'Option "shallowMode" must be a Boolean, but %v was given.',
+            options.shallowMode
+          );
+        }
+      }
+      if (options.noParsingErrors !== void 0) {
+        if (typeof options.noParsingErrors !== "boolean") {
+          throw new import_js_format8.InvalidArgumentError(
+            'Option "noParsingErrors" must be a Boolean, but %v was given.',
+            options.noParsingErrors
+          );
+        }
+      }
+    }
+    const sourcePath = options && options.sourcePath || void 0;
+    const shallowMode = Boolean(options && options.shallowMode);
+    const noParsingErrors = Boolean(options && options.noParsingErrors);
+    validateDataSchema(schema, true);
+    const schemaResolver = this.getService(DataSchemaResolver);
+    if (typeof schema !== "object") {
+      schema = schemaResolver.resolve(schema);
+    }
+    value = this._parsers.reduce((input, parser) => {
+      return parser(input, schema, options, this.container);
+    }, value);
+    if (!shallowMode) {
+      if (Array.isArray(value) && schema.items !== void 0) {
+        value = [...value];
+        value.forEach((item, index) => {
+          const itemPath = (sourcePath || "array") + `[${index}]`;
+          const itemOptions = { ...options, sourcePath: itemPath };
+          value[index] = this.parse(item, schema.items, itemOptions);
+        });
+      } else if (value !== null && typeof value === "object" && schema.properties !== void 0) {
+        let propsSchema = schema.properties;
+        value = { ...value };
+        if (typeof propsSchema !== "object") {
+          const resolvedSchema = schemaResolver.resolve(propsSchema);
+          if (resolvedSchema.type !== DataType.OBJECT) {
+            throw new import_js_format8.InvalidArgumentError(
+              'Unable to get the "properties" option from the data schema of %v type.',
+              resolvedSchema.type || DataType.ANY
+            );
+          }
+          propsSchema = resolvedSchema.properties || {};
+        }
+        Object.keys(propsSchema).forEach((propName) => {
+          const propSchema = propsSchema[propName];
+          if (propSchema === void 0) {
+            return;
+          }
+          const propValue = value[propName];
+          const propPath = sourcePath ? sourcePath + `.${propName}` : propName;
+          const propOptions = { ...options, sourcePath: propPath };
+          const newPropValue = this.parse(propValue, propSchema, propOptions);
+          if (value[propName] !== newPropValue) {
+            value[propName] = newPropValue;
+          }
+        });
+      }
+    }
+    if (!noParsingErrors) {
+      const validator = this.getService(DataValidator);
+      validator.validate(value, schema, { shallowMode: true });
+    }
+    return value;
+  }
+};
+__name(_DataParser, "DataParser");
+var DataParser = _DataParser;
+// Annotate the CommonJS export names for ESM import in node:
+0 && (module.exports = {
+  DATA_TYPE_LIST,
+  DataParser,
+  DataParsingError,
+  DataSchemaRegistry,
+  DataSchemaResolver,
+  DataType,
+  DataValidationError,
+  DataValidator,
+  arrayTypeParser,
+  arrayTypeValidator,
+  booleanTypeParser,
+  booleanTypeValidator,
+  getDataTypeFromValue,
+  numberTypeParser,
+  numberTypeValidator,
+  objectTypeParser,
+  objectTypeValidator,
+  requiredValueValidator,
+  stringTypeParser,
+  stringTypeValidator,
+  validateDataSchema,
+  validateDataSchemaDefinition
+});

+ 3 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@e22m4u/js-data-schema",
-  "version": "0.0.0",
+  "version": "0.0.1",
   "description": "JavaScript модуль для работы со схемой данных",
   "author": "Mikhail Evstropov <e22m4u@yandex.ru>",
   "license": "MIT",
@@ -48,8 +48,8 @@
     "@types/chai": "~5.2.3",
     "@types/mocha": "~10.0.10",
     "c8": "~10.1.3",
-    "chai": "~6.2.1",
-    "esbuild": "~0.27.1",
+    "chai": "~6.2.2",
+    "esbuild": "~0.27.2",
     "eslint": "~9.39.2",
     "eslint-config-prettier": "~10.1.8",
     "eslint-plugin-chai-expect": "~3.1.0",

+ 6 - 6
src/data-parser.js

@@ -67,8 +67,8 @@ export class DataParser extends Service {
 
   /**
    * Define schema.
-   * 
-   * @param {object} schemaDef 
+   *
+   * @param {object} schemaDef
    * @returns {this}
    */
   defineSchema(schemaDef) {
@@ -78,8 +78,8 @@ export class DataParser extends Service {
 
   /**
    * Has schema.
-   * 
-   * @param {string} schemaName 
+   *
+   * @param {string} schemaName
    * @returns {boolean}
    */
   hasSchema(schemaName) {
@@ -88,8 +88,8 @@ export class DataParser extends Service {
 
   /**
    * Get schema.
-   * 
-   * @param {string} schemaName 
+   *
+   * @param {string} schemaName
    * @returns {object}
    */
   getSchema(schemaName) {

+ 9 - 9
src/data-parser.spec.js

@@ -94,8 +94,8 @@ describe('DataParser', function () {
     });
   });
 
-  describe('defineSchema', function() {
-    it('should pass a given schema definition to the registry', function() {
+  describe('defineSchema', function () {
+    it('should pass a given schema definition to the registry', function () {
       const S = new DataParser();
       const registry = S.getService(DataSchemaRegistry);
       const schemaDef = {name: 'mySchema', schema: {}};
@@ -104,7 +104,7 @@ describe('DataParser', function () {
       expect(res).to.be.eql(schemaDef);
     });
 
-    it('should return a current instance', function() {
+    it('should return a current instance', function () {
       const S = new DataParser();
       const schemaDef = {name: 'mySchema', schema: {}};
       const res = S.defineSchema(schemaDef);
@@ -112,8 +112,8 @@ describe('DataParser', function () {
     });
   });
 
-  describe('hasSchema', function() {
-    it('should return true if a given name is registered', function() {
+  describe('hasSchema', function () {
+    it('should return true if a given name is registered', function () {
       const S = new DataParser();
       const schemaDef = {name: 'mySchema', schema: {}};
       expect(S.hasSchema(schemaDef.name)).to.be.false;
@@ -121,9 +121,9 @@ describe('DataParser', function () {
       expect(S.hasSchema(schemaDef.name)).to.be.true;
     });
   });
-  
-  describe('getSchema', function() {
-    it('should return a register schema for a given name', function() {
+
+  describe('getSchema', function () {
+    it('should return a register schema for a given name', function () {
       const S = new DataParser();
       const schemaDef = {name: 'mySchema', schema: {}};
       S.defineSchema(schemaDef);
@@ -131,7 +131,7 @@ describe('DataParser', function () {
       expect(res).to.be.eql(schemaDef.schema);
     });
 
-    it('should throw an error if a given name is not registered', function() {
+    it('should throw an error if a given name is not registered', function () {
       const S = new DataParser();
       const throwable = () => S.getSchema('mySchema');
       expect(throwable).to.throw('Data schema "mySchema" is not found.');

+ 4 - 1
src/data-parsers/boolean-type-parser.spec.js

@@ -71,7 +71,10 @@ describe('booleanTypeParser', function () {
 
   it('should convert a number value to a boolean when the boolean schema is given', function () {
     const container = new ServiceContainer();
-    const resMap = [[1, true], [0, false]];
+    const resMap = [
+      [1, true],
+      [0, false],
+    ];
     resMap.forEach(([value, expected]) => {
       const res = booleanTypeParser(
         value,

+ 5 - 5
src/data-parsers/index.js

@@ -1,5 +1,5 @@
-export * from './array-type-parser.js'
-export * from './string-type-parser.js'
-export * from './number-type-parser.js'
-export * from './object-type-parser.js'
-export * from './boolean-type-parser.js'
+export * from './array-type-parser.js';
+export * from './string-type-parser.js';
+export * from './number-type-parser.js';
+export * from './object-type-parser.js';
+export * from './boolean-type-parser.js';

+ 16 - 16
src/data-schema-registry.spec.js

@@ -1,9 +1,9 @@
-import {expect} from "chai";
-import {DataSchemaRegistry} from "./data-schema-registry.js";
+import {expect} from 'chai';
+import {DataSchemaRegistry} from './data-schema-registry.js';
 
-describe('DataSchemaRegistry', function() {
-  describe('defineSchema', function() {
-    it('should throw an error if the schema name is already registered', function() {
+describe('DataSchemaRegistry', function () {
+  describe('defineSchema', function () {
+    it('should throw an error if the schema name is already registered', function () {
       const S = new DataSchemaRegistry();
       const schemaDef = {name: 'mySchema', schema: {}};
       S.defineSchema(schemaDef);
@@ -13,7 +13,7 @@ describe('DataSchemaRegistry', function() {
       );
     });
 
-    it('should register the given definition', function() {
+    it('should register the given definition', function () {
       const S = new DataSchemaRegistry();
       const schemaDef = {name: 'mySchema', schema: {}};
       S.defineSchema(schemaDef);
@@ -21,15 +21,15 @@ describe('DataSchemaRegistry', function() {
       expect(res).to.be.eql(schemaDef);
     });
 
-    it('should return the current instance', function() {
+    it('should return the current instance', function () {
       const S = new DataSchemaRegistry();
       const res = S.defineSchema({name: 'mySchema', schema: {}});
       expect(res).to.be.eq(S);
     });
   });
 
-  describe('hasSchema', function() {
-    it('should return true if the given name is registered', function() {
+  describe('hasSchema', function () {
+    it('should return true if the given name is registered', function () {
       const S = new DataSchemaRegistry();
       const schemaDef = {name: 'mySchema', schema: {}};
       expect(S.hasSchema(schemaDef.name)).to.be.false;
@@ -38,14 +38,14 @@ describe('DataSchemaRegistry', function() {
     });
   });
 
-  describe('getSchema', function() {
-    it('should throw an error if the given name is not registered', function() {
+  describe('getSchema', function () {
+    it('should throw an error if the given name is not registered', function () {
       const S = new DataSchemaRegistry();
       const throwable = () => S.getSchema('mySchema');
       expect(throwable).to.throw('Data schema "mySchema" is not found.');
     });
 
-    it('should return the schema part of a registered definition for a given name', function() {
+    it('should return the schema part of a registered definition for a given name', function () {
       const S = new DataSchemaRegistry();
       const schemaDef = {name: 'mySchema', schema: {}};
       S.defineSchema(schemaDef);
@@ -54,14 +54,14 @@ describe('DataSchemaRegistry', function() {
     });
   });
 
-  describe('getDefinition', function() {
-    it('should throw an error if the given name is not registered', function() {
+  describe('getDefinition', function () {
+    it('should throw an error if the given name is not registered', function () {
       const S = new DataSchemaRegistry();
       const throwable = () => S.getDefinition('mySchema');
       expect(throwable).to.throw('Schema definition "mySchema" is not found.');
     });
-    
-    it('should return the registered definition for a given name', function() {
+
+    it('should return the registered definition for a given name', function () {
       const S = new DataSchemaRegistry();
       const schemaDef = {name: 'mySchema', schema: {}};
       S.defineSchema(schemaDef);

+ 11 - 10
src/data-schema-resolver.spec.js

@@ -19,7 +19,7 @@ describe('DataSchemaResolver', function () {
       expect(invoked).to.be.eq(1);
     });
 
-    it('should require a factory value to be an object or a non-empty string', function() {
+    it('should require a factory value to be an object or a non-empty string', function () {
       const S = new DataSchemaResolver();
       const registry = S.getService(DataSchemaRegistry);
       registry.defineSchema({name: 'mySchema', schema: {}});
@@ -49,7 +49,7 @@ describe('DataSchemaResolver', function () {
       expect(S.resolve('mySchema')).to.be.eq(schema);
     });
 
-    it('should require the schema registry return a valid value', function() {
+    it('should require the schema registry return a valid value', function () {
       const S = new DataSchemaResolver();
       const registry = S.getService(DataSchemaRegistry);
       const throwable = v => () => {
@@ -61,12 +61,13 @@ describe('DataSchemaResolver', function () {
           return v;
         };
         S.resolve('dummySchema');
-      }
-      const error = s => format(
-        'Named schema must be an Object, a Function ' +
-          'or a non-empty String, but %s was given.',
-        s,
-      );
+      };
+      const error = s =>
+        format(
+          'Named schema must be an Object, a Function ' +
+            'or a non-empty String, but %s was given.',
+          s,
+        );
       expect(throwable('')).to.throw(error('""'));
       expect(throwable(10)).to.throw(error('10'));
       expect(throwable(0)).to.throw(error('0'));
@@ -80,7 +81,7 @@ describe('DataSchemaResolver', function () {
       throwable(() => ({}))();
     });
 
-    it('should be able to resolve a name chain', function() {
+    it('should be able to resolve a name chain', function () {
       const S = new DataSchemaResolver();
       const schema = {type: DataType.ANY};
       const registry = S.getService(DataSchemaRegistry);
@@ -115,7 +116,7 @@ describe('DataSchemaResolver', function () {
       expect(invoked).to.be.eq(1);
     });
 
-    it('should return a given schema as is', function() {
+    it('should return a given schema as is', function () {
       const S = new DataSchemaResolver();
       const schema = {type: DataType.STRING};
       const res = S.resolve(schema);

+ 1 - 2
src/data-type.js

@@ -10,7 +10,6 @@ export const DataType = {
   OBJECT: 'object',
 };
 
-
 /**
  * Data type list.
  */
@@ -31,4 +30,4 @@ export function getDataTypeFromValue(value) {
   if (Array.isArray(value)) return DataType.ARRAY;
   if (baseType === 'object') return DataType.OBJECT;
   return DataType.ANY;
-}
+}

+ 6 - 6
src/data-validator.js

@@ -68,8 +68,8 @@ export class DataValidator extends Service {
 
   /**
    * Define schema.
-   * 
-   * @param {object} schemaDef 
+   *
+   * @param {object} schemaDef
    * @returns {this}
    */
   defineSchema(schemaDef) {
@@ -79,8 +79,8 @@ export class DataValidator extends Service {
 
   /**
    * Has schema.
-   * 
-   * @param {string} schemaName 
+   *
+   * @param {string} schemaName
    * @returns {boolean}
    */
   hasSchema(schemaName) {
@@ -89,8 +89,8 @@ export class DataValidator extends Service {
 
   /**
    * Get schema.
-   * 
-   * @param {string} schemaName 
+   *
+   * @param {string} schemaName
    * @returns {object}
    */
   getSchema(schemaName) {

+ 8 - 8
src/data-validator.spec.js

@@ -97,8 +97,8 @@ describe('DataValidator', function () {
     });
   });
 
-  describe('defineSchema', function() {
-    it('should pass a given schema definition to the registry', function() {
+  describe('defineSchema', function () {
+    it('should pass a given schema definition to the registry', function () {
       const S = new DataValidator();
       const registry = S.getService(DataSchemaRegistry);
       const schemaDef = {name: 'mySchema', schema: {}};
@@ -107,7 +107,7 @@ describe('DataValidator', function () {
       expect(res).to.be.eql(schemaDef);
     });
 
-    it('should return a current instance', function() {
+    it('should return a current instance', function () {
       const S = new DataValidator();
       const schemaDef = {name: 'mySchema', schema: {}};
       const res = S.defineSchema(schemaDef);
@@ -115,8 +115,8 @@ describe('DataValidator', function () {
     });
   });
 
-  describe('hasSchema', function() {
-    it('should return true if a given name is registered', function() {
+  describe('hasSchema', function () {
+    it('should return true if a given name is registered', function () {
       const S = new DataValidator();
       const schemaDef = {name: 'mySchema', schema: {}};
       expect(S.hasSchema(schemaDef.name)).to.be.false;
@@ -125,8 +125,8 @@ describe('DataValidator', function () {
     });
   });
 
-  describe('getSchema', function() {
-    it('should return a register schema for a given name', function() {
+  describe('getSchema', function () {
+    it('should return a register schema for a given name', function () {
       const S = new DataValidator();
       const schemaDef = {name: 'mySchema', schema: {}};
       S.defineSchema(schemaDef);
@@ -134,7 +134,7 @@ describe('DataValidator', function () {
       expect(res).to.be.eql(schemaDef.schema);
     });
 
-    it('should throw an error if a given name is not registered', function() {
+    it('should throw an error if a given name is not registered', function () {
       const S = new DataValidator();
       const throwable = () => S.getSchema('mySchema');
       expect(throwable).to.throw('Data schema "mySchema" is not found.');

+ 1 - 1
src/data-validators/index.js

@@ -3,4 +3,4 @@ export * from './object-type-validator.js';
 export * from './string-type-validator.js';
 export * from './number-type-validator.js';
 export * from './boolean-type-validator.js';
-export * from './required-value-validator.js';
+export * from './required-value-validator.js';

+ 1 - 1
src/errors/data-parsing-error.spec.js

@@ -4,7 +4,7 @@ import {DataParsingError} from './data-parsing-error.js';
 
 describe('DataParsingError', function () {
   describe('constructor', function () {
-    it('should set given arguments to instance properties', function() {
+    it('should set given arguments to instance properties', function () {
       const error = new DataParsingError(10, DataType.STRING, 'aSource');
       expect(error.value).to.be.eq(10);
       expect(error.targetType).to.be.eq(DataType.STRING);

+ 2 - 2
src/errors/data-validation-error.js

@@ -1,6 +1,6 @@
-import {InvalidArgumentError} from "@e22m4u/js-format";
+import {InvalidArgumentError} from '@e22m4u/js-format';
 
 /**
  * Data validation error.
  */
-export class DataValidationError extends InvalidArgumentError {}
+export class DataValidationError extends InvalidArgumentError {}

+ 1 - 1
src/validate-data-schema-definition.js

@@ -3,7 +3,7 @@ import {validateDataSchema} from './validate-data-schema.js';
 
 /**
  * Validate data schema definition.
- * 
+ *
  * @param {object} schemaDef
  */
 export function validateDataSchemaDefinition(schemaDef) {

+ 10 - 13
src/validate-data-schema.spec.js

@@ -7,10 +7,7 @@ describe('validateDataSchema', function () {
   it('should require the "shallowMode" argument to be a Boolean', function () {
     const throwable = v => () => validateDataSchema({}, v);
     const error = s =>
-      format(
-        'Argument "shallowMode" must be a Boolean, but %s was given.',
-        s,
-      );
+      format('Argument "shallowMode" must be a Boolean, but %s was given.', s);
     expect(throwable('str')).to.throw(error('"str"'));
     expect(throwable('')).to.throw(error('""'));
     expect(throwable(10)).to.throw(error('10'));
@@ -23,7 +20,7 @@ describe('validateDataSchema', function () {
     throwable(false)();
     throwable(undefined)();
   });
-  
+
   it('should require the "validatedSchemas" argument to be a Set instance', function () {
     const throwable = v => () => validateDataSchema({}, false, v);
     const error = s =>
@@ -46,7 +43,7 @@ describe('validateDataSchema', function () {
     throwable(undefined)();
   });
 
-  it('should skip validation if the given schema is already validated', function() {
+  it('should skip validation if the given schema is already validated', function () {
     const invalidSchema = {type: 'invalid'};
     const validatedSchemas = new Set([invalidSchema]);
     validateDataSchema(invalidSchema, undefined, validatedSchemas);
@@ -73,7 +70,7 @@ describe('validateDataSchema', function () {
     throwable(() => ({}))();
   });
 
-  it('should add the given schema to the validated schema set', function() {
+  it('should add the given schema to the validated schema set', function () {
     const schema = {type: DataType.ANY};
     const validatedSchemas = new Set();
     validateDataSchema(schema, undefined, validatedSchemas);
@@ -273,34 +270,34 @@ describe('validateDataSchema', function () {
     throwable(undefined)();
   });
 
-  it('should allow circular schema validation', function() {
+  it('should allow circular schema validation', function () {
     const schemaA = () => ({
       type: DataType.OBJECT,
       properties: {
         foo: schemaB(),
-      }
+      },
     });
     const schemaB = () => ({
       type: DataType.OBJECT,
       properties: {
         bar: schemaA(),
-      }
+      },
     });
     validateDataSchema(schemaA);
   });
 
-  it('should allow circular schema validation in the shallow mode', function() {
+  it('should allow circular schema validation in the shallow mode', function () {
     const schemaA = () => ({
       type: DataType.OBJECT,
       properties: {
         foo: schemaB(),
-      }
+      },
     });
     const schemaB = () => ({
       type: DataType.OBJECT,
       properties: {
         bar: schemaA(),
-      }
+      },
     });
     validateDataSchema(schemaA, true);
   });