join-media.js 872 B

12345678910111213141516171819202122232425262728
  1. "use strict"
  2. const startsWithKeywordRegexp = /^(all|not|only|print|screen)/i
  3. module.exports = function (parentMedia, childMedia) {
  4. if (!parentMedia.length && childMedia.length) return childMedia
  5. if (parentMedia.length && !childMedia.length) return parentMedia
  6. if (!parentMedia.length && !childMedia.length) return []
  7. const media = []
  8. parentMedia.forEach(parentItem => {
  9. const parentItemStartsWithKeyword = startsWithKeywordRegexp.test(parentItem)
  10. childMedia.forEach(childItem => {
  11. const childItemStartsWithKeyword = startsWithKeywordRegexp.test(childItem)
  12. if (parentItem !== childItem) {
  13. if (childItemStartsWithKeyword && !parentItemStartsWithKeyword) {
  14. media.push(`${childItem} and ${parentItem}`)
  15. } else {
  16. media.push(`${parentItem} and ${childItem}`)
  17. }
  18. }
  19. })
  20. })
  21. return media
  22. }