File tree Expand file tree Collapse file tree 1 file changed +1
-32
lines changed Expand file tree Collapse file tree 1 file changed +1
-32
lines changed Original file line number Diff line number Diff line change 1
1
const distance = require ( "jaro-winkler" ) ;
2
2
3
3
module . exports = {
4
- getBazaarProduct : ( query , products ) => {
5
- let resultMatch ;
6
- let itemResults = [ ] ;
7
- for ( const key in products ) {
8
- itemResults . push ( { ...products [ key ] } ) ;
9
- }
10
- for ( const product of itemResults ) {
11
- if ( product . name . toLowerCase ( ) == query ) {
12
- resultMatch = product ;
13
- }
14
- product . tagMatches = 0 ;
15
- product . distance = distance ( product . name , query , { caseSensitive : false } ) ;
16
- for ( const part of query . split ( " " ) ) {
17
- for ( const tag of product . tag ) {
18
- if ( tag == part ) {
19
- product . tagMatches ++ ;
20
- }
21
- }
22
- }
23
- }
24
- itemResults = itemResults . sort ( ( a , b ) => {
25
- if ( a . tagMatches > b . tagMatches ) return - 1 ;
26
- if ( a . tagMatches < b . tagMatches ) return 1 ;
27
- if ( a . distance > b . distance ) return - 1 ;
28
- if ( a . distance < b . distance ) return 1 ;
29
- } ) ;
30
- if ( ! resultMatch ) {
31
- resultMatch = itemResults [ 0 ] ;
32
- }
33
- return resultMatch ;
34
- } ,
35
4
formatNumber : ( number , floor , rounding = 10 ) => {
36
5
let roundFunc = floor ? Math . floor : Math . ceil ;
37
6
if ( number < 1000 ) {
@@ -46,4 +15,4 @@ module.exports = {
46
15
return ( roundFunc ( number / 1000 / 1000 / 1000 * rounding * 10 ) / ( rounding * 10 ) ) . toFixed ( rounding . toString ( ) . length ) + 'B' ;
47
16
}
48
17
}
49
- }
18
+ }
You can’t perform that action at this time.
0 commit comments