File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 11const flatfile = require ( 'flat-file-db' )
22const promisify = require ( 'then-flat-file-db' )
3+ const escapeRegexp = require ( 'escape-regex' )
34
45const db = promisify ( flatfile . sync ( process . env . DB_NAME || 'views.db' ) )
56
7+ const keyRegex = ( str ) => {
8+ str = str . split ( '*' ) . map ( s => escapeRegexp ( s ) ) . join ( '*' )
9+ return new RegExp ( '^' + str . replace ( '*' , '.*' ) )
10+ }
11+
612module . exports = {
713 put : db . put . bind ( db ) ,
814 has : ( key ) => Promise . resolve ( db . has ( key ) ) ,
@@ -27,7 +33,9 @@ module.exports = {
2733 // Get all values starting with a certain pathname and filter their views
2834 getAll : async function getAll ( options ) {
2935 const data = { }
30- const keys = ( await module . exports . keys ( ) ) . filter ( key => key . startsWith ( options . pathname ) )
36+ const keys = ( await module . exports . keys ( ) ) . filter ( ( key ) => {
37+ return options . ignoreWildcard ? key . startsWith ( options . pathname ) : key . match ( keyRegex ( options . pathname ) )
38+ } )
3139
3240 for ( let key of keys ) {
3341 data [ key ] = await module . exports . get ( key , { before : options . before , after : options . after } )
Original file line number Diff line number Diff line change 2424 },
2525 "homepage" : " https://github.com/mxstbr/micro-analytics-adapter-flat-file-db#readme" ,
2626 "dependencies" : {
27+ "escape-regex" : " ^1.0.7" ,
2728 "flat-file-db" : " ^1.0.0" ,
2829 "then-flat-file-db" : " ^1.0.0"
2930 },
You can’t perform that action at this time.
0 commit comments