ExistsMatchExpression.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. var LeafMatchExpression = require('./LeafMatchExpression');
  3. // File: expression_leaf.cpp
  4. var ExistsMatchExpression = module.exports = function ExistsMatchExpression(){
  5. base.call(this);
  6. this._matchType = 'EXISTS';
  7. }, klass = ExistsMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. /**
  9. *
  10. * Writes a debug string for this object
  11. * @method debugString
  12. * @param level
  13. *
  14. */
  15. proto.debugString = function debugString(level) {
  16. return this._debugAddSpace( level ) + this.path() + " exists" + (this.getTag() ? " " + this.getTag().debugString() : "") + "\n";
  17. };
  18. /**
  19. *
  20. * checks if this expression is == to the other
  21. * @method equivalent
  22. * @param other
  23. *
  24. */
  25. proto.equivalent = function equivalent(other) {
  26. if(this._matchType !== other._matchType) {
  27. return false;
  28. }
  29. return this.path() == other.path();
  30. };
  31. /**
  32. *
  33. * Initialize the necessary items
  34. * @method init
  35. * @param path
  36. * @param type
  37. *
  38. */
  39. proto.init = function init(path) {
  40. return this.initPath( path );
  41. };
  42. /**
  43. *
  44. * Check if the input element matches
  45. * @method matchesSingleElement
  46. * @param e
  47. *
  48. */
  49. proto.matchesSingleElement = function matchesSingleElement(e) {
  50. if(typeof(e) === 'undefined')
  51. return false;
  52. if(e === null)
  53. return true;
  54. if(typeof(e) === 'object')
  55. return (Object.keys(e).length > 0);
  56. else
  57. return true;
  58. };
  59. /**
  60. *
  61. * clone this instance to a new one
  62. * @method shallowClone
  63. *
  64. */
  65. proto.shallowClone = function shallowClone(){
  66. var e = new ExistsMatchExpression();
  67. e.init(this.path());
  68. return e;
  69. };