0.2.0 • Published 6 months ago
@shvmeless/dictionary v0.2.0
Dictionary JS
A dictionary is defined as an object containing an indefinite number of properties (entries), all of which share values of the same data type. The Dictionary
class allows you to manipulate these dictionaries in a manner similar to arrays.
Dictionary Class
The Dictionary
class is designed to work with dictionaries as a unique element, where all changes made to the dictionary will be reflected in real time.
The following methods are available on a Dictionary
instance:
method | description |
---|---|
record | Returns a Record containing all current dictionary entries. |
keys | Returns an Array containing the keys of all dictionary entries. |
values | Returns an Array containing the values of all dictionary entries. |
entries | Returns an Array containing the key-value pairs of all dictionary entries. |
size | Returns the total number of entries in the dictionary. |
get | Returns the value associated with a specific key in the dictionary. |
set | Assigns a value to a specific key in the dictionary. |
rename | Renames the key of a specific dictionary entry. |
random | Returns a random key-value pair from the dictionary. |
copy | Creates and returns a new Dictionary instance containing a copy of all entries from the current dictionary. |
has | Returns true if the specified keys exist in the dictionary, otherwise returns false . |
hasOneOf | Returns true if at least one of the specified keys exists in the dictionary, otherwise returns false . |
includes | Returns true if all specified values exist in the dictionary, otherwise returns false . |
includesOneOf | Returns true if at least one of the specified values exists in the dictionary, otherwise returns false . |
clear | Removes all entries from the dictionary. |
retain | Keeps entries matching at least one of the provided keys and removes the rest. |
delete | Removes entries matching at least one of the provided keys. |
retainValues | Keeps entries matching at least one of the provided values and removes the rest. |
deleteValues | Removes entries matching at least one of the provided values. |
merge | Combines the dictionary with another object, overwriting duplicate entries and adding new ones. |
mergeDifference | Combines the dictionary with another object, adding new entries and ignoring duplicates. |
mergeIntersection | Combines the dictionary with another object, overwriting only the duplicate entries. |
difference | Combines the dictionary with another object, adding new entries and removing duplicates. |
intersection | Combines the dictionary with another object, retaining only the duplicate entries and removing the rest. |
forEach | Executes a provided function for each entry in the dictionary. |
some | Returns true if at least one entry satisfies the provided condition, otherwise false . |
every | Returns true if all entries satisfy the provided condition, otherwise false . |
find | Returns one of the entries that satisfies the provided condition, or undefined if none is found. |
count | Returns the number of entries that satisfy the provided condition. |
reduce | Applies a cumulative function to all dictionary entries, returning the accumulated result. |
filter | Filters the dictionary, removing entries that do not satisfy the provided condition. |
map | Returns a new Dictionary , mapping each entry to a new value based on the provided function. |
transformKeys | Transforms the keys of all dictionary entries based on the provided function. |
transformValues | Transforms the values of all dictionary entries based on the provided function. |
transformEntries | Transforms both keys and values of all dictionary entries based on the provided function. |
Dictionary Module
The dictionary
module is an alternative to thedictionary
class, which provides a series of functions to manipulate dictionaries more independent and flexible.
The following functions are available on the dictionary
module:
method | description |
---|---|
keys | Returns an Array containing the keys of all dictionary entries. |
values | Returns an Array containing the values of all dictionary entries. |
entries | Returns an Array containing the key-value pairs of all dictionary entries. |
size | Returns the total number of entries in the dictionary. |
get | Returns the value associated with a specific key in the dictionary. |
set | Returns a copy of the dictionary and assigns a value to a specific key. |
rename | Returns a copy of the dictionary and renames the key of a specific dictionary entry. |
random | Returns a random key-value pair from the dictionary. |
has | Returns true if the specified keys exist in the dictionary, otherwise returns false . |
hasOneOf | Returns true if at least one of the specified keys exists in the dictionary, otherwise returns false . |
includes | Returns true if all specified values exist in the dictionary, otherwise returns false . |
includesOneOf | Returns true if at least one of the specified values exists in the dictionary, otherwise returns false . |
retain | Returns a copy of the dictionary, keeps entries matching at least one of the provided keys and removes the rest. |
delete | Returns a copy of the dictionary, removes entries matching at least one of the provided keys. |
retainValues | Returns a copy of the dictionary, keeps entries matching at least one of the provided values and removes the rest. |
deleteValues | Returns a copy of the dictionary, removes entries matching at least one of the provided values. |
merge | Returns the combination of the dictionary with another dictionary, overwriting duplicate entries and adding new ones. |
mergeDifference | Returns the combination of the dictionary with another dictionary, adding new entries and ignoring duplicates. |
mergeIntersection | Returns the combination of the dictionary with another dictionary, overwriting only the duplicate entries. |
difference | Returns the combination of the dictionary with another dictionary, adding new entries and removing duplicates. |
intersection | Returns the combination of the dictionary with another dictionary, retaining only the duplicate entries and removing the rest. |
forEach | Executes a provided function for each entry in the dictionary. |
some | Returns true if at least one entry satisfies the provided condition, otherwise false . |
every | Returns true if all entries satisfy the provided condition, otherwise false . |
find | Returns one of the entries that satisfies the provided condition, or undefined if none is found. |
count | Returns the number of entries that satisfy the provided condition. |
reduce | Applies a cumulative function to all dictionary entries, returning the accumulated result. |
filter | Returns a copy of the dictionary, removing entries that do not satisfy the provided condition. |
transformKeys | Returns the result of transforming the keys of the dictionary entries based on the provided function. |
transformValues | Returns the result of transforming the values of the dictionary entries based on the provided function. |
transformEntries | Returns the result of transforming both the keys and values of the dictionary entries based on the provided function. |