opposite-position.js 823 B

1234567891011121314151617181920212223242526272829303132
  1. var utils = require('../utils')
  2. , nodes = require('../nodes');
  3. /**
  4. * Return the opposites of the given `positions`.
  5. *
  6. * Examples:
  7. *
  8. * opposite-position(top left)
  9. * // => bottom right
  10. *
  11. * @param {Expression} positions
  12. * @return {Expression}
  13. * @api public
  14. */
  15. (module.exports = function oppositePosition(positions){
  16. var expr = [];
  17. utils.unwrap(positions).nodes.forEach(function(pos, i){
  18. utils.assertString(pos, 'position ' + i);
  19. pos = (function(){ switch (pos.string) {
  20. case 'top': return 'bottom';
  21. case 'bottom': return 'top';
  22. case 'left': return 'right';
  23. case 'right': return 'left';
  24. case 'center': return 'center';
  25. default: throw new Error('invalid position ' + pos);
  26. }})();
  27. expr.push(new nodes.Literal(pos));
  28. });
  29. return expr;
  30. }).raw = true;