ToLowerExpression.js 1.1 KB

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