0.2.0 • Published 6 months ago

@shvmeless/dictionary v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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:

methoddescription
recordReturns a Record containing all current dictionary entries.
keysReturns an Array containing the keys of all dictionary entries.
valuesReturns an Array containing the values of all dictionary entries.
entriesReturns an Array containing the key-value pairs of all dictionary entries.
sizeReturns the total number of entries in the dictionary.
getReturns the value associated with a specific key in the dictionary.
setAssigns a value to a specific key in the dictionary.
renameRenames the key of a specific dictionary entry.
randomReturns a random key-value pair from the dictionary.
copyCreates and returns a new Dictionary instance containing a copy of all entries from the current dictionary.
hasReturns true if the specified keys exist in the dictionary, otherwise returns false.
hasOneOfReturns true if at least one of the specified keys exists in the dictionary, otherwise returns false.
includesReturns true if all specified values exist in the dictionary, otherwise returns false.
includesOneOfReturns true if at least one of the specified values exists in the dictionary, otherwise returns false.
clearRemoves all entries from the dictionary.
retainKeeps entries matching at least one of the provided keys and removes the rest.
deleteRemoves entries matching at least one of the provided keys.
retainValuesKeeps entries matching at least one of the provided values and removes the rest.
deleteValuesRemoves entries matching at least one of the provided values.
mergeCombines the dictionary with another object, overwriting duplicate entries and adding new ones.
mergeDifferenceCombines the dictionary with another object, adding new entries and ignoring duplicates.
mergeIntersectionCombines the dictionary with another object, overwriting only the duplicate entries.
differenceCombines the dictionary with another object, adding new entries and removing duplicates.
intersectionCombines the dictionary with another object, retaining only the duplicate entries and removing the rest.
forEachExecutes a provided function for each entry in the dictionary.
someReturns true if at least one entry satisfies the provided condition, otherwise false.
everyReturns true if all entries satisfy the provided condition, otherwise false.
findReturns one of the entries that satisfies the provided condition, or undefined if none is found.
countReturns the number of entries that satisfy the provided condition.
reduceApplies a cumulative function to all dictionary entries, returning the accumulated result.
filterFilters the dictionary, removing entries that do not satisfy the provided condition.
mapReturns a new Dictionary, mapping each entry to a new value based on the provided function.
transformKeysTransforms the keys of all dictionary entries based on the provided function.
transformValuesTransforms the values of all dictionary entries based on the provided function.
transformEntriesTransforms 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:

methoddescription
keysReturns an Array containing the keys of all dictionary entries.
valuesReturns an Array containing the values of all dictionary entries.
entriesReturns an Array containing the key-value pairs of all dictionary entries.
sizeReturns the total number of entries in the dictionary.
getReturns the value associated with a specific key in the dictionary.
setReturns a copy of the dictionary and assigns a value to a specific key.
renameReturns a copy of the dictionary and renames the key of a specific dictionary entry.
randomReturns a random key-value pair from the dictionary.
hasReturns true if the specified keys exist in the dictionary, otherwise returns false.
hasOneOfReturns true if at least one of the specified keys exists in the dictionary, otherwise returns false.
includesReturns true if all specified values exist in the dictionary, otherwise returns false.
includesOneOfReturns true if at least one of the specified values exists in the dictionary, otherwise returns false.
retainReturns a copy of the dictionary, keeps entries matching at least one of the provided keys and removes the rest.
deleteReturns a copy of the dictionary, removes entries matching at least one of the provided keys.
retainValuesReturns a copy of the dictionary, keeps entries matching at least one of the provided values and removes the rest.
deleteValuesReturns a copy of the dictionary, removes entries matching at least one of the provided values.
mergeReturns the combination of the dictionary with another dictionary, overwriting duplicate entries and adding new ones.
mergeDifferenceReturns the combination of the dictionary with another dictionary, adding new entries and ignoring duplicates.
mergeIntersectionReturns the combination of the dictionary with another dictionary, overwriting only the duplicate entries.
differenceReturns the combination of the dictionary with another dictionary, adding new entries and removing duplicates.
intersectionReturns the combination of the dictionary with another dictionary, retaining only the duplicate entries and removing the rest.
forEachExecutes a provided function for each entry in the dictionary.
someReturns true if at least one entry satisfies the provided condition, otherwise false.
everyReturns true if all entries satisfy the provided condition, otherwise false.
findReturns one of the entries that satisfies the provided condition, or undefined if none is found.
countReturns the number of entries that satisfy the provided condition.
reduceApplies a cumulative function to all dictionary entries, returning the accumulated result.
filterReturns a copy of the dictionary, removing entries that do not satisfy the provided condition.
transformKeysReturns the result of transforming the keys of the dictionary entries based on the provided function.
transformValuesReturns the result of transforming the values of the dictionary entries based on the provided function.
transformEntriesReturns the result of transforming both the keys and values of the dictionary entries based on the provided function.
0.2.0

6 months ago

0.1.0

6 months ago