Skip to content

Commit

Permalink
makeKeyGeneric supports $[]
Browse files Browse the repository at this point in the history
makeKeyGeneric now makes any $[<identifier>] notation generic as well
  • Loading branch information
kfritsch authored Mar 30, 2021
1 parent c795469 commit 46c642f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/mongo-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,17 @@ export default class MongoObject {

/* STATIC */

/* Takes a specific string that uses mongo-style dot notation
* and returns a generic string equivalent. Replaces all numeric
* "pieces" with a dollar sign ($).
/* Takes a specific string that uses any mongo-style positional update
* dot notation and returns a generic string equivalent. Replaces all numeric
* positional "pieces" (e.g. '.1') or any other positional operator
* (e.g. '$[<identifier>]') with a dollar sign ($).
*
* @param {type} name
* @returns {String} Generic name.
*/
static makeKeyGeneric(key) {
if (typeof key !== 'string') return null;
return key.replace(/\.[0-9]+(?=\.|$)/g, '.$');
return key.replace(/\.([0-9]+|\$\[.*\])(?=\.|$)/g, '.$');
}

/** Takes a string representation of an object key and its value
Expand Down

0 comments on commit 46c642f

Please sign in to comment.