Skip to content

Commit c741ed1

Browse files
committed
reduceCssCalc => reduceCSSCalc
poke @bloodyowl
1 parent 94fd9d9 commit c741ed1

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,36 @@ npm install reduce-css-calc
1313
## Usage
1414

1515
```javascript
16-
var reduceCssCalc = require('reduce-css-calc')
16+
var reduceCSSCalc = require('reduce-css-calc')
1717

18-
reduceCssCalc("calc(1 + 1)")
18+
reduceCSSCalc("calc(1 + 1)")
1919
// 2
2020

21-
reduceCssCalc("calc((6 / 2) - (4 * 2) + 1)")
21+
reduceCSSCalc("calc((6 / 2) - (4 * 2) + 1)")
2222
// -4
2323

24-
reduceCssCalc("calc(3rem * 2 - 1rem)")
24+
reduceCSSCalc("calc(3rem * 2 - 1rem)")
2525
// 5rem
2626

27-
reduceCssCalc("calc(2 * 50%)")
27+
reduceCSSCalc("calc(2 * 50%)")
2828
// 100%
2929

30-
reduceCssCalc("calc(120% * 50%)")
30+
reduceCSSCalc("calc(120% * 50%)")
3131
// 60%
3232

33-
reduceCssCalc("a calc(1 + 1) b calc(1 - 1) c")
33+
reduceCSSCalc("a calc(1 + 1) b calc(1 - 1) c")
3434
// a 2 b 0 c
3535

36-
reduceCssCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)")
36+
reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)")
3737
// 0.125rem
3838

39-
reduceCssCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)")
39+
reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)")
4040
// calc(1.125rem - 1px)
4141

42-
reduceCssCalc("-moz-calc(100px / 2)")
42+
reduceCSSCalc("-moz-calc(100px / 2)")
4343
// 50px
4444

45-
reduceCssCalc("-moz-calc(50% - 2em)")
45+
reduceCSSCalc("-moz-calc(50% - 2em)")
4646
// -moz-calc(50% - 2em)
4747
```
4848

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ var balanced = require("balanced-match")
55
var reduceFunctionCall = require("reduce-function-call")
66

77
/**
8-
* Expose reduceCssCalc plugin
8+
* Expose reduceCSSCalc plugin
99
*
1010
* @type {Function}
1111
*/
12-
module.exports = reduceCssCalc
12+
module.exports = reduceCSSCalc
1313

1414
/**
1515
* Reduce CSS calc() in a string, whenever it's possible
1616
*
1717
* @param {String} value css input
1818
*/
19-
function reduceCssCalc(value) {
19+
function reduceCSSCalc(value) {
2020
return reduceFunctionCall(value, /((?:\-[a-z]+\-)?calc)\(/, evaluateExpression)
2121
}
2222

test/index.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
11
var test = require("tape")
2-
var reduceCssCalc = require("..")
2+
var reduceCSSCalc = require("..")
33

44
test("throws an syntax error if a parenthese is missing", function(t) {
5-
t.throws(function() { reduceCssCalc("calc(")}, SyntaxError)
6-
t.throws(function() { reduceCssCalc("calc((2 + 1)")}, SyntaxError)
7-
t.throws(function() { reduceCssCalc("a calc(calc(2 + 1) b()")}, SyntaxError)
5+
t.throws(function() { reduceCSSCalc("calc(")}, SyntaxError)
6+
t.throws(function() { reduceCSSCalc("calc((2 + 1)")}, SyntaxError)
7+
t.throws(function() { reduceCSSCalc("a calc(calc(2 + 1) b()")}, SyntaxError)
88
t.end()
99
})
1010

1111
test("throws an error if a calc() is empty", function(t) {
12-
t.throws(function() { reduceCssCalc("calc()")}, Error)
13-
t.throws(function() { reduceCssCalc("calc(2 + ())")}, SyntaxError)
14-
t.throws(function() { reduceCssCalc("calc(2 + calc())")}, SyntaxError)
12+
t.throws(function() { reduceCSSCalc("calc()")}, Error)
13+
t.throws(function() { reduceCSSCalc("calc(2 + ())")}, SyntaxError)
14+
t.throws(function() { reduceCSSCalc("calc(2 + calc())")}, SyntaxError)
1515
t.end()
1616
})
1717

1818
test("complete reduce for simple css calc()", function(t) {
19-
t.equal(reduceCssCalc("calc(1 + 1)"), "2", "addition")
20-
t.equal(reduceCssCalc("calc(1 - 1)"), "0", "substraction")
21-
t.equal(reduceCssCalc("calc(2 * 2)"), "4", "multiplication")
22-
t.equal(reduceCssCalc("calc(8 / 2)"), "4", "division")
23-
t.equal(reduceCssCalc("calc((6 / 2) - (4 * 2) + 1)"), "-4", "embed operations")
19+
t.equal(reduceCSSCalc("calc(1 + 1)"), "2", "addition")
20+
t.equal(reduceCSSCalc("calc(1 - 1)"), "0", "substraction")
21+
t.equal(reduceCSSCalc("calc(2 * 2)"), "4", "multiplication")
22+
t.equal(reduceCSSCalc("calc(8 / 2)"), "4", "division")
23+
t.equal(reduceCSSCalc("calc((6 / 2) - (4 * 2) + 1)"), "-4", "embed operations")
2424
t.end()
2525
})
2626

2727
test("complete reduce for css calc() with a single unit", function(t) {
28-
t.equal(reduceCssCalc("calc(3px * 2 - 1px)"), "5px", "px")
29-
t.equal(reduceCssCalc("calc(3rem * 2 - 1rem)"), "5rem", "rem")
30-
t.equal(reduceCssCalc("calc(3em * 2 - 1em)"), "5em", "em")
31-
t.equal(reduceCssCalc("calc(3pt * 2 - 1pt)"), "5pt", "pt")
32-
t.equal(reduceCssCalc("calc(3vh * 2 - 1vh)"), "5vh", "vh")
28+
t.equal(reduceCSSCalc("calc(3px * 2 - 1px)"), "5px", "px")
29+
t.equal(reduceCSSCalc("calc(3rem * 2 - 1rem)"), "5rem", "rem")
30+
t.equal(reduceCSSCalc("calc(3em * 2 - 1em)"), "5em", "em")
31+
t.equal(reduceCSSCalc("calc(3pt * 2 - 1pt)"), "5pt", "pt")
32+
t.equal(reduceCSSCalc("calc(3vh * 2 - 1vh)"), "5vh", "vh")
3333
t.end()
3434
})
3535

3636
test("complete & accurate reduce for css calc() with percentages", function(t) {
37-
t.equal(reduceCssCalc("calc(2 * 50%)"), "100%", "integer * percentage")
38-
t.equal(reduceCssCalc("calc(120% * 50%)"), "60%", "percentage * percentage")
37+
t.equal(reduceCSSCalc("calc(2 * 50%)"), "100%", "integer * percentage")
38+
t.equal(reduceCSSCalc("calc(120% * 50%)"), "60%", "percentage * percentage")
3939
t.end()
4040
})
4141

4242
test("ignore value around css calc() functions ", function(t) {
43-
t.equal(reduceCssCalc("calc(1 + 1) a"), "2 a", "value after")
44-
t.equal(reduceCssCalc("a calc(1 + 1)"), "a 2", "value before")
45-
t.equal(reduceCssCalc("calc(1 + 1) a calc(1 - 1)"), "2 a 0", "value between 2 calc()")
46-
t.equal(reduceCssCalc("a calc(1 + 1) b calc(1 - 1)"), "a 2 b 0", "value before & between 2 calc()")
47-
t.equal(reduceCssCalc("a calc(1 + 1) b calc(1 - 1) c"), "a 2 b 0 c", "value before, between & after 2 calc()")
43+
t.equal(reduceCSSCalc("calc(1 + 1) a"), "2 a", "value after")
44+
t.equal(reduceCSSCalc("a calc(1 + 1)"), "a 2", "value before")
45+
t.equal(reduceCSSCalc("calc(1 + 1) a calc(1 - 1)"), "2 a 0", "value between 2 calc()")
46+
t.equal(reduceCSSCalc("a calc(1 + 1) b calc(1 - 1)"), "a 2 b 0", "value before & between 2 calc()")
47+
t.equal(reduceCSSCalc("a calc(1 + 1) b calc(1 - 1) c"), "a 2 b 0 c", "value before, between & after 2 calc()")
4848
t.end()
4949
})
5050

5151
test("reduce complexe css calc()", function(t) {
52-
t.equal(reduceCssCalc("calc(calc(100 + 10) + 1)"), "111", "integer")
53-
t.equal(reduceCssCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)"), "0.125rem", "with a single unit")
54-
t.equal(reduceCssCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)"), "calc(1.125rem - 1px)", "multiple units with explicit calc")
55-
t.equal(reduceCssCalc("calc(((1rem * 0.75) * 1.5) - 1px)"), "calc(1.125rem - 1px)", "multiple units with implicit calc")
56-
t.equal(reduceCssCalc("calc(-1px + (1.5 * (1rem * 0.75)))"), "calc(-1px + 1.125rem)", "multiple units with implicit calc, reverse order")
57-
t.equal(reduceCssCalc("calc(2rem * (2 * (2 + 3)) + 4 + (5/2))"), "26.5rem", "complex math formula works correctly")
52+
t.equal(reduceCSSCalc("calc(calc(100 + 10) + 1)"), "111", "integer")
53+
t.equal(reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)"), "0.125rem", "with a single unit")
54+
t.equal(reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)"), "calc(1.125rem - 1px)", "multiple units with explicit calc")
55+
t.equal(reduceCSSCalc("calc(((1rem * 0.75) * 1.5) - 1px)"), "calc(1.125rem - 1px)", "multiple units with implicit calc")
56+
t.equal(reduceCSSCalc("calc(-1px + (1.5 * (1rem * 0.75)))"), "calc(-1px + 1.125rem)", "multiple units with implicit calc, reverse order")
57+
t.equal(reduceCSSCalc("calc(2rem * (2 * (2 + 3)) + 4 + (5/2))"), "26.5rem", "complex math formula works correctly")
5858

59-
t.equal(reduceCssCalc("calc((4 * 2) + 4.2 + 1 + (2rem * .4) + (2px * .4))"), "calc(8 + 4.2 + 1 + 0.8rem + 0.8px)", "handle long formula")
59+
t.equal(reduceCSSCalc("calc((4 * 2) + 4.2 + 1 + (2rem * .4) + (2px * .4))"), "calc(8 + 4.2 + 1 + 0.8rem + 0.8px)", "handle long formula")
6060
t.end()
6161
})
6262

6363
test("reduce prefixed css calc()", function(t) {
64-
t.equal(reduceCssCalc("-webkit-calc(120% * 50%)"), "60%", "-webkit, complete reduce")
65-
t.equal(reduceCssCalc("-webkit-calc(100% - 2em)"), "-webkit-calc(100% - 2em)", "-webkit, multiple unit")
64+
t.equal(reduceCSSCalc("-webkit-calc(120% * 50%)"), "60%", "-webkit, complete reduce")
65+
t.equal(reduceCSSCalc("-webkit-calc(100% - 2em)"), "-webkit-calc(100% - 2em)", "-webkit, multiple unit")
6666

67-
t.equal(reduceCssCalc("-moz-calc(100px / 2)"), "50px", "-moz, complete reduce")
68-
t.equal(reduceCssCalc("-moz-calc(50% - 2em)"), "-moz-calc(50% - 2em)","-moz, multiple unit")
67+
t.equal(reduceCSSCalc("-moz-calc(100px / 2)"), "50px", "-moz, complete reduce")
68+
t.equal(reduceCSSCalc("-moz-calc(50% - 2em)"), "-moz-calc(50% - 2em)","-moz, multiple unit")
6969
t.end()
7070
})
7171

7272
test("ignore unrecognized values", function(t) {
73-
t.equal(reduceCssCalc("calc((4px * 2) + 4.2 + a1 + (2rem * .4))"), "calc(8px + 4.2 + a1 + 0.8rem)", "ignore when eval fail")
73+
t.equal(reduceCSSCalc("calc((4px * 2) + 4.2 + a1 + (2rem * .4))"), "calc(8px + 4.2 + a1 + 0.8rem)", "ignore when eval fail")
7474
t.end()
7575
})

0 commit comments

Comments
 (0)