Skip to content

Commit

Permalink
Uniqueness now includes counts by default
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed May 8, 2018
1 parent 5de7378 commit a09f304
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 214 deletions.
9 changes: 4 additions & 5 deletions src/analyzer/atrules/fontfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = atRules => {
.map(rule => rule.descriptors)

// Tricky bit: uniqueness will be based on the `src` of the @font-face
const uniqueWithCount = uniquer(
const unique = uniquer(
all.map(ff => ff.src)
).uniqueWithCount.map(item => {
).unique.map(item => {
// Once we have a list of unique @font-faces,
// we'll map it back to the original values again
return {
Expand All @@ -19,8 +19,7 @@ module.exports = atRules => {

return {
total: all.length,
unique: uniqueWithCount.map(item => item.value),
totalUnique: uniqueWithCount.length,
uniqueWithCount
unique,
totalUnique: unique.length
}
}
11 changes: 4 additions & 7 deletions src/utils/uniquer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ module.exports = (values, sortFn) => {
.map(el => el.value)
.sort(sortFn)

const final = sorted
.map(el => {
return reduced.find(r => r.value === el)
})
const unique = sorted
.map(value => reduced.find(r => r.value === value))

return {
unique: final.map(v => v.value),
totalUnique: final.length,
uniqueWithCount: final
unique,
totalUnique: unique.length
}
}
3 changes: 1 addition & 2 deletions test/analyzer/atrules/charsets/output.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"total": 1,
"unique": ["'UTF-8'"],
"totalUnique": 1,
"uniqueWithCount": [{
"unique": [{
"value": "'UTF-8'",
"count": 1
}]
Expand Down
5 changes: 1 addition & 4 deletions test/analyzer/atrules/documents/output.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"total": 1,
"unique": [
"url('https://example.com')"
],
"totalUnique": 1,
"uniqueWithCount": [
"unique": [
{
"value": "url('https://example.com')",
"count": 1
Expand Down
31 changes: 0 additions & 31 deletions test/analyzer/atrules/fontfaces/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@
"total": 6,
"totalUnique": 5,
"unique": [
{
"font-display": "swap",
"font-family": "monospace",
"font-stretch": "condensed",
"font-style": "italic",
"font-weight": "bold",
"font-variant": "no-common-ligatures proportional-nums",
"font-feature-settings": "\"liga\" 0",
"font-variation-settings": "\"xhgt\" 0.7",
"src": "local('Input Mono')",
"unicode-range": "U+0025-00FF"
},
{
"font-family": "MyHelvetica",
"src": "local(\"Helvetica Neue Bold\"), local(\"HelveticaNeue-Bold\"), url(MgOpenModernaBold.ttf)",
"font-weight": "bold"
},
{
"src": "url('https://example.com')",
"font-family": "'Example Duplicate'"
},
{
"font-family": "\"Open Sans\"",
"src": "url(\"/fonts/OpenSans-Regular-webfont.woff2\") format(\"woff2\"), url(\"/fonts/OpenSans-Regular-webfont.woff\") format(\"woff\")"
},
{
"font-family": "\"Bitstream Vera Serif Bold\"",
"src": "url(\"https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf\")"
}
],
"uniqueWithCount": [
{
"count": 1,
"value": {
Expand Down
6 changes: 0 additions & 6 deletions test/analyzer/atrules/imports/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"total": 4,
"totalUnique": 4,
"unique": [
"'https://example.com/without-url'",
"url('https://example.com/with-media-query') screen and (min-width: 33em)",
"url('https://example.com/with-multiple-media-queries') screen, projection",
"url('https://example.com/with-url')"
],
"uniqueWithCount": [
{
"value": "'https://example.com/without-url'",
"count": 1
Expand Down
4 changes: 0 additions & 4 deletions test/analyzer/atrules/keyframes/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"total": 5,
"totalUnique": 2,
"unique": [
"fontbulger",
"NAME-YOUR-ANIMATION"
],
"uniqueWithCount": [
{
"value": "fontbulger",
"count": 1
Expand Down
8 changes: 0 additions & 8 deletions test/analyzer/atrules/mediaqueries/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
"total": 8,
"totalUnique": 6,
"unique": [
"(max-width: 200px)",
"(min-width: 20px)",
"print",
"screen",
"screen and (min-width: 33em)",
"screen or print"
],
"uniqueWithCount": [
{
"value": "(max-width: 200px)",
"count": 1
Expand Down
4 changes: 0 additions & 4 deletions test/analyzer/atrules/namespaces/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
"total": 2,
"totalUnique": 2,
"unique": [
"svg url(http://www.w3.org/2000/svg)",
"url(http://www.w3.org/1999/xhtml)"
],
"uniqueWithCount": [
{
"value": "svg url(http://www.w3.org/2000/svg)",
"count": 1
Expand Down
6 changes: 0 additions & 6 deletions test/analyzer/atrules/pages/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"total": 4,
"totalUnique": 4,
"unique": [
"",
":first",
":left",
":right"
],
"uniqueWithCount": [
{
"value": "",
"count": 1
Expand Down
5 changes: 0 additions & 5 deletions test/analyzer/atrules/supports/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"total": 4,
"totalUnique": 3,
"unique": [
"(-webkit-appearance:none)",
"(display: table-cell) and (display: list-item)",
"(filter: blur(5px))"
],
"uniqueWithCount": [
{
"value": "(-webkit-appearance:none)",
"count": 2
Expand Down
54 changes: 18 additions & 36 deletions test/analyzer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,47 @@ test('Returns the correct analysis object structure', async t => {
charsets: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
documents: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
fontfaces: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
imports: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
keyframes: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
mediaqueries: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
namespaces: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
pages: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
supports: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
}
},
declarations: {
Expand All @@ -81,13 +72,11 @@ test('Returns the correct analysis object structure', async t => {
share: 0,
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
rules: {
total: 1
Expand All @@ -96,8 +85,7 @@ test('Returns the correct analysis object structure', async t => {
id: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
identifiers: {
average: 1,
Expand All @@ -111,8 +99,7 @@ test('Returns the correct analysis object structure', async t => {
js: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
specificity: {
top: [
Expand All @@ -132,8 +119,7 @@ test('Returns the correct analysis object structure', async t => {
universal: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
}
},
stylesheets: {
Expand All @@ -147,27 +133,23 @@ test('Returns the correct analysis object structure', async t => {
colors: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
fontfamilies: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
fontsizes: {
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
prefixed: {
share: 0,
total: 0,
totalUnique: 0,
unique: [],
uniqueWithCount: []
unique: []
},
total: 0
}
Expand Down
16 changes: 0 additions & 16 deletions test/analyzer/properties/output.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
{
"total": 12,
"unique": [
"-moz-border-radius",
"-o-border-radius",
"-webkit-border-radius",
"background-image",
"border-radius",
"margin",
"opacity",
"property",
"zoom"
],
"uniqueWithCount": [
{
"value": "-moz-border-radius",
"count": 1
Expand Down Expand Up @@ -53,11 +42,6 @@
"prefixed": {
"total": 3,
"unique": [
"-moz-border-radius",
"-o-border-radius",
"-webkit-border-radius"
],
"uniqueWithCount": [
{
"value": "-moz-border-radius",
"count": 1
Expand Down
27 changes: 0 additions & 27 deletions test/analyzer/selectors/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
"total": 6,
"totalUnique": 6,
"unique": [
".adjecent.js-selector",
".js-toggle-item",
".JSFOO",
"[class*=\"js-selector\"]",
"[id='js-selector']",
"#jsSelector"
],
"uniqueWithCount": [
{
"value": ".adjecent.js-selector",
"count": 1
Expand Down Expand Up @@ -43,12 +35,6 @@
"total": 4,
"totalUnique": 4,
"unique": [
".Foo > .Bar ~ .Baz [type=\"text\"] + span:before #bazz #fizz #buzz #drank #drugs",
"#foo",
"#jsSelector",
"#multipe #ids #counted #as #one"
],
"uniqueWithCount": [
{
"value": ".Foo > .Bar ~ .Baz [type=\"text\"] + span:before #bazz #fizz #buzz #drank #drugs",
"count": 1
Expand All @@ -71,19 +57,6 @@
"total": 12,
"totalUnique": 11,
"unique": [
".foo *",
".foo * .bar",
".selector:not(*:root)",
"*",
"* + html .selector",
"* html .selector",
"*:first-child + html .selector",
"*:first-child+html .selector",
"*+html .selector",
"*|html[xmlns*=\"\"] .selector",
"body*.selector"
],
"uniqueWithCount": [
{
"value": ".foo *",
"count": 1
Expand Down
Loading

0 comments on commit a09f304

Please sign in to comment.