ToUpperExpression.js 960 B

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