@fireproof/core 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -127,13 +127,23 @@ export class DbIndex {
127
127
  applyMapFn(mapFn, name) {
128
128
  if (typeof mapFn === 'string') {
129
129
  this.mapFnString = mapFn;
130
+ // make a regex that matches strings that only have letters, numbers, and spaces
131
+ const regex = /^[a-zA-Z0-9 ]+$/;
132
+ // if the string matches the regex, make a function that returns the value at that key
133
+ if (regex.test(mapFn)) {
134
+ this.mapFn = (doc, emit) => {
135
+ if (doc[mapFn])
136
+ emit(doc[mapFn]);
137
+ };
138
+ this.includeDocsDefault = true;
139
+ }
130
140
  }
131
141
  else {
132
142
  this.mapFn = mapFn;
133
143
  this.mapFnString = mapFn.toString();
134
144
  }
135
145
  const matches = /=>\s*(.*)/.exec(this.mapFnString);
136
- this.includeDocsDefault = matches && matches.length > 0;
146
+ this.includeDocsDefault = this.includeDocsDefault || (matches && matches.length > 0);
137
147
  this.name = name || this.makeName();
138
148
  }
139
149
  makeName() {
@@ -398,7 +398,7 @@ declare class DbIndex {
398
398
  applyMapFn(mapFn: any, name: any): void;
399
399
  mapFnString: any;
400
400
  mapFn: any;
401
- includeDocsDefault: boolean;
401
+ includeDocsDefault: any;
402
402
  name: any;
403
403
  makeName(): any;
404
404
  toJSON(): {
@@ -41711,12 +41711,21 @@ class DbIndex {
41711
41711
  applyMapFn (mapFn, name) {
41712
41712
  if (typeof mapFn === 'string') {
41713
41713
  this.mapFnString = mapFn;
41714
+ // make a regex that matches strings that only have letters, numbers, and spaces
41715
+ const regex = /^[a-zA-Z0-9 ]+$/;
41716
+ // if the string matches the regex, make a function that returns the value at that key
41717
+ if (regex.test(mapFn)) {
41718
+ this.mapFn = (doc, emit) => {
41719
+ if (doc[mapFn]) emit(doc[mapFn]);
41720
+ };
41721
+ this.includeDocsDefault = true;
41722
+ }
41714
41723
  } else {
41715
41724
  this.mapFn = mapFn;
41716
41725
  this.mapFnString = mapFn.toString();
41717
41726
  }
41718
41727
  const matches = /=>\s*(.*)/.exec(this.mapFnString);
41719
- this.includeDocsDefault = matches && matches.length > 0;
41728
+ this.includeDocsDefault = this.includeDocsDefault || (matches && matches.length > 0);
41720
41729
  this.name = name || this.makeName();
41721
41730
  }
41722
41731