cleanPositionalOperators.js 331 B

123456789101112
  1. 'use strict';
  2. /**
  3. * For consistency's sake, we replace positional operator `$` and array filters
  4. * `$[]` and `$[foo]` with `0` when looking up schema paths.
  5. */
  6. module.exports = function cleanPositionalOperators(path) {
  7. return path.
  8. replace(/\.\$(\[[^\]]*\])?(?=\.)/g, '.0').
  9. replace(/\.\$(\[[^\]]*\])?$/g, '.0');
  10. };