Browse Source

refactor: renames utility isPureObject to isPlainObject

e22m4u 3 weeks ago
parent
commit
b1c4f11a7c

+ 21 - 21
dist/cjs/index.cjs

@@ -205,19 +205,6 @@ var init_get_ctor_name = __esm({
   }
 });
 
-// src/utils/is-pure-object.js
-function isPureObject(value) {
-  return Boolean(
-    typeof value === "object" && value && !Array.isArray(value) && (!value.constructor || value.constructor && value.constructor.name === "Object")
-  );
-}
-var init_is_pure_object = __esm({
-  "src/utils/is-pure-object.js"() {
-    "use strict";
-    __name(isPureObject, "isPureObject");
-  }
-});
-
 // src/errors/not-implemented-error.js
 var import_js_format, _NotImplementedError, NotImplementedError;
 var init_not_implemented_error = __esm({
@@ -325,6 +312,19 @@ var init_like_to_regexp = __esm({
   }
 });
 
+// src/utils/is-plain-object.js
+function isPlainObject(value) {
+  return Boolean(
+    typeof value === "object" && value && !Array.isArray(value) && (!value.constructor || value.constructor && value.constructor.name === "Object")
+  );
+}
+var init_is_plain_object = __esm({
+  "src/utils/is-plain-object.js"() {
+    "use strict";
+    __name(isPlainObject, "isPlainObject");
+  }
+});
+
 // src/utils/string-to-regexp.js
 function stringToRegexp(pattern, flags = void 0) {
   if (pattern instanceof RegExp) {
@@ -497,8 +497,8 @@ var init_utils = __esm({
     init_singularize();
     init_is_deep_equal();
     init_get_ctor_name();
-    init_is_pure_object();
     init_like_to_regexp();
+    init_is_plain_object();
     init_string_to_regexp();
     init_get_value_by_path();
     init_transform_promise();
@@ -1242,7 +1242,7 @@ var init_where_clause_tool = __esm({
           }
           return false;
         }
-        if (isPureObject(example)) {
+        if (isPlainObject(example)) {
           const operatorsTest = this.getService(OperatorClauseTool).testAll(
             example,
             value
@@ -2633,7 +2633,7 @@ var init_property_uniqueness_validator = __esm({
             'The parameter "modelName" of the PropertyUniquenessValidator must be a non-empty String, but %v was given.',
             modelName
           );
-        if (!isPureObject(modelData))
+        if (!isPlainObject(modelData))
           throw new InvalidArgumentError(
             "The data of the model %v should be an Object, but %v was given.",
             modelName,
@@ -3130,7 +3130,7 @@ var init_model_data_validator = __esm({
        * @returns {undefined}
        */
       validate(modelName, modelData, isPartial = false) {
-        if (!isPureObject(modelData))
+        if (!isPlainObject(modelData))
           throw new InvalidArgumentError(
             "The data of the model %v should be an Object, but %v was given.",
             modelName,
@@ -3248,7 +3248,7 @@ var init_model_data_validator = __esm({
             break;
           // OBJECT
           case DataType.OBJECT: {
-            if (!isPureObject(propValue)) throw createError("an Object");
+            if (!isPlainObject(propValue)) throw createError("an Object");
             if (typeof propDef === "object") {
               const modelOptionField = isArrayValue ? "itemModel" : "model";
               const modelOptionValue = propDef[modelOptionField];
@@ -3420,7 +3420,7 @@ var init_model_data_transformer = __esm({
        * @returns {object|Promise<object>}
        */
       transform(modelName, modelData, isPartial = false) {
-        if (!isPureObject(modelData))
+        if (!isPlainObject(modelData))
           throw new InvalidArgumentError(
             "The data of the model %v should be an Object, but %v was given.",
             modelName,
@@ -6483,8 +6483,8 @@ __export(index_exports, {
   getValueByPath: () => getValueByPath,
   isCtor: () => isCtor,
   isDeepEqual: () => isDeepEqual,
+  isPlainObject: () => isPlainObject,
   isPromise: () => isPromise,
-  isPureObject: () => isPureObject,
   likeToRegexp: () => likeToRegexp,
   modelNameToModelKey: () => modelNameToModelKey,
   selectObjectKeys: () => selectObjectKeys,
@@ -6589,8 +6589,8 @@ init_repository2();
   getValueByPath,
   isCtor,
   isDeepEqual,
+  isPlainObject,
   isPromise,
-  isPureObject,
   likeToRegexp,
   modelNameToModelKey,
   selectObjectKeys,

+ 2 - 2
src/definition/model/model-data-transformer.js

@@ -1,6 +1,6 @@
 import {Service} from '@e22m4u/js-service';
 import {cloneDeep} from '../../utils/index.js';
-import {isPureObject} from '../../utils/index.js';
+import {isPlainObject} from '../../utils/index.js';
 import {transformPromise} from '../../utils/index.js';
 import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {InvalidArgumentError} from '../../errors/index.js';
@@ -20,7 +20,7 @@ export class ModelDataTransformer extends Service {
    * @returns {object|Promise<object>}
    */
   transform(modelName, modelData, isPartial = false) {
-    if (!isPureObject(modelData))
+    if (!isPlainObject(modelData))
       throw new InvalidArgumentError(
         'The data of the model %v should be an Object, but %v was given.',
         modelName,

+ 3 - 3
src/definition/model/model-data-validator.js

@@ -1,7 +1,7 @@
 import {Service} from '@e22m4u/js-service';
 import {DataType} from './properties/index.js';
 import {getCtorName} from '../../utils/index.js';
-import {isPureObject} from '../../utils/index.js';
+import {isPlainObject} from '../../utils/index.js';
 import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {InvalidArgumentError} from '../../errors/index.js';
 import {PropertyValidatorRegistry} from './properties/index.js';
@@ -20,7 +20,7 @@ export class ModelDataValidator extends Service {
    * @returns {undefined}
    */
   validate(modelName, modelData, isPartial = false) {
-    if (!isPureObject(modelData))
+    if (!isPlainObject(modelData))
       throw new InvalidArgumentError(
         'The data of the model %v should be an Object, but %v was given.',
         modelName,
@@ -157,7 +157,7 @@ export class ModelDataValidator extends Service {
         break;
       // OBJECT
       case DataType.OBJECT: {
-        if (!isPureObject(propValue)) throw createError('an Object');
+        if (!isPlainObject(propValue)) throw createError('an Object');
         if (typeof propDef === 'object') {
           const modelOptionField = isArrayValue ? 'itemModel' : 'model';
           const modelOptionValue = propDef[modelOptionField];

+ 2 - 2
src/definition/model/properties/property-uniqueness-validator.js

@@ -1,6 +1,6 @@
 import {DataType} from './data-type.js';
 import {Service} from '@e22m4u/js-service';
-import {isPureObject} from '../../../utils/index.js';
+import {isPlainObject} from '../../../utils/index.js';
 import {EmptyValuesService} from '@e22m4u/js-empty-values';
 import {PropertyUniqueness} from './property-uniqueness.js';
 import {InvalidArgumentError} from '../../../errors/index.js';
@@ -45,7 +45,7 @@ export class PropertyUniquenessValidator extends Service {
           'must be a non-empty String, but %v was given.',
         modelName,
       );
-    if (!isPureObject(modelData))
+    if (!isPlainObject(modelData))
       throw new InvalidArgumentError(
         'The data of the model %v should be an Object, but %v was given.',
         modelName,

+ 2 - 2
src/filter/where-clause-tool.js

@@ -1,7 +1,7 @@
 import {Service} from '@e22m4u/js-service';
 import {InvalidArgumentError} from '../errors/index.js';
 import {OperatorClauseTool} from './operator-clause-tool.js';
-import {getValueByPath, isDeepEqual, isPureObject} from '../utils/index.js';
+import {getValueByPath, isDeepEqual, isPlainObject} from '../utils/index.js';
 
 /**
  * Where clause tool.
@@ -124,7 +124,7 @@ export class WhereClauseTool extends Service {
       return false;
     }
     // условием является простой объект
-    if (isPureObject(example)) {
+    if (isPlainObject(example)) {
       const operatorsTest = this.getService(OperatorClauseTool).testAll(
         example,
         value,

+ 1 - 1
src/utils/index.d.ts

@@ -5,8 +5,8 @@ export * from './clone-deep.js';
 export * from './singularize.js';
 export * from './is-deep-equal.js';
 export * from './get-ctor-name.js';
-export * from './is-pure-object.js';
 export * from './like-to-regexp.js';
+export * from './is-plain-object.js';
 export * from './string-to-regexp.js';
 export * from './get-value-by-path.js';
 export * from './transform-promise.js';

+ 1 - 1
src/utils/index.js

@@ -5,8 +5,8 @@ export * from './clone-deep.js';
 export * from './singularize.js';
 export * from './is-deep-equal.js';
 export * from './get-ctor-name.js';
-export * from './is-pure-object.js';
 export * from './like-to-regexp.js';
+export * from './is-plain-object.js';
 export * from './string-to-regexp.js';
 export * from './get-value-by-path.js';
 export * from './transform-promise.js';

+ 6 - 0
src/utils/is-plain-object.d.ts

@@ -0,0 +1,6 @@
+/**
+ * Is plain object.
+ *
+ * @param value
+ */
+export declare function isPlainObject(value: unknown): boolean;

+ 2 - 2
src/utils/is-pure-object.js → src/utils/is-plain-object.js

@@ -1,10 +1,10 @@
 /**
- * Is pure object.
+ * Is plain object.
  *
  * @param {*} value
  * @returns {boolean}
  */
-export function isPureObject(value) {
+export function isPlainObject(value) {
   return Boolean(
     typeof value === 'object' &&
       value &&

+ 25 - 0
src/utils/is-plain-object.spec.js

@@ -0,0 +1,25 @@
+import {expect} from 'chai';
+import {isPlainObject} from './is-plain-object.js';
+
+describe('isPlainObject', function () {
+  it('returns true if a pure object given', function () {
+    expect(isPlainObject({})).to.be.true;
+    expect(isPlainObject({key: 'val'})).to.be.true;
+    expect(isPlainObject(Object.create(null))).to.be.true;
+  });
+
+  it('returns false if a non-pure object given', function () {
+    expect(isPlainObject(new Date())).to.be.false;
+    expect(isPlainObject([])).to.be.false;
+    expect(isPlainObject(() => undefined)).to.be.false;
+  });
+
+  it('returns false if a non-object given', function () {
+    expect(isPlainObject('string')).to.be.false;
+    expect(isPlainObject(10)).to.be.false;
+    expect(isPlainObject(true)).to.be.false;
+    expect(isPlainObject(false)).to.be.false;
+    expect(isPlainObject(null)).to.be.false;
+    expect(isPlainObject(undefined)).to.be.false;
+  });
+});

+ 0 - 6
src/utils/is-pure-object.d.ts

@@ -1,6 +0,0 @@
-/**
- * Is pure object.
- *
- * @param value
- */
-export declare function isPureObject(value: unknown): boolean;

+ 0 - 25
src/utils/is-pure-object.spec.js

@@ -1,25 +0,0 @@
-import {expect} from 'chai';
-import {isPureObject} from './is-pure-object.js';
-
-describe('isPureObject', function () {
-  it('returns ture if a pure object given', function () {
-    expect(isPureObject({})).to.be.true;
-    expect(isPureObject({key: 'val'})).to.be.true;
-    expect(isPureObject(Object.create(null))).to.be.true;
-  });
-
-  it('returns false if a non-pure object given', function () {
-    expect(isPureObject(new Date())).to.be.false;
-    expect(isPureObject([])).to.be.false;
-    expect(isPureObject(() => undefined)).to.be.false;
-  });
-
-  it('returns false if a non-object given', function () {
-    expect(isPureObject('string')).to.be.false;
-    expect(isPureObject(10)).to.be.false;
-    expect(isPureObject(true)).to.be.false;
-    expect(isPureObject(false)).to.be.false;
-    expect(isPureObject(null)).to.be.false;
-    expect(isPureObject(undefined)).to.be.false;
-  });
-});