forked from postcss/postcss-import
/
join-media.js
28 lines (22 loc) · 867 Bytes
/
join-media.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict"
const startsWithKeywordRegexp = /^(all|not|screen|print)/i
module.exports = function (parentMedia, childMedia) {
if (!parentMedia.length && childMedia.length) return childMedia
if (parentMedia.length && !childMedia.length) return parentMedia
if (!parentMedia.length && !childMedia.length) return []
const media = []
parentMedia.forEach(parentItem => {
const parentItemStartsWithKeyword = startsWithKeywordRegexp.test(parentItem)
childMedia.forEach(childItem => {
const childItemStartsWithKeyword = startsWithKeywordRegexp.test(childItem)
if (parentItem !== childItem) {
if (childItemStartsWithKeyword && !parentItemStartsWithKeyword) {
media.push(`${childItem} and ${parentItem}`)
} else {
media.push(`${parentItem} and ${childItem}`)
}
}
})
})
return media
}