README

The WMA - Matching Algorithm is a light-weighted and fast library to match an object against an object array. Define matching keys and match. Make as many matching objects as you want.
WMA - Matching Algorithm
Install
Install with npm:
$ npm install --save-dev wma-matching-algorithm
Install with yarn:
$ yarn add wma-matching-algorithm --dev
Usage
Import the library
import WMA from 'wma-matching-algorithm' //ES6
//or
var WMA = require('wma-matching-algorithm'); //nodejs
or download the lib folder and add the script tag:
<script src="./Path-to-lib/wma.js" charset="utf-8"></script>
Tip: If you use a script tag pleas add this before closing the body tag.
Declare a new instance
Making new instance of the WMA Class
const wma = new WMA({
source: data, // The object array
matchIndex: 10, // Optional - add number on 10 first items.
showOriginal: true, // Optional - keep same matching object in results.
decimals: 2, // Optional - Numbers of decimals for matching percent.
verbose: true, // Optional - Give output.
keys: [ // Array of all keys.
{
key: `matching-one`, // Name of the key.
m: 20 // Number of importance.
},
{key: `matching-two`, m: 50}
]
})
source
This is simply the full dataset, the object array with all the matching objects.
matchIndex
optional - If you define this the output object will contain a key matchIndex
. This can be used for pagination. If the matchIndex is default set to 10. This means every 10the object the index will increase.
showOriginal
optional - If this is set to True
. The result array will contain the object of matching if this object is in the array. Default it's set False
.
decimals
optional - If you define this param each item in item of your result array will contain a percent with 2 digits after the comma. Default it set to 2
.
verbose
optional - Default set False
. If set True
, you can see output of the library in your console.
Keys
Keys is an object array that define every matching key with a multiplier. The highest multiplier has the most impact on the matching result.
keys: [
{
key: 'string',
m: number
},
{
key: 'height',
m: 10
}
...
]
You can define as many keys as you want. The multiplier can have a positive or negative number.
Match
The match is a function that allows you to match any object to the defined object array.
wma.match({
id: 1,
height: 10,
width: 5,
color: 'purple'
});
object
The object is an single object containing key values.
{
id: 1,
height: 10,
width: 5,
color: 'purple'
}
Note: At least one key must be defined in the keys array when declaring a new instance.
Examples
You'll find an example of the matching in the demo directory.
Feel free to contribute more!
Running the tests
We use Jest for testing. If you want to run these tests type folowing command in your terminal.
using npm:
$ npm run test
using yarn:
$ yarn test
All testes are located in the test directory. Some included are:
Feel free to contribute more!
FAQ
Can I write unit tests with this library?
Definitely yes! You can write unit and integration tests with this library.The tests in this project show several examples of unit testing with this library.
Can I hide the matching object in the results?
Yes you can set a parameter when declaring an new instance: showOriginal: true || false
.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Write code in the src directory. The source code will compile and placed in the lib directory. Open a browser an serve to localhost:3000
and you'll see the contents of the demo directory that use the new compiled WMA Library.
If you want to contribute you need to install all packages who are required and start the compiler. Just use the command:
using npm:
$ npm install && npm run start
using yarn:
$ yarn && yarn start
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Gert-Jan Wille - Initial work - gert-janwille
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details
Acknowledgments
- Accomplished by De Jongens Van Boven