@revmob/minimum-bid-validator
v0.1.3
Published
Revmob minimum bid validation utility
Downloads
3
Keywords
Readme
Minimum Bid Validator
Motivation
This module contains simple rules for minimum bid retrieval and validation for different countries and OSs.
Installation
npm install --save @revmob/minimum-bid-validator
Usage
// CommonJS:
const minimumBidValidator = require('@revmob/minimum-bid-validation').default
// or with ES6 modules:
import minimumBidValidator from '@revmob/minimum-bid-validation'
Public Interface
Methods
minimumBidValidator.setDefaultMinimumBid(defaults: BidInfo) => Void
minimumBidValidator.setAllBidsByCountry(bids: CountryBids) => Void
minimumBidValidator.getMinimumBid(os: String, countryList: String[]) => Number | undefined
minimumBidValidator.validate(os: String, countryList: String[], currentBid: Number) => Void, throws: Error
Types
interface BidInfo {
[os: String]: Number
}
interface CountryBids {
[countryCode: String]: BidInfo
}
Rules
getMinimumBid
- If the country list contains invalid countries, only the valid ones are considered.
- If there are no valid countries in the country list, returns the default minimum bid.
- If the country list contains all countries set in
setAllBidsByCountry
, returns the default minimum bid. - If the OS is missing for one or more of the countries, it will not be considered.
- If the OS is missing for all countries, returns
undefined
.
validate
- If the country list contains invalid countries, only the valid ones are considered.
- If there are no valid countries in the country list, uses the default minimum bid to validate.
- If the country list contains all countries set in
setAllBidsByCountry
, uses the default minimum bid to validate. - If the OS is missing for one or more of the countries, it will not be considered.
- If the OS is missing for all countries, always throws.
Example
// First setup...
const defaultBids = {
'android': 1,
'ios': 2
}
// Setting the default bids
minimumBidValidator.setDefaultMinimumBid(defaultBids)
// Setting the bids for each country
const bids = {
BR: { 'android': 1, 'ios': 1 }
US: { 'android': 2, 'ios': 2 }
IN: { 'android': 0.5, 'ios': 0.75 }
}
minimumBidValidator.setAllBidsByCountry(bids)
// Then using...
// Getting the minimum bid for android in ['BR', 'US']
minimumBidValidator.getMinimumBid('android', ['BR', 'US']) // returns 2
// Validate if a given bid is greater than or equal the minimum bid
minimumBidValidator.validate('android', ['BR', 'US'], 1) // throws Error