Similify is a versatile JavaScript package designed to simplify and enhance similarity comparisons in various contexts. Whether you're comparing words, objects, arrays, or exploring string lengths and numerical ranges, Similify provides an easy-to-use interface with customizable thresholds. Effortlessly find the most similar instances and match percentages, making complex comparisons a breeze. Streamline your similarity analysis and unlock new possibilities with Similify.
npm install similify
Require Similify in your JavaScript file and start using its functions:
const { compareWords } = require('similify');
// Example usage with default threshold (70)
const result = compareWords("apple", "orange");
console.log(result);
// Output: { mostSimilar: 'orange', matchPercentage: 71.43 }
const { wordToObjectArrayComparison } = require('similify');
const objectsArray = [{ name: "banana" }, { name: "orange" }];
const result = wordToObjectArrayComparison("apple", objectsArray, "name");
console.log(result);
// Output: { mostSimilar: 'orange', matchPercentage: 71.43 }
const { compareObjects } = require('similify');
// Example usage with default threshold (70)
const result = compareObjects({ a: 1, b: 2 }, { a: 1, b: 3 });
console.log(result);
// Output: { mostSimilar: '{"a":1,"b":2}', matchPercentage: 71.43 }
const { compareArrayPlaces } = require('similify');
const array1 = ["apple", "banana"];
const array2 = ["orange", "banana"];
const result = compareArrayPlaces(array1, 0, array2, 1);
console.log(result);
// Output: { mostSimilar: 'banana', matchPercentage: 71.43 }
const { compareWordToArray } = require('similify');
const word = "apple";
const array = ["orange", "banana", "grape"];
const result = compareWordToArray(word, array);
console.log(result);
// Output: { mostSimilar: 'grape', matchPercentage: 57.14 }
const { compareArrays } = require('similify');
const array1 = ["apple", "banana"];
const array2 = ["orange", "banana", "grape"];
const result = compareArrays(array1, array2);
console.log(result);
// Output: { mostSimilar: ['banana'], matchPercentage: 66.67 }
const { compareStringLength } = require('similify');
const result = compareStringLength("apple", "orange");
console.log(result);
// Output: { longerString: 'orange', lengthDifference: 1 }
const { compareNumberToRange } = require('similify');
const result = compareNumberToRange(25, 20, 30);
console.log(result);
// Output: { withinRange: true, deviationFromMidpoint: 2.5 }
This function compares two words, word1
and word2
, by calculating the similarity percentage based on letter matching. The default threshold is set to 70, and the function returns an object with the most similar word and the match percentage.
This function compares a word to the values of a specified key within an array of objects (objectArray
). It calculates the similarity percentage for each value and returns an object containing the most similar object instance and the corresponding match percentage.
Compares two objects (obj1
and obj2
) by converting them to JSON strings and then calculating the similarity percentage based on letter matching. The default threshold is set to 70, and the function returns an object with the most similar object and the match percentage.
Compares two elements at specified indices (index1
and index2
) within two arrays (array1
and array2
). It calculates the similarity percentage based on letter matching and returns an object with the most similar element and the match percentage. The default threshold is set to 70.
Compares a word to each element in an array (array
). It calculates the similarity percentage for each element and returns an object with the most similar element and the match percentage. The default threshold is set to 70.
Compares each element in two arrays (array1
and array2
). It calculates the similarity percentage for each pair of elements and returns an object with the most similar elements and the match percentage. The default threshold is set to 70.
Compares the lengths of two strings (str1
and str2
). It returns an object with the longer string and the absolute difference in length between the two strings.
Checks if a number is within a specified range (min
to max
). It returns an object with a boolean indicating whether the number is within the range and the deviation of the number from the midpoint of the range.
These functions provide a variety of comparison functionalities, allowing users to find similarities in words, objects, arrays, string lengths, and numerical ranges. Users can also customize the threshold for similarity based on their specific requirements.
For support and discussions, join our Telegram channel: AutomationCore
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.