Просмотр исходного кода

refactor: removes @e22m4u/js-empty-values

e22m4u 1 неделя назад
Родитель
Сommit
45f529fb8e

+ 73 - 70
README.md

@@ -9,7 +9,6 @@ JavaScript модуль для работы со схемой данных.
 - [Проверка данных](#проверка-данных)
 - [Проверка данных](#проверка-данных)
 - [Парсинг данных](#парсинг-данных)
 - [Парсинг данных](#парсинг-данных)
 - [Именованные схемы](#именованные-схемы)
 - [Именованные схемы](#именованные-схемы)
-- [Пустые значения](#пустые-значения)
 - [Тесты](#тесты)
 - [Тесты](#тесты)
 - [Лицензия](#лицензия)
 - [Лицензия](#лицензия)
 
 
@@ -41,10 +40,10 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
 
 
 Свойства схемы:
 Свойства схемы:
 
 
-- `type` тип данных (допускает [пустые значения](#пустые-значения));
+- `type` тип данных (см. таблицу ниже);
 - `items` схема элементов массива, фабрика или имя схемы;
 - `items` схема элементов массива, фабрика или имя схемы;
 - `properties` схема свойств объекта, фабрика или имя схемы;
 - `properties` схема свойств объекта, фабрика или имя схемы;
-- `required` исключает *пустые значения*;
+- `required` запрещает `undefined` и `null`;
 - `default` значение по умолчанию или фабрика;
 - `default` значение по умолчанию или фабрика;
 
 
 #### type
 #### type
@@ -65,7 +64,7 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
 #### items
 #### items
 
 
 Параметр `items` позволяет указать схему для элементов массива. Параметр можно
 Параметр `items` позволяет указать схему для элементов массива. Параметр можно
-использовать только если явно указан тип `array`. В примере ниже схема массива
+использовать, только если явно указан тип `array`. В примере ниже схема массива
 включает описание его элементов, которые должны соответствовать числовому типу.
 включает описание его элементов, которые должны соответствовать числовому типу.
 
 
 ```js
 ```js
@@ -75,22 +74,22 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
     type: DataType.NUMBER // тип элементов
     type: DataType.NUMBER // тип элементов
   }
   }
 }
 }
-// [-1, 0, 1, undefined, null]
+// [0, 1, 2, undefined, null]
 ```
 ```
 
 
-Так как типы допускают [пустые значения](#пустые-значения), рекомендуется
-использовать параметр `required` в определении схемы элемента, чтобы исключить
-такие значения из состава массива.
+Так как все типы допускают `undefined` и `null` в качестве пустых значений,
+рекомендуется использовать параметр `required` в определении схемы элемента,
+чтобы запретить данные значения в составе массива.
 
 
 ```js
 ```js
 {
 {
   type: DataType.ARRAY,
   type: DataType.ARRAY,
   items: {
   items: {
     type: DataType.NUMBER,
     type: DataType.NUMBER,
-    required: true // исключает undefined, null и 0
+    required: true // запрещает undefined, null
   }
   }
 }
 }
-// [-1, 1]
+// [0, 1, 2]
 ```
 ```
 
 
 #### properties
 #### properties
@@ -117,10 +116,9 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
 // }
 // }
 ```
 ```
 
 
-Значения свойств могут быть обязательными. Для этого используется
-параметр `required` в схеме соответствующего свойства. Если параметр
-указан, то [пустые значения](#пустые-значения) будут вызывать ошибку
-при проверке свойства.
+Свойства объекта могут быть обязательными. Для этого используется параметр
+`required` в схеме соответствующего свойства. Если параметр указан, то при
+проверке значений `undefined` и `null` будет выброшена ошибка.
 
 
 ```js
 ```js
 {
 {
@@ -128,11 +126,11 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
   properties: {
   properties: {
     name: {
     name: {
       type: DataType.STRING,
       type: DataType.STRING,
-      required: true // исключает undefined, null и ""
+      required: true // запрещает undefined и null
     },
     },
     age: {
     age: {
       type: DataType.NUMBER,
       type: DataType.NUMBER,
-      required: true // исключает undefined, null и 0
+      required: true // запрещает undefined и null
     }
     }
   }
   }
 }
 }
@@ -140,14 +138,14 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
 
 
 #### required
 #### required
 
 
-Так как по умолчанию все типы допускают [пустые значения](#пустые-значения),
-параметр `required` может быть полезен для явного их запрета при проверке
-данных. Параметр можно использовать там, где указывается тип данных.
+По умолчанию все типы допускают `undefined` и `null` в качестве пустых
+значений. Параметр `required` может быть использован для явного запрета
+таких значений при проверке данных.
 
 
 ```js
 ```js
 {
 {
   type: DataType.STRING, // тип данных
   type: DataType.STRING, // тип данных
-  required: true         // исключает пустые значения
+  required: true         // запрещает undefined и null
 }
 }
 // "foo", "bar" ...
 // "foo", "bar" ...
 ```
 ```
@@ -155,9 +153,8 @@ const {DataValidator} = require('@e22m4u/js-data-schema');
 #### default
 #### default
 
 
 Значение по умолчанию можно указать в параметре `default`. Указанное значение
 Значение по умолчанию можно указать в параметре `default`. Указанное значение
-будет использовано, если исходное значение оказалось [пустым](#пустые-значения).
-Если значение параметра является объектом или массивом, то итоговые данных
-получат его копию.
+будет использовано вместо `undefined` и `null`. Если значение параметра
+является объектом или массивом, то итоговые данные получат его копию.
 
 
 ```js
 ```js
 {
 {
@@ -191,9 +188,9 @@ validator.validate([1, 2, 3], numberSchema);
 validator.validate({foo: 'bar'}, numberSchema);
 validator.validate({foo: 'bar'}, numberSchema);
 ```
 ```
 
 
-Каждый тип данных имеет собственный набор [пустых значений](#пустые-значения),
-которые являются допустимыми при проверке соответствующего типа. Чтобы исключить
-такие значения применяется параметр `required`.
+Как видно из примера выше, `undefined` и `null` являются допустимыми значениями,
+несмотря на указанный тип данных. Чтобы изменить это поведение, используется
+параметр `required`, запрещая пустые значения для данной схемы.
 
 
 ```js
 ```js
 import {DataValidator, DataType} from '@e22m4u/js-data-schema';
 import {DataValidator, DataType} from '@e22m4u/js-data-schema';
@@ -202,15 +199,15 @@ const validator = new DataValidator();
 
 
 const requiredNumberSchema = {
 const requiredNumberSchema = {
   type: DataType.NUMBER,
   type: DataType.NUMBER,
-  required: true // исключает пустые значения
+  required: true // запрещает undefined и null
 };
 };
 
 
 // OK
 // OK
 validator.validate(10, requiredNumberSchema);
 validator.validate(10, requiredNumberSchema);
+validator.validate(0, requiredNumberSchema);
 validator.validate(-10, requiredNumberSchema);
 validator.validate(-10, requiredNumberSchema);
 
 
 // выбросит DataValidationError
 // выбросит DataValidationError
-validator.validate(0, requiredNumberSchema);
 validator.validate(undefined, requiredNumberSchema);
 validator.validate(undefined, requiredNumberSchema);
 validator.validate(null, requiredNumberSchema);
 validator.validate(null, requiredNumberSchema);
 ```
 ```
@@ -218,9 +215,9 @@ validator.validate(null, requiredNumberSchema);
 ## Парсинг данных
 ## Парсинг данных
 
 
 Сервис `DataParser` спроектирован для приведения данных в соответствие
 Сервис `DataParser` спроектирован для приведения данных в соответствие
-указанной схеме. Приведение выполняется с учетом возможных ошибок
-пользовательского ввода. К примеру, если схема ожидает число, но входящие
-данные содержат другие символы, то будет выброшена ошибка.
+указанной схеме. Приведение выполняется с учетом возможных ошибок ввода.
+К примеру, если схема ожидает число, но входящие данные содержат буквы,
+то будет выброшена ошибка.
 
 
 ```js
 ```js
 import {DataParser, DataType} from '@e22m4u/js-data-schema';
 import {DataParser, DataType} from '@e22m4u/js-data-schema';
@@ -246,7 +243,7 @@ const numberListSchema = {
   type: DataType.ARRAY,
   type: DataType.ARRAY,
   items: {
   items: {
     type: DataType.NUMBER,
     type: DataType.NUMBER,
-    required: true, // исключает undefined, null и 0
+    required: true, // запрещает undefined и null
   },
   },
 };
 };
 
 
@@ -254,9 +251,9 @@ parser.parse('[1, 2, 3]', numberListSchema);    // [1, 2, 3]
 parser.parse('[1, 2, null]', numberListSchema); // DataParsingError
 parser.parse('[1, 2, null]', numberListSchema); // DataParsingError
 ```
 ```
 
 
-Если при разборе данных значение оказалось [пустым](#пустые-значения),
-то при наличии параметра `default` используется значение по умолчанию.
-Значение данного параметра должно соответствовать схеме.
+При разборе данных учитывается параметр `default`. Если исходным значением
+является `undefined` или `null`, то будет использовано значение по умолчанию.
+Значение данного параметра должно соответствовать указанному типу.
 
 
 ```js
 ```js
 import {DataParser, DataType} from '@e22m4u/js-data-schema';
 import {DataParser, DataType} from '@e22m4u/js-data-schema';
@@ -265,14 +262,35 @@ const parser = new DataParser();
 
 
 const schema = {
 const schema = {
   type: DataType.NUMBER,
   type: DataType.NUMBER,
-  default: 0,
+  default: 5,
 };
 };
 
 
 parser.parse('10', schema);      // 10
 parser.parse('10', schema);      // 10
-parser.parse(undefined, schema); // 0
+parser.parse(undefined, schema); // 5
 parser.parse('N/A', schema);     // DataParsingError
 parser.parse('N/A', schema);     // DataParsingError
 ```
 ```
 
 
+Подмену исходных значений на значения по умолчанию можно отключить, если
+передать параметр `noDefaultValues` в настройки метода `parse`, как это
+показано ниже.
+
+```js
+import {DataParser, DataType} from '@e22m4u/js-data-schema';
+
+const parser = new DataParser();
+
+const schema = {
+  type: DataType.NUMBER,
+  default: 5,
+};
+
+// используется значение по умолчанию
+parser.parse(undefined, schema); // 5
+
+// с параметром "noDefaultValues" значение по умолчанию игнорируется
+parser.parse(undefined, schema, {noDefaultValues: true}); // undefined
+```
+
 Если схема объекта содержит параметр `properties`, то свойства исходного
 Если схема объекта содержит параметр `properties`, то свойства исходного
 объекта, не описанные в схеме, исключаются из результата. Итоговый объект
 объекта, не описанные в схеме, исключаются из результата. Итоговый объект
 будет содержать только те свойства, которые были определены явно.
 будет содержать только те свойства, которые были определены явно.
@@ -298,9 +316,9 @@ console.log(result);
 // {"name": "Fedor"}
 // {"name": "Fedor"}
 ```
 ```
 
 
-При указании схемы свойств, неизвестные свойства будут отброшены. Чтобы
-изменить это поведение, используется параметр `keepUnknownProperties`,
-который позволяет сохранить все свойства исходного объекта.
+Чтобы избежать удаления свойств, не указанных в схеме данных, используется
+параметр `keepUnknownProperties`, который позволяет сохранить все свойства
+исходного объекта.
 
 
 ```js
 ```js
 const schema = {
 const schema = {
@@ -319,16 +337,16 @@ const data = {
 parser.parse(data, schema);
 parser.parse(data, schema);
 // {id: 1}
 // {id: 1}
 
 
-// с опцией "keepUnknownProperties" свойства сохраняются
+// с параметром "keepUnknownProperties" свойства сохраняются
 parser.parse(data, schema, {keepUnknownProperties: true});
 parser.parse(data, schema, {keepUnknownProperties: true});
 // {id: 1, role: 'admin'}
 // {id: 1, role: 'admin'}
 ```
 ```
 
 
 ## Именованные схемы
 ## Именованные схемы
 
 
-Модуль экспортирует сервисы для проверки и парсинга данных. Каждый
-сервис позволяет регистрировать схемы данных по уникальному имени
етодом `defineSchema`.
+Сервисы для проверки и парсинга данных позволяют регистрировать схемы данных
+по уникальному имени методом `defineSchema`. В дальнейшем именованные схемы
огут быть использованы вместо объекта схемы аналогичным образом.
 
 
 ```js
 ```js
 import {DataValidator, DataParser, DataType} from '@e22m4u/js-data-schema';
 import {DataValidator, DataParser, DataType} from '@e22m4u/js-data-schema';
@@ -348,8 +366,9 @@ validator.defineSchema({name: 'mySchema', schema});
 parser.defineSchema({name: 'mySchema', schema});
 parser.defineSchema({name: 'mySchema', schema});
 ```
 ```
 
 
-Регистрация схем может выполняться централизованно через реестр. Этого можно
-добиться используя сервис-контейнер, который выступает в роли точки входа.
+Регистрация схем может выполняться централизованно через встроенный реестр.
+Этого можно добиться, используя сервис-контейнер, который выступает в роли
+точки входа в приложение.
 
 
 ```js
 ```js
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
@@ -361,8 +380,8 @@ import {
   DataSchemaRegistry,
   DataSchemaRegistry,
 } from '@e22m4u/js-data-schema';
 } from '@e22m4u/js-data-schema';
 
 
-const app = new ServiceContainer();
-const registry = app.get(DataSchemaRegistry);
+const app = new ServiceContainer();           // сервис-контейнер
+const registry = app.get(DataSchemaRegistry); // реестр схем данных
 
 
 registry.defineSchema({
 registry.defineSchema({
   name: 'mySchema',
   name: 'mySchema',
@@ -375,6 +394,8 @@ registry.defineSchema({
   },
   },
 });
 });
 
 
+// порядок доступа к сервисам и порядок
+// регистрации схем значения не имеет
 const validator = app.get(DataValidator);
 const validator = app.get(DataValidator);
 const parser = app.get(DataParser);
 const parser = app.get(DataParser);
 ```
 ```
@@ -385,12 +406,13 @@ const parser = app.get(DataParser);
 
 
 #### Использование именованных схем
 #### Использование именованных схем
 
 
-Зарегистрированное имя схемы можно использовать вместо объекта схемы. Пример
-ниже демонстрирует проверку данных с помощью именованной схемы.
+Зарегистрированное имя можно использовать вместо объекта схемы. Пример ниже
+демонстрирует регистрацию схемы `mySchema` и проверку массива с помощью
+данного имени.
 
 
 ```js
 ```js
 validator.defineSchema({
 validator.defineSchema({
-  name: 'stringList',
+  name: 'mySchema',
   schema: {
   schema: {
     type: DataType.STRING,
     type: DataType.STRING,
     required: true,
     required: true,
@@ -454,25 +476,6 @@ validator.validate(data, {
 });
 });
 ```
 ```
 
 
-## Пустые значения
-
-Разные типы данных имеют свои наборы пустых значений. Эти наборы используются
-для определения наличия полезной нагрузки в значении свойства. Например,
-параметр `required` исключает пустые значения при проверке данных. 
-
-| тип данных         | пустые значения            |
-|--------------------|----------------------------|
-| `DataType.ANY`     | *значения остальных типов* |
-| `DataType.STRING`  | `undefined`, `null`, `""`  |
-| `DataType.NUMBER`  | `undefined`, `null`, `0`   |
-| `DataType.BOOLEAN` | `undefined`, `null`        |
-| `DataType.ARRAY`   | `undefined`, `null`, `[]`  |
-| `DataType.OBJECT`  | `undefined`, `null`, `{}`  |
-
-Управление этими наборами осуществляется через специальный сервис, который предоставляет модуль
-[@e22m4u/js-empty-values](https://www.npmjs.com/package/@e22m4u/js-empty-values)
-(не требует установки).
-
 ## Тесты
 ## Тесты
 
 
 ```bash
 ```bash

+ 34 - 78
dist/cjs/index.cjs

@@ -70,10 +70,10 @@ function getDataTypeFromValue(value) {
 __name(getDataTypeFromValue, "getDataTypeFromValue");
 __name(getDataTypeFromValue, "getDataTypeFromValue");
 
 
 // src/data-parser.js
 // src/data-parser.js
-var import_js_service16 = require("@e22m4u/js-service");
+var import_js_service5 = require("@e22m4u/js-service");
 
 
 // src/data-validator.js
 // src/data-validator.js
-var import_js_service9 = require("@e22m4u/js-service");
+var import_js_service3 = require("@e22m4u/js-service");
 var import_js_format7 = require("@e22m4u/js-format");
 var import_js_format7 = require("@e22m4u/js-format");
 
 
 // src/data-schema-resolver.js
 // src/data-schema-resolver.js
@@ -311,9 +311,6 @@ var DataSchemaResolver = class extends import_js_service2.Service {
   }
   }
 };
 };
 
 
-// src/data-validators/array-type-validator.js
-var import_js_service3 = require("@e22m4u/js-service");
-
 // src/utils/to-pascal-case.js
 // src/utils/to-pascal-case.js
 function toPascalCase(input) {
 function toPascalCase(input) {
   if (!input) return "";
   if (!input) return "";
@@ -381,14 +378,11 @@ var DataValidationError = class extends import_js_format6.InvalidArgumentError {
 };
 };
 
 
 // src/data-validators/array-type-validator.js
 // src/data-validators/array-type-validator.js
-var import_js_empty_values = require("@e22m4u/js-empty-values");
-function arrayTypeValidator(value, schema, options, container) {
+function arrayTypeValidator(value, schema, options) {
   if (schema.type !== DataType.ARRAY) {
   if (schema.type !== DataType.ARRAY) {
     return;
     return;
   }
   }
-  const emptyValues = container.get(import_js_empty_values.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   if (Array.isArray(value)) {
   if (Array.isArray(value)) {
@@ -411,15 +405,11 @@ function arrayTypeValidator(value, schema, options, container) {
 __name(arrayTypeValidator, "arrayTypeValidator");
 __name(arrayTypeValidator, "arrayTypeValidator");
 
 
 // src/data-validators/object-type-validator.js
 // 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) {
+function objectTypeValidator(value, schema, options) {
   if (schema.type !== DataType.OBJECT) {
   if (schema.type !== DataType.OBJECT) {
     return;
     return;
   }
   }
-  const emptyValues = container.get(import_js_empty_values2.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   if (value !== null && typeof value === "object" && !Array.isArray(value)) {
   if (value !== null && typeof value === "object" && !Array.isArray(value)) {
@@ -442,15 +432,11 @@ function objectTypeValidator(value, schema, options, container) {
 __name(objectTypeValidator, "objectTypeValidator");
 __name(objectTypeValidator, "objectTypeValidator");
 
 
 // src/data-validators/string-type-validator.js
 // 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) {
+function stringTypeValidator(value, schema, options) {
   if (schema.type !== DataType.STRING) {
   if (schema.type !== DataType.STRING) {
     return;
     return;
   }
   }
-  const emptyValues = container.get(import_js_empty_values3.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   if (typeof value === "string") {
   if (typeof value === "string") {
@@ -473,15 +459,11 @@ function stringTypeValidator(value, schema, options, container) {
 __name(stringTypeValidator, "stringTypeValidator");
 __name(stringTypeValidator, "stringTypeValidator");
 
 
 // src/data-validators/number-type-validator.js
 // 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) {
+function numberTypeValidator(value, schema, options) {
   if (schema.type !== DataType.NUMBER) {
   if (schema.type !== DataType.NUMBER) {
     return;
     return;
   }
   }
-  const emptyValues = container.get(import_js_empty_values4.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   if (typeof value === "number") {
   if (typeof value === "number") {
@@ -504,15 +486,11 @@ function numberTypeValidator(value, schema, options, container) {
 __name(numberTypeValidator, "numberTypeValidator");
 __name(numberTypeValidator, "numberTypeValidator");
 
 
 // src/data-validators/boolean-type-validator.js
 // 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) {
+function booleanTypeValidator(value, schema, options) {
   if (schema.type !== DataType.BOOLEAN) {
   if (schema.type !== DataType.BOOLEAN) {
     return;
     return;
   }
   }
-  const emptyValues = container.get(import_js_empty_values5.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   if (typeof value === "boolean") {
   if (typeof value === "boolean") {
@@ -535,15 +513,11 @@ function booleanTypeValidator(value, schema, options, container) {
 __name(booleanTypeValidator, "booleanTypeValidator");
 __name(booleanTypeValidator, "booleanTypeValidator");
 
 
 // src/data-validators/required-value-validator.js
 // 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) {
+function requiredValueValidator(value, schema, options) {
   if (schema.required !== true) {
   if (schema.required !== true) {
     return;
     return;
   }
   }
-  const emptyValues = container.get(import_js_empty_values6.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (!emptyValues.isEmptyOf(dataType, value)) {
+  if (value != null) {
     return;
     return;
   }
   }
   const sourcePath = options && options.sourcePath;
   const sourcePath = options && options.sourcePath;
@@ -563,7 +537,7 @@ function requiredValueValidator(value, schema, options, container) {
 __name(requiredValueValidator, "requiredValueValidator");
 __name(requiredValueValidator, "requiredValueValidator");
 
 
 // src/data-validator.js
 // src/data-validator.js
-var DataValidator = class extends import_js_service9.Service {
+var DataValidator = class extends import_js_service3.Service {
   static {
   static {
     __name(this, "DataValidator");
     __name(this, "DataValidator");
   }
   }
@@ -721,9 +695,7 @@ var DataValidator = class extends import_js_service9.Service {
 var import_js_format8 = require("@e22m4u/js-format");
 var import_js_format8 = require("@e22m4u/js-format");
 
 
 // src/data-parsers/array-type-parser.js
 // 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) {
+function arrayTypeParser(value, schema, options) {
   if (schema.type !== DataType.ARRAY) {
   if (schema.type !== DataType.ARRAY) {
     return value;
     return value;
   }
   }
@@ -741,13 +713,12 @@ function arrayTypeParser(value, schema, options, container) {
       return newValue;
       return newValue;
     }
     }
   }
   }
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(import_js_empty_values7.EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   return value;
   return value;
@@ -755,9 +726,7 @@ function arrayTypeParser(value, schema, options, container) {
 __name(arrayTypeParser, "arrayTypeParser");
 __name(arrayTypeParser, "arrayTypeParser");
 
 
 // src/data-parsers/string-type-parser.js
 // 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) {
+function stringTypeParser(value, schema, options) {
   if (schema.type !== DataType.STRING) {
   if (schema.type !== DataType.STRING) {
     return value;
     return value;
   }
   }
@@ -767,13 +736,12 @@ function stringTypeParser(value, schema, options, container) {
   if (typeof value === "number") {
   if (typeof value === "number") {
     return String(value);
     return String(value);
   }
   }
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(import_js_empty_values8.EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   return value;
   return value;
@@ -781,16 +749,14 @@ function stringTypeParser(value, schema, options, container) {
 __name(stringTypeParser, "stringTypeParser");
 __name(stringTypeParser, "stringTypeParser");
 
 
 // src/data-parsers/number-type-parser.js
 // 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) {
+function numberTypeParser(value, schema, options) {
   if (schema.type !== DataType.NUMBER) {
   if (schema.type !== DataType.NUMBER) {
     return value;
     return value;
   }
   }
   if (typeof value === "number") {
   if (typeof value === "number") {
     return value;
     return value;
   }
   }
-  if (value && typeof value === "string") {
+  if (typeof value === "string" && value.trim() !== "") {
     if (value.length <= 20) {
     if (value.length <= 20) {
       const newValue = Number(value.trim());
       const newValue = Number(value.trim());
       if (!isNaN(newValue)) {
       if (!isNaN(newValue)) {
@@ -798,13 +764,12 @@ function numberTypeParser(value, schema, options, container) {
       }
       }
     }
     }
   }
   }
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(import_js_empty_values9.EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   return value;
   return value;
@@ -812,9 +777,7 @@ function numberTypeParser(value, schema, options, container) {
 __name(numberTypeParser, "numberTypeParser");
 __name(numberTypeParser, "numberTypeParser");
 
 
 // src/data-parsers/object-type-parser.js
 // 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) {
+function objectTypeParser(value, schema, options) {
   if (schema.type !== DataType.OBJECT) {
   if (schema.type !== DataType.OBJECT) {
     return value;
     return value;
   }
   }
@@ -832,13 +795,12 @@ function objectTypeParser(value, schema, options, container) {
       return newValue;
       return newValue;
     }
     }
   }
   }
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(import_js_empty_values10.EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   return value;
   return value;
@@ -846,9 +808,7 @@ function objectTypeParser(value, schema, options, container) {
 __name(objectTypeParser, "objectTypeParser");
 __name(objectTypeParser, "objectTypeParser");
 
 
 // src/data-parsers/boolean-type-parser.js
 // 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) {
+function booleanTypeParser(value, schema, options) {
   if (schema.type !== DataType.BOOLEAN) {
   if (schema.type !== DataType.BOOLEAN) {
     return value;
     return value;
   }
   }
@@ -865,13 +825,12 @@ function booleanTypeParser(value, schema, options, container) {
     if (value === 1) return true;
     if (value === 1) return true;
     if (value === 0) return false;
     if (value === 0) return false;
   }
   }
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(import_js_empty_values11.EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   return value;
   return value;
@@ -879,8 +838,7 @@ function booleanTypeParser(value, schema, options, container) {
 __name(booleanTypeParser, "booleanTypeParser");
 __name(booleanTypeParser, "booleanTypeParser");
 
 
 // src/data-parsers/default-value-setter.js
 // src/data-parsers/default-value-setter.js
-var import_js_service15 = require("@e22m4u/js-service");
-var import_js_empty_values12 = require("@e22m4u/js-empty-values");
+var import_js_service4 = require("@e22m4u/js-service");
 function defaultValueSetter(value, schema, options, container) {
 function defaultValueSetter(value, schema, options, container) {
   if (options && options.noDefaultValues) {
   if (options && options.noDefaultValues) {
     return value;
     return value;
@@ -888,9 +846,7 @@ function defaultValueSetter(value, schema, options, container) {
   if (schema.default === void 0) {
   if (schema.default === void 0) {
     return value;
     return value;
   }
   }
-  const emptyValues = container.get(import_js_empty_values12.EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (!emptyValues.isEmptyOf(dataType, value)) {
+  if (value != null) {
     return value;
     return value;
   }
   }
   if (typeof schema.default === "function") {
   if (typeof schema.default === "function") {
@@ -901,7 +857,7 @@ function defaultValueSetter(value, schema, options, container) {
 __name(defaultValueSetter, "defaultValueSetter");
 __name(defaultValueSetter, "defaultValueSetter");
 
 
 // src/data-parser.js
 // src/data-parser.js
-var DataParser = class extends import_js_service16.Service {
+var DataParser = class extends import_js_service5.Service {
   static {
   static {
     __name(this, "DataParser");
     __name(this, "DataParser");
   }
   }

+ 0 - 1
package.json

@@ -37,7 +37,6 @@
     "prepare": "husky"
     "prepare": "husky"
   },
   },
   "dependencies": {
   "dependencies": {
-    "@e22m4u/js-empty-values": "~0.3.2",
     "@e22m4u/js-format": "~0.3.2",
     "@e22m4u/js-format": "~0.3.2",
     "@e22m4u/js-service": "~0.5.1"
     "@e22m4u/js-service": "~0.5.1"
   },
   },

+ 4 - 8
src/data-parsers/array-type-parser.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Array type parser.
  * Array type parser.
@@ -9,10 +7,9 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  * @returns {*}
  * @returns {*}
  */
  */
-export function arrayTypeParser(value, schema, options, container) {
+export function arrayTypeParser(value, schema, options) {
   // если тип не соответствует массиву,
   // если тип не соответствует массиву,
   // то преобразование пропускается
   // то преобразование пропускается
   if (schema.type !== DataType.ARRAY) {
   if (schema.type !== DataType.ARRAY) {
@@ -37,17 +34,16 @@ export function arrayTypeParser(value, schema, options, container) {
       return newValue;
       return newValue;
     }
     }
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то преобразование пропускается
   // то преобразование пропускается
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   // если преобразовать значение не удалось,
   // если преобразовать значение не удалось,
   // то выбрасывается ошибка
   // то выбрасывается ошибка
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   // если установлен флаг бесшумной работы,
   // если установлен флаг бесшумной работы,

+ 13 - 14
src/data-parsers/array-type-parser.spec.js

@@ -3,7 +3,6 @@ import {DataParsingError} from '../errors/index.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {arrayTypeParser} from './array-type-parser.js';
 import {arrayTypeParser} from './array-type-parser.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 describe('arrayTypeParser', function () {
 describe('arrayTypeParser', function () {
   it('should return a value as is when a non-array schema is given', function () {
   it('should return a value as is when a non-array schema is given', function () {
@@ -19,7 +18,7 @@ describe('arrayTypeParser', function () {
     dataTypes.forEach(parse);
     dataTypes.forEach(parse);
   });
   });
 
 
-  it('should return an array value as is when the array schema is given', function () {
+  it('should return an array value as is when an array schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value = [];
     const value = [];
     const res = arrayTypeParser(
     const res = arrayTypeParser(
@@ -31,7 +30,7 @@ describe('arrayTypeParser', function () {
     expect(res).to.be.eq(value);
     expect(res).to.be.eq(value);
   });
   });
 
 
-  it('should parse a json string when the array schema is given', function () {
+  it('should parse a json string when an array schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value = '[1, 2, 3]';
     const value = '[1, 2, 3]';
     const res = arrayTypeParser(
     const res = arrayTypeParser(
@@ -43,20 +42,20 @@ describe('arrayTypeParser', function () {
     expect(res).to.be.eql([1, 2, 3]);
     expect(res).to.be.eql([1, 2, 3]);
   });
   });
 
 
-  it('should return an empty value as is when the array schema is given', function () {
+  it('should return a nullish value as is when an array schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ARRAY, [undefined]);
-    const res = arrayTypeParser(
-      undefined,
-      {type: DataType.ARRAY},
-      undefined,
-      container,
-    );
-    expect(res).to.be.undefined;
+    [undefined, null].forEach(value => {
+      const res = arrayTypeParser(
+        value,
+        {type: DataType.ARRAY},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should throw an error for a non-array value when the array schema is given', function () {
+  it('should throw an error for a non-array value when an array schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const values = ['str', '', 10, 0, true, false, {}];
     const values = ['str', '', 10, 0, true, false, {}];
     const dataType = DataType.ARRAY;
     const dataType = DataType.ARRAY;

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

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Boolean type parser.
  * Boolean type parser.
@@ -9,10 +7,9 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  * @returns {*}
  * @returns {*}
  */
  */
-export function booleanTypeParser(value, schema, options, container) {
+export function booleanTypeParser(value, schema, options) {
   // если тип не соответствует логическому
   // если тип не соответствует логическому
   // значению, то преобразование пропускается
   // значению, то преобразование пропускается
   if (schema.type !== DataType.BOOLEAN) {
   if (schema.type !== DataType.BOOLEAN) {
@@ -38,17 +35,16 @@ export function booleanTypeParser(value, schema, options, container) {
     if (value === 1) return true;
     if (value === 1) return true;
     if (value === 0) return false;
     if (value === 0) return false;
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то преобразование пропускается
   // то преобразование пропускается
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   // если преобразовать значение не удалось,
   // если преобразовать значение не удалось,
   // то выбрасывается ошибка
   // то выбрасывается ошибка
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   // если установлен флаг бесшумной работы,
   // если установлен флаг бесшумной работы,

+ 14 - 15
src/data-parsers/boolean-type-parser.spec.js

@@ -3,7 +3,6 @@ import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
 import {booleanTypeParser} from './boolean-type-parser.js';
 import {booleanTypeParser} from './boolean-type-parser.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 describe('booleanTypeParser', function () {
 describe('booleanTypeParser', function () {
   it('should return a value as is when a non-boolean schema is given', function () {
   it('should return a value as is when a non-boolean schema is given', function () {
@@ -19,7 +18,7 @@ describe('booleanTypeParser', function () {
     dataTypes.forEach(parse);
     dataTypes.forEach(parse);
   });
   });
 
 
-  it('should return a boolean value as is when the boolean schema is given', function () {
+  it('should return a boolean value as is when a boolean schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value1 = true;
     const value1 = true;
     const res1 = booleanTypeParser(
     const res1 = booleanTypeParser(
@@ -39,7 +38,7 @@ describe('booleanTypeParser', function () {
     expect(res2).to.be.eq(value2);
     expect(res2).to.be.eq(value2);
   });
   });
 
 
-  it('should convert a string value to a boolean when the boolean schema is given', function () {
+  it('should convert a string value to a boolean when a boolean schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const resMap = [
     const resMap = [
       ['1', true],
       ['1', true],
@@ -69,7 +68,7 @@ describe('booleanTypeParser', function () {
     expect(res).to.be.true;
     expect(res).to.be.true;
   });
   });
 
 
-  it('should convert a number value to a boolean when the boolean schema is given', function () {
+  it('should convert a number value to a boolean when a boolean schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const resMap = [
     const resMap = [
       [1, true],
       [1, true],
@@ -86,20 +85,20 @@ describe('booleanTypeParser', function () {
     });
     });
   });
   });
 
 
-  it('should return an empty value as is when the boolean schema is given', function () {
+  it('should return a nullish value as is when a boolean schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.BOOLEAN, [undefined]);
-    const res = booleanTypeParser(
-      undefined,
-      {type: DataType.BOOLEAN},
-      undefined,
-      container,
-    );
-    expect(res).to.be.undefined;
+    [undefined, null].forEach(value => {
+      const res = booleanTypeParser(
+        value,
+        {type: DataType.BOOLEAN},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should throw an error for a non-boolean value when the boolean schema is given', function () {
+  it('should throw an error for a non-boolean value when a boolean schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const values = ['str', '', 10, -10, [], {}];
     const values = ['str', '', 10, -10, [], {}];
     const dataType = DataType.BOOLEAN;
     const dataType = DataType.BOOLEAN;

+ 2 - 6
src/data-parsers/default-value-setter.js

@@ -1,6 +1,4 @@
-import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Default value setter.
  * Default value setter.
@@ -22,11 +20,9 @@ export function defaultValueSetter(value, schema, options, container) {
   if (schema.default === undefined) {
   if (schema.default === undefined) {
     return value;
     return value;
   }
   }
-  // если значение не является пустым,
+  // если значение было определено,
   // то операция пропускается
   // то операция пропускается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (!emptyValues.isEmptyOf(dataType, value)) {
+  if (value != null) {
     return value;
     return value;
   }
   }
   // если значение является фабрикой,
   // если значение является фабрикой,

+ 78 - 77
src/data-parsers/default-value-setter.spec.js

@@ -1,107 +1,108 @@
 import {expect} from 'chai';
 import {expect} from 'chai';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {defaultValueSetter} from './default-value-setter.js';
 import {defaultValueSetter} from './default-value-setter.js';
 
 
 describe('defaultValueSetter', function () {
 describe('defaultValueSetter', function () {
-  it('should return an empty value as is when default values is disabled', function () {
+  it('should return a nullish value as is when default values is disabled', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    const res = defaultValueSetter(
-      'none',
-      {type: DataType.ANY, default: 10},
-      {noDefaultValues: true},
-      container,
-    );
-    expect(res).to.be.eq('none');
+    [undefined, null].forEach(value => {
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY, default: 10},
+        {noDefaultValues: true},
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should return an empty value as is when no default value is specified', function () {
+  it('should return a nullish value as is when no default value is specified', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    const res = defaultValueSetter(
-      'none',
-      {type: DataType.ANY},
-      undefined,
-      container,
-    );
-    expect(res).to.be.eq('none');
+    [undefined, null].forEach(value => {
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should return a non-empty value as is', function () {
+  it('should return a non-nullish value as is', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    const res = defaultValueSetter(
-      'non-empty',
-      {type: DataType.ANY},
-      undefined,
-      container,
-    );
-    expect(res).to.be.eq('non-empty');
+    const values = ['str', '', 10, 0, true, false, [1], [], {p: 1}, {}];
+    values.forEach(value => {
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should return a non-empty value as is even if the "default" option is specified', function () {
+  it('should return a non-nullish value as is even if the "default" option is specified', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    const res = defaultValueSetter(
-      'non-empty',
-      {type: DataType.ANY, default: 10},
-      undefined,
-      container,
-    );
-    expect(res).to.be.eq('non-empty');
+    const values = ['str', '', 10, 0, true, false, [1], [], {p: 1}, {}];
+    values.forEach(value => {
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY, default: 10},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
   it('should resolve a factory value from the "default" option', function () {
   it('should resolve a factory value from the "default" option', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    let invoked = 0;
-    const factory = (...args) => {
-      invoked++;
-      expect(args).to.be.eql([container]);
-      return 10;
-    };
-    const res = defaultValueSetter(
-      'none',
-      {type: DataType.ANY, default: factory},
-      undefined,
-      container,
-    );
-    expect(res).to.be.eq(10);
-    expect(invoked).to.be.eq(1);
+    [undefined, null].forEach(value => {
+      let invoked = 0;
+      const factory = (...args) => {
+        invoked++;
+        expect(args).to.be.eql([container]);
+        return 10;
+      };
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY, default: factory},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(10);
+      expect(invoked).to.be.eq(1);
+    });
   });
   });
 
 
-  it('should return a default value when a given value is empty', function () {
+  it('should return a default value when a nullish value is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    const res = defaultValueSetter(
-      'none',
-      {type: DataType.ANY, default: 10},
-      undefined,
-      container,
-    );
-    expect(res).to.be.eq(10);
+    [undefined, null].forEach(value => {
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY, default: 10},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(10);
+    });
   });
   });
 
 
   it('should return a clone of a default value instead of its reference', function () {
   it('should return a clone of a default value instead of its reference', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
     const defaultValue = {foo: 'bar'};
     const defaultValue = {foo: 'bar'};
-    const res = defaultValueSetter(
-      'none',
-      {type: DataType.ANY, default: defaultValue},
-      undefined,
-      container,
-    );
-    expect(res).to.be.eql(defaultValue);
-    expect(res).to.be.not.eq(defaultValue);
+    [undefined, null].forEach(value => {
+      const res = defaultValueSetter(
+        value,
+        {type: DataType.ANY, default: defaultValue},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eql(defaultValue);
+      expect(res).to.be.not.eq(defaultValue);
+    });
   });
   });
 });
 });

+ 5 - 9
src/data-parsers/number-type-parser.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Number type parser.
  * Number type parser.
@@ -9,10 +7,9 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  * @returns {*}
  * @returns {*}
  */
  */
-export function numberTypeParser(value, schema, options, container) {
+export function numberTypeParser(value, schema, options) {
   // если тип не соответствует числу,
   // если тип не соответствует числу,
   // то преобразование пропускается
   // то преобразование пропускается
   if (schema.type !== DataType.NUMBER) {
   if (schema.type !== DataType.NUMBER) {
@@ -25,7 +22,7 @@ export function numberTypeParser(value, schema, options, container) {
   }
   }
   // если значение является не пустой строкой,
   // если значение является не пустой строкой,
   // то выполняется попытка преобразования
   // то выполняется попытка преобразования
-  if (value && typeof value === 'string') {
+  if (typeof value === 'string' && value.trim() !== '') {
     if (value.length <= 20) {
     if (value.length <= 20) {
       const newValue = Number(value.trim());
       const newValue = Number(value.trim());
       if (!isNaN(newValue)) {
       if (!isNaN(newValue)) {
@@ -33,17 +30,16 @@ export function numberTypeParser(value, schema, options, container) {
       }
       }
     }
     }
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то преобразование пропускается
   // то преобразование пропускается
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   // если преобразовать значение не удалось,
   // если преобразовать значение не удалось,
   // то выбрасывается ошибка
   // то выбрасывается ошибка
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   // если установлен флаг бесшумной работы,
   // если установлен флаг бесшумной работы,

+ 20 - 14
src/data-parsers/number-type-parser.spec.js

@@ -3,7 +3,6 @@ import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
 import {numberTypeParser} from './number-type-parser.js';
 import {numberTypeParser} from './number-type-parser.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 describe('numberTypeParser', function () {
 describe('numberTypeParser', function () {
   it('should return a value as is when a non-number schema is given', function () {
   it('should return a value as is when a non-number schema is given', function () {
@@ -19,7 +18,7 @@ describe('numberTypeParser', function () {
     dataTypes.forEach(parse);
     dataTypes.forEach(parse);
   });
   });
 
 
-  it('should return a number value as is when the number schema is given', function () {
+  it('should return a number value as is when a number schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value = 10;
     const value = 10;
     const res = numberTypeParser(
     const res = numberTypeParser(
@@ -31,7 +30,7 @@ describe('numberTypeParser', function () {
     expect(res).to.be.eq(value);
     expect(res).to.be.eq(value);
   });
   });
 
 
-  it('should parse a digits string when the number schema is given', function () {
+  it('should parse a digits string when a number schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const res = numberTypeParser(
     const res = numberTypeParser(
       '10',
       '10',
@@ -42,7 +41,7 @@ describe('numberTypeParser', function () {
     expect(res).to.be.eq(10);
     expect(res).to.be.eq(10);
   });
   });
 
 
-  it('should parse a float string when the number schema is given', function () {
+  it('should parse a float string when a number schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const res = numberTypeParser(
     const res = numberTypeParser(
       '10.5',
       '10.5',
@@ -83,17 +82,24 @@ describe('numberTypeParser', function () {
     expect(throwable).to.throw(DataParsingError);
     expect(throwable).to.throw(DataParsingError);
   });
   });
 
 
-  it('should return an empty value as is when the number schema is given', function () {
+  it('should throw an error for a string with whitespaces', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.NUMBER, [undefined]);
-    const res = numberTypeParser(
-      undefined,
-      {type: DataType.NUMBER},
-      undefined,
-      container,
-    );
-    expect(res).to.be.undefined;
+    const throwable = () =>
+      numberTypeParser('   ', {type: DataType.NUMBER}, undefined, container);
+    expect(throwable).to.throw(DataParsingError);
+  });
+
+  it('should return a nullish value as is when a number schema is given', function () {
+    const container = new ServiceContainer();
+    [undefined, null].forEach(value => {
+      const res = numberTypeParser(
+        value,
+        {type: DataType.NUMBER},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
   it('should throw an error for a non-number value when a number schema is given', function () {
   it('should throw an error for a non-number value when a number schema is given', function () {

+ 4 - 8
src/data-parsers/object-type-parser.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Object type parser.
  * Object type parser.
@@ -9,10 +7,9 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  * @returns {*}
  * @returns {*}
  */
  */
-export function objectTypeParser(value, schema, options, container) {
+export function objectTypeParser(value, schema, options) {
   // если тип не соответствует объекту,
   // если тип не соответствует объекту,
   // то проверка пропускается
   // то проверка пропускается
   if (schema.type !== DataType.OBJECT) {
   if (schema.type !== DataType.OBJECT) {
@@ -41,17 +38,16 @@ export function objectTypeParser(value, schema, options, container) {
       return newValue;
       return newValue;
     }
     }
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то преобразование пропускается
   // то преобразование пропускается
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   // если преобразовать значение не удалось,
   // если преобразовать значение не удалось,
   // то выбрасывается ошибка
   // то выбрасывается ошибка
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   // если установлен флаг бесшумной работы,
   // если установлен флаг бесшумной работы,

+ 13 - 14
src/data-parsers/object-type-parser.spec.js

@@ -3,7 +3,6 @@ import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
 import {objectTypeParser} from './object-type-parser.js';
 import {objectTypeParser} from './object-type-parser.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 describe('objectTypeParser', function () {
 describe('objectTypeParser', function () {
   it('should return a value as is when a non-object schema is given', function () {
   it('should return a value as is when a non-object schema is given', function () {
@@ -19,7 +18,7 @@ describe('objectTypeParser', function () {
     dataTypes.forEach(parse);
     dataTypes.forEach(parse);
   });
   });
 
 
-  it('should return an object value as is when the object schema is given', function () {
+  it('should return an object value as is when an object schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value = {};
     const value = {};
     const res = objectTypeParser(
     const res = objectTypeParser(
@@ -31,7 +30,7 @@ describe('objectTypeParser', function () {
     expect(res).to.be.eq(value);
     expect(res).to.be.eq(value);
   });
   });
 
 
-  it('should parse a json string when the object schema is given', function () {
+  it('should parse a json string when an object schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value = '{"foo": "bar"}';
     const value = '{"foo": "bar"}';
     const res = objectTypeParser(
     const res = objectTypeParser(
@@ -43,20 +42,20 @@ describe('objectTypeParser', function () {
     expect(res).to.be.eql({foo: 'bar'});
     expect(res).to.be.eql({foo: 'bar'});
   });
   });
 
 
-  it('should return an empty value as is when the object schema is given', function () {
+  it('should return a nullish value as is when an object schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.OBJECT, [undefined]);
-    const res = objectTypeParser(
-      undefined,
-      {type: DataType.OBJECT},
-      undefined,
-      container,
-    );
-    expect(res).to.be.undefined;
+    [undefined, null].forEach(value => {
+      const res = objectTypeParser(
+        value,
+        {type: DataType.OBJECT},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should throw an error for a non-object value when the object schema is given', function () {
+  it('should throw an error for a non-object value when an object schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const values = ['str', '', 10, 0, true, false, []];
     const values = ['str', '', 10, 0, true, false, []];
     const dataType = DataType.OBJECT;
     const dataType = DataType.OBJECT;

+ 4 - 8
src/data-parsers/string-type-parser.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * String type parser.
  * String type parser.
@@ -9,10 +7,9 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  * @returns {*}
  * @returns {*}
  */
  */
-export function stringTypeParser(value, schema, options, container) {
+export function stringTypeParser(value, schema, options) {
   // если тип не соответствует строке,
   // если тип не соответствует строке,
   // то преобразование пропускается
   // то преобразование пропускается
   if (schema.type !== DataType.STRING) {
   if (schema.type !== DataType.STRING) {
@@ -28,17 +25,16 @@ export function stringTypeParser(value, schema, options, container) {
   if (typeof value === 'number') {
   if (typeof value === 'number') {
     return String(value);
     return String(value);
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то преобразование пропускается
   // то преобразование пропускается
-  const dataType = schema.type || DataType.ANY;
-  const emptyValues = container.get(EmptyValuesService);
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return value;
     return value;
   }
   }
   // если преобразовать значение не удалось,
   // если преобразовать значение не удалось,
   // то выбрасывается ошибка
   // то выбрасывается ошибка
   if (!options || !options.noParsingErrors) {
   if (!options || !options.noParsingErrors) {
     const sourcePath = options && options.sourcePath;
     const sourcePath = options && options.sourcePath;
+    const dataType = schema.type || DataType.ANY;
     throw new DataParsingError(value, dataType, sourcePath);
     throw new DataParsingError(value, dataType, sourcePath);
   }
   }
   // если установлен флаг бесшумной работы,
   // если установлен флаг бесшумной работы,

+ 13 - 14
src/data-parsers/string-type-parser.spec.js

@@ -3,7 +3,6 @@ import {ServiceContainer} from '@e22m4u/js-service';
 import {DataParsingError} from '../errors/index.js';
 import {DataParsingError} from '../errors/index.js';
 import {stringTypeParser} from './string-type-parser.js';
 import {stringTypeParser} from './string-type-parser.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
 import {DATA_TYPE_LIST, DataType} from '../data-type.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 describe('stringTypeParser', function () {
 describe('stringTypeParser', function () {
   it('should return a value as is when a non-string schema is given', function () {
   it('should return a value as is when a non-string schema is given', function () {
@@ -19,7 +18,7 @@ describe('stringTypeParser', function () {
     dataTypes.forEach(parse);
     dataTypes.forEach(parse);
   });
   });
 
 
-  it('should return a string value as is when the string schema is given', function () {
+  it('should return a string value as is when a string schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const value = 'str';
     const value = 'str';
     const res = stringTypeParser(
     const res = stringTypeParser(
@@ -31,7 +30,7 @@ describe('stringTypeParser', function () {
     expect(res).to.be.eq(value);
     expect(res).to.be.eq(value);
   });
   });
 
 
-  it('should convert a number value to a string when the string schema is given', function () {
+  it('should convert a number value to a string when a string schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const res = stringTypeParser(
     const res = stringTypeParser(
       10,
       10,
@@ -42,20 +41,20 @@ describe('stringTypeParser', function () {
     expect(res).to.be.eq('10');
     expect(res).to.be.eq('10');
   });
   });
 
 
-  it('should return an empty value as is when the string schema is given', function () {
+  it('should return a nullish value as is when a string schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
-    const emptyValues = container.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.STRING, [undefined]);
-    const res = stringTypeParser(
-      undefined,
-      {type: DataType.STRING},
-      undefined,
-      container,
-    );
-    expect(res).to.be.undefined;
+    [undefined, null].forEach(value => {
+      const res = stringTypeParser(
+        value,
+        {type: DataType.STRING},
+        undefined,
+        container,
+      );
+      expect(res).to.be.eq(value);
+    });
   });
   });
 
 
-  it('should throw an error for a non-string value when the string schema is given', function () {
+  it('should throw an error for a non-string value when a string schema is given', function () {
     const container = new ServiceContainer();
     const container = new ServiceContainer();
     const values = [true, false, [], {}];
     const values = [true, false, [], {}];
     const dataType = DataType.STRING;
     const dataType = DataType.STRING;

+ 3 - 8
src/data-validators/array-type-validator.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataValidationError} from '../errors/index.js';
 import {DataValidationError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Array type validator.
  * Array type validator.
@@ -9,19 +7,16 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  */
  */
-export function arrayTypeValidator(value, schema, options, container) {
+export function arrayTypeValidator(value, schema, options) {
   // если тип не соответствует массиву,
   // если тип не соответствует массиву,
   // то проверка пропускается
   // то проверка пропускается
   if (schema.type !== DataType.ARRAY) {
   if (schema.type !== DataType.ARRAY) {
     return;
     return;
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то проверка пропускается
   // то проверка пропускается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   // если значение является массивом,
   // если значение является массивом,

+ 4 - 6
src/data-validators/array-type-validator.spec.js

@@ -2,7 +2,6 @@ import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {arrayTypeValidator} from './array-type-validator.js';
 import {arrayTypeValidator} from './array-type-validator.js';
 
 
 const validate = arrayTypeValidator;
 const validate = arrayTypeValidator;
@@ -19,11 +18,10 @@ describe('arrayTypeValidator', function () {
     validate(value, {type: DataType.OBJECT}, undefined, cont);
     validate(value, {type: DataType.OBJECT}, undefined, cont);
   });
   });
 
 
-  it('should not validate empty values', function () {
+  it('should not validate a nullish value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ARRAY, [[]]);
-    validate([], {type: DataType.ARRAY}, undefined, cont);
+    validate(undefined, {type: DataType.ARRAY}, undefined, cont);
+    validate(null, {type: DataType.ARRAY}, undefined, cont);
   });
   });
 
 
   it('should throw an error for an invalid value', function () {
   it('should throw an error for an invalid value', function () {
@@ -44,7 +42,7 @@ describe('arrayTypeValidator', function () {
     throwable([])();
     throwable([])();
   });
   });
 
 
-  it('should add the source path to error message', function () {
+  it('should add a source path to error message', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
     const schema = {type: DataType.ARRAY};
     const schema = {type: DataType.ARRAY};
     const options = {sourcePath: 'array[0]'};
     const options = {sourcePath: 'array[0]'};

+ 3 - 8
src/data-validators/boolean-type-validator.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataValidationError} from '../errors/index.js';
 import {DataValidationError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Boolean type validator.
  * Boolean type validator.
@@ -9,19 +7,16 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  */
  */
-export function booleanTypeValidator(value, schema, options, container) {
+export function booleanTypeValidator(value, schema, options) {
   // если тип не соответствует логическому
   // если тип не соответствует логическому
   // значению, то проверка пропускается
   // значению, то проверка пропускается
   if (schema.type !== DataType.BOOLEAN) {
   if (schema.type !== DataType.BOOLEAN) {
     return;
     return;
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то проверка пропускается
   // то проверка пропускается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   // если значение является логическим,
   // если значение является логическим,

+ 4 - 6
src/data-validators/boolean-type-validator.spec.js

@@ -2,7 +2,6 @@ import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {booleanTypeValidator} from './boolean-type-validator.js';
 import {booleanTypeValidator} from './boolean-type-validator.js';
 
 
 const validate = booleanTypeValidator;
 const validate = booleanTypeValidator;
@@ -19,11 +18,10 @@ describe('booleanTypeValidator', function () {
     validate(value, {type: DataType.OBJECT}, undefined, cont);
     validate(value, {type: DataType.OBJECT}, undefined, cont);
   });
   });
 
 
-  it('should not validate empty values', function () {
+  it('should not validate a nullish value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.BOOLEAN, [false]);
-    validate(false, {type: DataType.BOOLEAN}, undefined, cont);
+    validate(undefined, {type: DataType.BOOLEAN}, undefined, cont);
+    validate(null, {type: DataType.BOOLEAN}, undefined, cont);
   });
   });
 
 
   it('should throw an error for an invalid value', function () {
   it('should throw an error for an invalid value', function () {
@@ -44,7 +42,7 @@ describe('booleanTypeValidator', function () {
     throwable(false)();
     throwable(false)();
   });
   });
 
 
-  it('should add the source path to error message', function () {
+  it('should add a source path to error message', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
     const schema = {type: DataType.BOOLEAN};
     const schema = {type: DataType.BOOLEAN};
     const options = {sourcePath: 'array[0]'};
     const options = {sourcePath: 'array[0]'};

+ 3 - 8
src/data-validators/number-type-validator.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataValidationError} from '../errors/index.js';
 import {DataValidationError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Number type validator.
  * Number type validator.
@@ -9,19 +7,16 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  */
  */
-export function numberTypeValidator(value, schema, options, container) {
+export function numberTypeValidator(value, schema, options) {
   // если тип не соответствует числу,
   // если тип не соответствует числу,
   // то проверка пропускается
   // то проверка пропускается
   if (schema.type !== DataType.NUMBER) {
   if (schema.type !== DataType.NUMBER) {
     return;
     return;
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то проверка пропускается
   // то проверка пропускается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   // если значение является числом,
   // если значение является числом,

+ 4 - 6
src/data-validators/number-type-validator.spec.js

@@ -2,7 +2,6 @@ import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {numberTypeValidator} from './number-type-validator.js';
 import {numberTypeValidator} from './number-type-validator.js';
 
 
 const validate = numberTypeValidator;
 const validate = numberTypeValidator;
@@ -19,11 +18,10 @@ describe('numberTypeValidator', function () {
     validate(value, {type: DataType.OBJECT}, undefined, cont);
     validate(value, {type: DataType.OBJECT}, undefined, cont);
   });
   });
 
 
-  it('should not validate empty values', function () {
+  it('should not validate a nullish value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.NUMBER, [0]);
-    validate(0, {type: DataType.NUMBER}, undefined, cont);
+    validate(undefined, {type: DataType.NUMBER}, undefined, cont);
+    validate(null, {type: DataType.NUMBER}, undefined, cont);
   });
   });
 
 
   it('should throw an error for an invalid value', function () {
   it('should throw an error for an invalid value', function () {
@@ -44,7 +42,7 @@ describe('numberTypeValidator', function () {
     throwable(0)();
     throwable(0)();
   });
   });
 
 
-  it('should add the source path to error message', function () {
+  it('should add a source path to error message', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
     const schema = {type: DataType.NUMBER};
     const schema = {type: DataType.NUMBER};
     const options = {sourcePath: 'array[0]'};
     const options = {sourcePath: 'array[0]'};

+ 3 - 8
src/data-validators/object-type-validator.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataValidationError} from '../errors/index.js';
 import {DataValidationError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Object type validator.
  * Object type validator.
@@ -9,19 +7,16 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  */
  */
-export function objectTypeValidator(value, schema, options, container) {
+export function objectTypeValidator(value, schema, options) {
   // если тип не соответствует объекту,
   // если тип не соответствует объекту,
   // то проверка пропускается
   // то проверка пропускается
   if (schema.type !== DataType.OBJECT) {
   if (schema.type !== DataType.OBJECT) {
     return;
     return;
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то проверка пропускается
   // то проверка пропускается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   // если значение является объектом,
   // если значение является объектом,

+ 4 - 6
src/data-validators/object-type-validator.spec.js

@@ -2,7 +2,6 @@ import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {objectTypeValidator} from './object-type-validator.js';
 import {objectTypeValidator} from './object-type-validator.js';
 
 
 const validate = objectTypeValidator;
 const validate = objectTypeValidator;
@@ -19,11 +18,10 @@ describe('objectTypeValidator', function () {
     validate(value, {type: DataType.ARRAY}, undefined, cont);
     validate(value, {type: DataType.ARRAY}, undefined, cont);
   });
   });
 
 
-  it('should not validate empty values', function () {
+  it('should not validate a nullish value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.OBJECT, [{}]);
-    validate({}, {type: DataType.OBJECT}, undefined, cont);
+    validate(undefined, {type: DataType.OBJECT}, undefined, cont);
+    validate(null, {type: DataType.OBJECT}, undefined, cont);
   });
   });
 
 
   it('should throw an error for an invalid value', function () {
   it('should throw an error for an invalid value', function () {
@@ -44,7 +42,7 @@ describe('objectTypeValidator', function () {
     throwable({})();
     throwable({})();
   });
   });
 
 
-  it('should add the source path to error message', function () {
+  it('should add a source path to error message', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
     const schema = {type: DataType.OBJECT};
     const schema = {type: DataType.OBJECT};
     const options = {sourcePath: 'array[0]'};
     const options = {sourcePath: 'array[0]'};

+ 3 - 9
src/data-validators/required-value-validator.js

@@ -1,7 +1,4 @@
-import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataValidationError} from '../errors/index.js';
 import {DataValidationError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * Required value validator.
  * Required value validator.
@@ -9,19 +6,16 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  */
  */
-export function requiredValueValidator(value, schema, options, container) {
+export function requiredValueValidator(value, schema, options) {
   // если значение не является обязательным,
   // если значение не является обязательным,
   // то проверка пропускается
   // то проверка пропускается
   if (schema.required !== true) {
   if (schema.required !== true) {
     return;
     return;
   }
   }
-  // если значение не является пустым,
+  // если значение определено,
   // то проверка успешно завершается
   // то проверка успешно завершается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (!emptyValues.isEmptyOf(dataType, value)) {
+  if (value != null) {
     return;
     return;
   }
   }
   // если значение является пустым,
   // если значение является пустым,

+ 27 - 22
src/data-validators/required-value-validator.spec.js

@@ -1,46 +1,51 @@
 import {expect} from 'chai';
 import {expect} from 'chai';
+import {format} from '@e22m4u/js-format';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {requiredValueValidator} from './required-value-validator.js';
 import {requiredValueValidator} from './required-value-validator.js';
 
 
 const validate = requiredValueValidator;
 const validate = requiredValueValidator;
 
 
 describe('requiredValueValidator', function () {
 describe('requiredValueValidator', function () {
-  it('should skip not required value', function () {
+  it('should ignore a nullish value when the value is optional', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
-    validate('none', {}, undefined, cont);
-    validate('none', {required: false}, undefined, cont);
+    [undefined, null].forEach(value => {
+      validate(value, {}, undefined, cont);
+      validate(value, {required: false}, undefined, cont);
+    });
   });
   });
 
 
-  it('should throw an error when required value is empty', function () {
+  it('should throw an error when a nullish value is given as a required value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
     const schema = {required: true};
     const schema = {required: true};
-    const throwable = () => validate('none', schema, undefined, cont);
-    expect(throwable).to.throw('Value is required, but "none" was given.');
+    [undefined, null].forEach(value => {
+      const throwable = () => validate(value, schema, undefined, cont);
+      const error = format('Value is required, but %v was given.', value);
+      expect(throwable).to.throw(error);
+    });
   });
   });
 
 
-  it('should throw an error when required value is empty when the type is specified', function () {
+  it('should validate a given value when the data type is specified', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.STRING, ['none']);
     const schema = {type: DataType.STRING, required: true};
     const schema = {type: DataType.STRING, required: true};
-    const throwable = () => validate('none', schema, undefined, cont);
-    expect(throwable).to.throw('Value is required, but "none" was given.');
+    [undefined, null].forEach(value => {
+      const throwable = () => validate(value, schema, undefined, cont);
+      const error = format('Value is required, but %v was given.', value);
+      expect(throwable).to.throw(error);
+    });
   });
   });
 
 
-  it('should add the source path to error message', function () {
+  it('should add a source path to an error message for a nullish value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.ANY, ['none']);
     const schema = {required: true};
     const schema = {required: true};
     const options = {sourcePath: 'array[0]'};
     const options = {sourcePath: 'array[0]'};
-    const throwable = () => validate('none', schema, options, cont);
-    const error = 'Value of "array[0]" is required, but "none" was given.';
-    expect(throwable).to.throw(error);
+    [undefined, null].forEach(value => {
+      const throwable = () => validate(value, schema, options, cont);
+      const error = format(
+        'Value of "array[0]" is required, but %v was given.',
+        value,
+      );
+      expect(throwable).to.throw(error);
+    });
   });
   });
 });
 });

+ 3 - 8
src/data-validators/string-type-validator.js

@@ -1,7 +1,5 @@
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
-import {ServiceContainer} from '@e22m4u/js-service';
 import {DataValidationError} from '../errors/index.js';
 import {DataValidationError} from '../errors/index.js';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 
 
 /**
 /**
  * String type validator.
  * String type validator.
@@ -9,19 +7,16 @@ import {EmptyValuesService} from '@e22m4u/js-empty-values';
  * @param {*} value
  * @param {*} value
  * @param {object} schema
  * @param {object} schema
  * @param {object|undefined} options
  * @param {object|undefined} options
- * @param {ServiceContainer} container
  */
  */
-export function stringTypeValidator(value, schema, options, container) {
+export function stringTypeValidator(value, schema, options) {
   // если тип не соответствует строке,
   // если тип не соответствует строке,
   // то проверка пропускается
   // то проверка пропускается
   if (schema.type !== DataType.STRING) {
   if (schema.type !== DataType.STRING) {
     return;
     return;
   }
   }
-  // если значение является пустым,
+  // если значение не определено,
   // то проверка пропускается
   // то проверка пропускается
-  const emptyValues = container.get(EmptyValuesService);
-  const dataType = schema.type || DataType.ANY;
-  if (emptyValues.isEmptyOf(dataType, value)) {
+  if (value == null) {
     return;
     return;
   }
   }
   // если значение является строкой,
   // если значение является строкой,

+ 4 - 6
src/data-validators/string-type-validator.spec.js

@@ -2,7 +2,6 @@ import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {DataType} from '../data-type.js';
 import {DataType} from '../data-type.js';
 import {ServiceContainer} from '@e22m4u/js-service';
 import {ServiceContainer} from '@e22m4u/js-service';
-import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {stringTypeValidator} from './string-type-validator.js';
 import {stringTypeValidator} from './string-type-validator.js';
 
 
 const validate = stringTypeValidator;
 const validate = stringTypeValidator;
@@ -19,11 +18,10 @@ describe('stringTypeValidator', function () {
     validate(value, {type: DataType.OBJECT}, undefined, cont);
     validate(value, {type: DataType.OBJECT}, undefined, cont);
   });
   });
 
 
-  it('should not validate empty values', function () {
+  it('should not validate a nullish value', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
-    const emptyValues = cont.get(EmptyValuesService);
-    emptyValues.setEmptyValuesOf(DataType.STRING, ['']);
-    validate('', {type: DataType.STRING}, undefined, cont);
+    validate(undefined, {type: DataType.STRING}, undefined, cont);
+    validate(null, {type: DataType.STRING}, undefined, cont);
   });
   });
 
 
   it('should throw an error for an invalid value', function () {
   it('should throw an error for an invalid value', function () {
@@ -43,7 +41,7 @@ describe('stringTypeValidator', function () {
     throwable('str')();
     throwable('str')();
   });
   });
 
 
-  it('should add the source path to error message', function () {
+  it('should add a source path to error message', function () {
     const cont = new ServiceContainer();
     const cont = new ServiceContainer();
     const schema = {type: DataType.STRING};
     const schema = {type: DataType.STRING};
     const options = {sourcePath: 'array[0]'};
     const options = {sourcePath: 'array[0]'};