@fireproof/core 0.6.4 → 0.6.6

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.
@@ -41709,12 +41709,21 @@ class DbIndex {
41709
41709
  applyMapFn (mapFn, name) {
41710
41710
  if (typeof mapFn === 'string') {
41711
41711
  this.mapFnString = mapFn;
41712
+ // make a regex that matches strings that only have letters, numbers, and spaces
41713
+ const regex = /^[a-zA-Z0-9 ]+$/;
41714
+ // if the string matches the regex, make a function that returns the value at that key
41715
+ if (regex.test(mapFn)) {
41716
+ this.mapFn = (doc, emit) => {
41717
+ if (doc[mapFn]) emit(doc[mapFn]);
41718
+ };
41719
+ this.includeDocsDefault = true;
41720
+ }
41712
41721
  } else {
41713
41722
  this.mapFn = mapFn;
41714
41723
  this.mapFnString = mapFn.toString();
41715
41724
  }
41716
41725
  const matches = /=>\s*(.*)/.exec(this.mapFnString);
41717
- this.includeDocsDefault = matches && matches.length > 0;
41726
+ this.includeDocsDefault = this.includeDocsDefault || (matches && matches.length > 0);
41718
41727
  this.name = name || this.makeName();
41719
41728
  }
41720
41729