Skip to content

Commit ecb9818

Browse files
committed
Initial commit based on rework-calc v1.1.0
0 parents  commit ecb9818

11 files changed

+509
-0
lines changed

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
indent_style = space
10+
indent_size = 2
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[Makefile]
16+
indent_style = tab

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.jscsrc

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"excludeFiles": [
3+
"node_modules/**"
4+
],
5+
"fileExtensions": [
6+
".js"
7+
],
8+
"requireCurlyBraces": [
9+
"if",
10+
"else",
11+
"for",
12+
"while",
13+
"do",
14+
"try",
15+
"catch"
16+
],
17+
"requireSpaceAfterKeywords": [
18+
"if",
19+
"else",
20+
"for",
21+
"while",
22+
"do",
23+
"switch",
24+
"return",
25+
"try",
26+
"catch"
27+
],
28+
"requireSpaceBeforeBlockStatements": true,
29+
"requireParenthesesAroundIIFE": true,
30+
"requireSpacesInConditionalExpression": {
31+
"afterTest": true,
32+
"beforeConsequent": true,
33+
"afterConsequent": true,
34+
"beforeAlternate": true
35+
},
36+
"requireSpacesInFunctionExpression": {
37+
"beforeOpeningCurlyBrace": true
38+
},
39+
"disallowSpacesInFunctionExpression": {
40+
"beforeOpeningRoundBrace": true
41+
},
42+
"disallowMultipleVarDecl": true,
43+
"requireBlocksOnNewline": 1,
44+
"disallowPaddingNewlinesInBlocks": true,
45+
"disallowEmptyBlocks": true,
46+
"disallowSpacesInsideObjectBrackets": true,
47+
"disallowSpacesInsideArrayBrackets": true,
48+
"disallowSpacesInsideParentheses": true,
49+
"disallowQuotedKeysInObjects": "allButReserved",
50+
"disallowSpaceAfterObjectKeys": true,
51+
"requireCommaBeforeLineBreak": true,
52+
"requireOperatorBeforeLineBreak": [
53+
"?",
54+
"+",
55+
"-",
56+
"/",
57+
"*",
58+
"=",
59+
"==",
60+
"===",
61+
"!=",
62+
"!==",
63+
">",
64+
">=",
65+
"<",
66+
"<="
67+
],
68+
"disallowSpaceAfterPrefixUnaryOperators": [
69+
"++",
70+
"--",
71+
"+",
72+
"-",
73+
"~",
74+
"!"
75+
],
76+
"disallowSpaceBeforePostfixUnaryOperators": [
77+
"++",
78+
"--"
79+
],
80+
"requireSpaceBeforeBinaryOperators": [
81+
"+",
82+
"-",
83+
"/",
84+
"*",
85+
"=",
86+
"==",
87+
"===",
88+
"!=",
89+
"!=="
90+
],
91+
"requireSpaceAfterBinaryOperators": [
92+
"+",
93+
"-",
94+
"/",
95+
"*",
96+
"=",
97+
"==",
98+
"===",
99+
"!=",
100+
"!=="
101+
],
102+
"disallowImplicitTypeConversion": [
103+
"numeric",
104+
"boolean",
105+
"binary",
106+
"string"
107+
],
108+
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
109+
"disallowKeywords": [
110+
"with"
111+
],
112+
"disallowMultipleLineStrings": true,
113+
"validateQuoteMarks": "\"",
114+
"validateIndentation": 2,
115+
"disallowMixedSpacesAndTabs": true,
116+
"disallowTrailingWhitespace": true,
117+
"requireKeywordsOnNewLine": [
118+
"else"
119+
],
120+
"requireLineFeedAtFileEnd": true,
121+
"requireCapitalizedConstructors": true,
122+
"safeContextKeyword": "that",
123+
"requireDotNotation": true,
124+
"validateJSDoc": {
125+
"checkParamNames": true,
126+
"checkRedundantParams": true,
127+
"requireParamTypes": true
128+
},
129+
"requireSpaceAfterLineComment": true
130+
}

.jshintrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"newcap": false,
3+
"undef": true,
4+
"unused": true,
5+
"asi": true,
6+
"esnext": true,
7+
"node": true,
8+
"browser": true,
9+
10+
"evil": true
11+
}

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: node_js

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 1.0.0 - 2014-08-04
2+
3+
First release
4+
5+
- based on [rework-calc](https://github.com/reworkcss/rework-calc) v1.1.0
6+
- add error if the calc() embed an empty calc() or empty ()
7+
- jscs + jshint added before tests

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 "MoOx" Maxime Thirouin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# reduce-css-calc [![Build Status](https://travis-ci.org/MoOx/reduce-css-calc.png)](https://travis-ci.org/MoOx/reduce-css-calc)
2+
3+
Reduce CSS calc() function at the maximum.
4+
5+
Particularly useful for packages like [rework-calc](https://github.com/reworkcss/rework-calc) or [postcss-calc](https://github.com/postcss/postcss-calc).
6+
7+
## Installation
8+
9+
```bash
10+
npm install reduce-css-calc
11+
```
12+
13+
## Usage
14+
15+
```javascript
16+
var reduceCssCalc = require('reduce-css-calc')
17+
18+
reduceCssCalc("calc(1 + 1)")
19+
// 2
20+
21+
reduceCssCalc("calc((6 / 2) - (4 * 2) + 1)")
22+
// -4
23+
24+
reduceCssCalc("calc(3rem * 2 - 1rem)")
25+
// 5rem
26+
27+
reduceCssCalc("calc(2 * 50%)")
28+
// 100%
29+
30+
reduceCssCalc("calc(120% * 50%)")
31+
// 60%
32+
33+
reduceCssCalc("a calc(1 + 1) b calc(1 - 1) c")
34+
// a 2 b 0 c
35+
36+
reduceCssCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)")
37+
// 0.125rem
38+
39+
reduceCssCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)")
40+
// calc(1.125rem - 1px)
41+
42+
reduceCssCalc("-moz-calc(100px / 2)")
43+
// 50px
44+
45+
reduceCssCalc("-moz-calc(50% - 2em)")
46+
// -moz-calc(50% - 2em)
47+
```
48+
49+
See [unit tests](test/index.js) for others examples.
50+
51+
## Contributing
52+
53+
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
54+
55+
```bash
56+
git clone https://github.com/MoOx/reduce-css-calc.git
57+
git checkout -b patch-1
58+
npm install
59+
npm test
60+
```
61+
62+
## [Changelog](CHANGELOG.md)
63+
64+
## [License](LICENSE-MIT)

0 commit comments

Comments
 (0)