Functions to create, process and test objects.
Methods
-
<static> checkField(obj, field, filter, settings) → {Boolean}
-
Check whether the field of given object corresponds to specified condition(s) or filter(s).
Parameters:
Name Type Argument Description obj
Object Object to be processed.
field
String Name of the field that should be checked.
filter
Any A filter or array of filters specifying conditions that should be checked. A filter can be:
- a function; if the function returns a true value it means that the field corresponds to this filter; the following parameters will be passed into the function: field value, field name and reference to the object
- a regular expression; if the field value (converted to string) matches the regular expression it means that the field corresponds to this filter
- a string; value can be one of the following:
own
- if the field is own property of the object it means that the field corresponds to this filter!own
- if the field is not own property of the object it means that the field corresponds to this filter- any other value - is used as the check when calling isKindOf;
if isKindOf returns
true
for the given field value and the filter it means that the field corresponds to this filter
- an object;
- if the object has
and
oror
field, its value is used as subfilter and will be passed in recursive call ofcheckField
as value offilter
parameter; the field name (and
oror
) will be used as value offilterConnect
setting (see below); if the result of the recursive call istrue
it means that the field corresponds to this filter - if the object has
field
field, its value is used as filter; if the filter is a regular expression and the field name matches the regular expression it means that the field corresponds to this filter; otherwise the field corresponds to this filter when the filed name strictly equals to the filter (converted to string) - if the object has
value
field, its value is used as filter; if the field value strictly equals to the filter value it means that the field corresponds to this filter - in any other case if the field value strictly equals to the object it means that the field corresponds to this filter
- if the object has
- any other value; if the field value strictly equals to the filter value it means that the field corresponds to this filter
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported (setting's default value is specified in parentheses):
filterConnect
:String
(and
) - a boolean connector that should be used when array of filters is specified infilter
parameter; valid values are the following:and
,or
(case-insensitive); any other value is treated asand
value
:Any
- a value that should be used for check instead of field's value
Returns:
true
if the field corresponds to specified filter(s), otherwisefalse
.- Type
- Boolean
-
<static> fromArray(list, keyField, settings) → {Object}
-
Create object (map) from list of objects. Fields of the created object are values of specified field of objects, values of the created object are corresponding items of the list.
Parameters:
Name Type Argument Description list
Array List of objects/values to be processed.
keyField
function | String <optional>
Specifies names of fields of the created object. Can be name of field or method whose value is used as field name of the created object, or function that returns the field name. In the latter case the following parameters will be passed in the function: the source object (an item of the list), the created object, the index of the source object. When the parameter is not set, items of the list are used as field names.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported (setting's default value is specified in parentheses):
deleteKeyField
:Boolean
(false
) - specifies whether key field (whose value is field name of the created object) should be deleted from the source object (an item of the list)filter
- a filter specifying objects that should be included into result (see checkField); an item of the list will be used as value for checkfilterConnect
:String
- a boolean connector that should be used when array of filters is specified infilter
setting (see checkField)
- See:
Returns:
Object created from the given list.
- Type
- Object
-
<static> getClass(value) → {String}
-
Return class of given value (namely value of internal property
[[Class]]
).Parameters:
Name Type Description value
Any Value whose class should be determined.
Returns:
String indicating value class.
- Type
- String
-
<static> getFields(obj, settings) → {Array}
-
Return list of all or filtered fields of specified object.
Parameters:
Name Type Argument Description obj
Object Object to be processed.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
filter
- a filter specifying fields that should be selected (see checkField)filterConnect
:String
- a boolean connector that should be used when array of filters is specified infilter
setting (see checkField)
- See:
Returns:
List of all or filtered fields of specified object.
- Type
- Array
-
<static> getFreeField(obj, settings) → {String}
-
Return name of first free (absent) field of specified object, that conforms to the following pattern: <prefix><number>
Parameters:
Name Type Argument Description obj
Object Object in which a free field should be found. If
null
(or any false value) is set, the first value that conforms to the pattern will be returned.settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported (setting's default value is specified in parentheses):
checkPrefix
:Boolean
(false
) - specifies whether pattern consisting only from prefix (without number) should be checkedprefix
:String
(f
) - prefix of sought fieldstartNum
:Integer
(0
) - starting number which is used as part of pattern by search/check
Returns:
Name of field which is absent in the specified object and conforms to the pattern.
- Type
- String
-
<static> getSize(obj, settings) → {Integer}
-
Return number of all or filtered fields of specified object.
Parameters:
Name Type Argument Description obj
Object Object to be processed.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
filter
- a filter specifying fields that should be counted (see checkField)filterConnect
:String
- a boolean connector that should be used when array of filters is specified infilter
setting (see checkField)
- See:
Returns:
Number of all or filtered fields of specified object.
- Type
- Integer
-
<static> getType(value) → {String}
-
Return type of given value.
Parameters:
Name Type Description value
Any Value whose type should be determined.
Returns:
For
NaN
-'nan'
, fornull
-'null'
, otherwise - result oftypeof
operator.- Type
- String
-
<static> getValueKey(obj, value, bAll) → {Array|String|null}
-
Return the name of field (or list of names) having the specified value in the given object.
Parameters:
Name Type Argument Description obj
Object Object to be checked.
value
Any Value that should be searched for.
bAll
Boolean <optional>
Whether names of all found fields having the specified value should be returned. Default value is
false
.Returns:
Names of fields (when
bAll
istrue
) or a field name having the specified value, ornull
when the object do not contain the specified value.- Type
- Array | String | null
-
<static> getValues(obj, settings) → {Array}
-
Return list of all or filtered field values of specified object.
Parameters:
Name Type Argument Description obj
Object Object to be processed.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
filter
- a filter specifying fields that should be selected (see checkField)filterConnect
:String
- a boolean connector that should be used when array of filters is specified infilter
setting (see checkField)
- See:
Returns:
List of all or filtered field values of specified object.
- Type
- Array
-
<static> isEmpty(value) → {Boolean}
-
Check whether given value is an empty value i.e.
null
,undefined
, empty object, empty array or empty string.Parameters:
Name Type Description value
Any Value to be checked.
- See:
Returns:
true
if the value is an empty value, otherwisefalse
.- Type
- Boolean
-
<static> isKindOf(value, sKind) → {Boolean}
-
Check whether given value has (or does not have) specified kind (type or class).
Parameters:
Name Type Description value
Any Value to be checked.
sKind
String Type or class for check. Can be any value that is returned by getType and getClass, or one of the following:
empty
- check whether the value is empty (see isEmpty)even
- check whether the value is an even integerfalse
- check whether the value is a false valueinfinity
- check whether the value is a number representing positive or negative infinityinteger
- check whether the value is an integer numbernegative
- check whether the value is a negative numberodd
- check whether the value is an odd integerpositive
- check whether the value is a positive numberreal
- check whether the value is a real numbertrue
- check whether the value is a true valuezero
- check whether the value is0
If exclamation mark (
!
) is set before the kind, it means that the check should be negated i.e. check whether given value does not have the specified kind. For example,!real
means: check whether the value is not a real number.
Returns:
true
if value has the specified kind (or does not have when the check is negated), otherwisefalse
.- Type
- Boolean
-
<static> isSizeMore(obj, nValue, settings) → {Boolean}
-
Check whether number of all or filtered fields of specified object is more than the given value.
Parameters:
Name Type Argument Description obj
Object Object to be checked.
nValue
Number Value that should be used for comparison with number of fields.
settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
filter
- a filter specifying fields that should be counted (see checkField)filterConnect
:String
- a boolean connector that should be used when array of filters is specified infilter
setting (see checkField)
- See:
Returns:
true
, when number of all or filtered fields is more than the given value, otherwisefalse
.- Type
- Boolean
-
<static> split(obj, firstObjFields, settings) → {Array}
-
Divide given object into 2 parts: the first part includes specified fields, the second part includes all other fields.
Parameters:
Name Type Argument Description obj
Object Object to be divided.
firstObjFields
Array | Object | null List of names of fields that should be included in the first part, or an object defining those fields. If value is not specified (
null
orundefined
),filter
setting should be used to divide fields into parts.settings
Object <optional>
Operation settings. Keys are settings names, values are corresponding settings values. The following settings are supported:
filter
- a filter that should be used to divide fields into parts (see checkField); fields conforming to the filter will be included in the first part, fields that do not conform to the filter will be included in the second partfilterConnect
:String
- a boolean connector that should be used when array of filters is specified infilter
setting (see checkField)
- See:
Returns:
Created parts: item with index 0 is the first part, item with index 1 is the second part.
- Type
- Array