ToUpperExpression.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var ToUpperExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /**
  4. * A $toUpper pipeline expression.
  5. *
  6. * @see evaluate
  7. * @class ToUpperExpression
  8. * @namespace mungedb.aggregate.pipeline.expressions
  9. * @module mungedb-aggregate
  10. * @constructor
  11. **/
  12. var klass = function ToUpperExpression(){
  13. if(arguments.length !== 0) throw new Error("zero args expected");
  14. base.call(this);
  15. }, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  16. // DEPENDENCIES
  17. var Value = require("../Value");
  18. // PROTOTYPE MEMBERS
  19. proto.getOpName = function getOpName(){
  20. return "$toUpper";
  21. };
  22. proto.addOperand = function addOperand(expr) {
  23. this.checkArgLimit(1);
  24. base.prototype.addOperand.call(this, expr);
  25. };
  26. /**
  27. * Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase.
  28. **/
  29. proto.evaluate = function evaluate(doc) {
  30. this.checkArgCount(1);
  31. var val = this.operands[0].evaluate(doc),
  32. str = Value.coerceToString(val);
  33. return str.toUpperCase();
  34. };
  35. return klass;
  36. })();