@@ -9,8 +9,8 @@ var pluralize = require('pluralize')
99function  toNative  ( value )  { 
1010  if  ( typeof  value  ===  'string' )  { 
1111    if  ( value  ===  '' 
12-     ||  value . trim ( )  !==  value 
13-     ||  ( value . length  >  1  &&  value [ 0 ]  ===  '0' ) )  { 
12+         ||  value . trim ( )  !==  value 
13+         ||  ( value . length  >  1  &&  value [ 0 ]  ===  '0' ) )  { 
1414      return  value 
1515    }  else  if  ( value  ===  'true'  ||  value  ===  'false' )  { 
1616      return  value  ===  'true' 
@@ -44,7 +44,7 @@ function createId (coll) {
4444// Example: a comment that references a post that doesn't exist 
4545function  getRemovable  ( db )  { 
4646  var  removable  =  [ ] 
47- 
47+    console . log ( db ) 
4848  _ ( db ) . each ( function  ( coll ,  collName )  { 
4949    _ ( coll ) . each ( function  ( doc )  { 
5050      _ ( doc ) . each ( function  ( value ,  key )  { 
@@ -66,8 +66,29 @@ function getRemovable (db) {
6666  return  removable 
6767} 
6868
69+ function  deepQuery  ( value ,  q )  { 
70+   if  ( value  &&  q )  { 
71+     if  ( _ . isArray ( value ) )  { 
72+       for  ( var  i  =  0 ;  i  <  value . length ;  i ++ )  { 
73+         if  ( deepQuery ( value [ i ] ,  q ) )  { 
74+           return  true 
75+         } 
76+       } 
77+     }  else  if  ( _ . isObject ( value )  &&  ! _ . isArray ( value ) )  { 
78+       for  ( var  k  in  value )  { 
79+         if  ( deepQuery ( value [ k ] ,  q ) )  { 
80+           return  true 
81+         } 
82+       } 
83+     }  else  if  ( value . toString ( ) . toLowerCase ( ) . indexOf ( q )  !==  - 1 )  { 
84+       return  true 
85+     } 
86+   } 
87+ } 
88+ 
6989module . exports  =  { 
7090  toNative : toNative , 
7191  createId : createId , 
72-   getRemovable : getRemovable 
92+   getRemovable : getRemovable , 
93+   deepQuery : deepQuery 
7394} 
0 commit comments