Repository: projectwallace/css-analyzer (js)

Issue:
analyze box-shadows
Also important for branding

Pull request description:
add box-shadow analysis
closes #87 

Patch:
diff --git a/readme.md b/readme.md
index 23733fc..fecf8cd 100644
--- a/readme.md
+++ b/readme.md
@@ -110,6 +110,9 @@ analyze('foo{}')
 //   'stylesheets.size': 5,
 //   'stylesheets.browserhacks.total': 0,
 //   'stylesheets.browserhacks.totalUnique': 0,
+//   'values.boxshadows.total': 0,
+//   'values.boxshadows.unique': [],
+//   'values.boxshadows.totalUnique': 0,
 //   'values.browserhacks.total': 0,
 //   'values.browserhacks.unique': [],
 //   'values.browserhacks.totalUnique': 0,
diff --git a/src/analyzer/values/box-shadows.js b/src/analyzer/values/box-shadows.js
new file mode 100644
index 0000000..d7833e8
--- /dev/null
+++ b/src/analyzer/values/box-shadows.js
@@ -0,0 +1,15 @@
+const uniquer = require('../../utils/uniquer')
+
+module.exports = declarations => {
+  const all = declarations
+    .filter(({property}) => property === 'box-shadow')
+    .map(declaration => declaration.value)
+
+  const {unique, totalUnique} = uniquer(all)
+
+  return {
+    total: all.length,
+    unique,
+    totalUnique
+  }
+}
diff --git a/src/analyzer/values/index.js b/src/analyzer/values/index.js
index b2425e2..e8b2db4 100644
--- a/src/analyzer/values/index.js
+++ b/src/analyzer/values/index.js
@@ -1,12 +1,12 @@
 module.exports = declarations => {
-  const all = declarations
-    .map(declaration => declaration.value)
+  const all = declarations.map(declaration => declaration.value)
 
   const prefixed = require('./prefixed.js')(all)
   const fontsizes = require('./font-sizes.js')(declarations)
   const fontfamilies = require('./font-families.js')(declarations)
   const colors = require('./colors.js')(declarations)
   const browserhacks = require('./browserhacks.js')(declarations)
+  const boxshadows = require('./box-shadows.js')(declarations)
 
   return {
     total: all.length,
@@ -14,6 +14,7 @@ module.exports = declarations => {
     fontsizes,
     fontfamilies,
     colors,
-    browserhacks
+    browserhacks,
+    boxshadows
   }
 }


Test patch:
diff --git a/test/analyzer/index.js b/test/analyzer/index.js
index 33e42cd..ee5376c 100644
--- a/test/analyzer/index.js
+++ b/test/analyzer/index.js
@@ -90,6 +90,9 @@ test('Returns the correct analysis object structure', async t => {
     'stylesheets.size': 5,
     'stylesheets.browserhacks.total': 0,
     'stylesheets.browserhacks.totalUnique': 0,
+    'values.boxshadows.total': 0,
+    'values.boxshadows.unique': [],
+    'values.boxshadows.totalUnique': 0,
     'values.browserhacks.total': 0,
     'values.browserhacks.unique': [],
     'values.browserhacks.totalUnique': 0,
diff --git a/test/analyzer/values/box-shadows.js b/test/analyzer/values/box-shadows.js
new file mode 100644
index 0000000..58e8ead
--- /dev/null
+++ b/test/analyzer/values/box-shadows.js
@@ -0,0 +1,82 @@
+const test = require('ava')
+const analyze = require('../../../src/analyzer/values/box-shadows.js')
+
+// Source: https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_boxes/Advanced_box_effects
+const SIMPLE_BOX_SHADOW = '1px 1px 1px black'
+const MULTIPLE_BOX_SHADOWS =
+  '1px 1px 1px black,inset 2px 3px 5px rgba(0,0,0,0.3),inset -2px -3px 5px rgba(255,255,255,0.5)'
+const INSET_BOX_SHADOW = 'inset -2px -3px 5px rgba(255,255,255,0.5)'
+
+test('It responds with the correct structure', t => {
+  const actual = analyze([])
+  const expected = {
+    total: 0,
+    unique: [],
+    totalUnique: 0
+  }
+
+  t.deepEqual(actual, expected)
+})
+
+test('It recognizes a simple/single box-shadow correctly', t => {
+  const actual = analyze([
+    {
+      property: 'box-shadow',
+      value: SIMPLE_BOX_SHADOW
+    }
+  ])
+  const expected = {
+    total: 1,
+    unique: [
+      {
+        value: SIMPLE_BOX_SHADOW,
+        count: 1
+      }
+    ],
+    totalUnique: 1
+  }
+
+  t.deepEqual(actual, expected)
+})
+
+test('It recognizes box-shadow that uses inset', t => {
+  const expected = {
+    total: 1,
+    totalUnique: 1,
+    unique: [
+      {
+        value: INSET_BOX_SHADOW,
+        count: 1
+      }
+    ]
+  }
+  const actual = analyze([
+    {
+      property: 'box-shadow',
+      value: INSET_BOX_SHADOW
+    }
+  ])
+
+  t.deepEqual(actual, expected)
+})
+
+test('It recognizes an advanced box-shadow with multiple shadows', t => {
+  const expected = {
+    total: 1,
+    unique: [
+      {
+        value: MULTIPLE_BOX_SHADOWS,
+        count: 1
+      }
+    ],
+    totalUnique: 1
+  }
+  const actual = analyze([
+    {
+      property: 'box-shadow',
+      value: MULTIPLE_BOX_SHADOWS
+    }
+  ])
+
+  t.deepEqual(actual, expected)
+})
diff --git a/test/analyzer/values/output.json b/test/analyzer/values/output.json
index d858723..2df88f4 100644
--- a/test/analyzer/values/output.json
+++ b/test/analyzer/values/output.json
@@ -412,5 +412,10 @@
       }
     ],
     "totalUnique": 1
+  },
+  "boxshadows": {
+    "total": 0,
+    "unique": [],
+    "totalUnique": 0
   }
 }