style-to-object 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,62 @@
1
- # Change Log
1
+ # Changelog
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [0.3.0](https://github.com/remarkablemark/style-to-object/compare/v0.2.3...v0.3.0) (2019-11-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **index:** update return type of main function (remove `any`) ([c6e8a54](https://github.com/remarkablemark/style-to-object/commit/c6e8a54))
11
+
12
+
13
+ ### Features
14
+
15
+ * add typescript support ([74a1b83](https://github.com/remarkablemark/style-to-object/commit/74a1b83))
16
+
17
+
18
+ ### Tests
19
+
20
+ * **index:** add test for TS declaration file ([b029a4b](https://github.com/remarkablemark/style-to-object/commit/b029a4b))
21
+
22
+
23
+
24
+ ### [0.2.3](https://github.com/remarkablemark/style-to-object/compare/v0.2.2...v0.2.3) (2019-06-22)
25
+
26
+
27
+ ### Build System
28
+
29
+ * **package:** add field "files" and remove `.npmignore` ([fdf3966](https://github.com/remarkablemark/style-to-object/commit/fdf3966))
30
+ * **package:** update script `build:min` to generate sourcemap ([a13be58](https://github.com/remarkablemark/style-to-object/commit/a13be58))
31
+ * **package:** upgrade devDependencies ([377bb40](https://github.com/remarkablemark/style-to-object/commit/377bb40))
32
+ * **rollup:** remove `uglify-es` from config as it's unneeded ([b0951e0](https://github.com/remarkablemark/style-to-object/commit/b0951e0))
33
+
34
+
35
+ ### Tests
36
+
37
+ * organize and rename describe blocks ([8d4c004](https://github.com/remarkablemark/style-to-object/commit/8d4c004))
38
+ * organize data (test suites) into cases, errors, and invalids ([513732b](https://github.com/remarkablemark/style-to-object/commit/513732b))
39
+ * rename `test/cases.js` to `test/data.js` ([75d084d](https://github.com/remarkablemark/style-to-object/commit/75d084d))
40
+ * **data:** add more test cases and errors ([c9242c7](https://github.com/remarkablemark/style-to-object/commit/c9242c7))
41
+ * **data:** refactor test data from object to array format ([1a07a38](https://github.com/remarkablemark/style-to-object/commit/1a07a38))
42
+
43
+
44
+
45
+ <a name="0.2.2"></a>
46
+ ## [0.2.2](https://github.com/remarkablemark/style-to-object/compare/v0.2.1...v0.2.2) (2018-09-13)
47
+
48
+
49
+
50
+ <a name="0.2.1"></a>
51
+ ## [0.2.1](https://github.com/remarkablemark/style-to-object/compare/v0.2.0...v0.2.1) (2018-05-09)
52
+
53
+
54
+ ### Bug Fixes
55
+
56
+ * **package:** upgrade css@2.2.3 which resolves security vulnerability ([d8b94c0](https://github.com/remarkablemark/style-to-object/commit/d8b94c0))
57
+
58
+
59
+
5
60
  <a name="0.2.0"></a>
6
61
  # [0.2.0](https://github.com/remarkablemark/style-to-object/compare/v0.1.0...v0.2.0) (2017-11-26)
7
62
 
package/README.md CHANGED
@@ -6,29 +6,35 @@
6
6
  [![Build Status](https://travis-ci.org/remarkablemark/style-to-object.svg?branch=master)](https://travis-ci.org/remarkablemark/style-to-object)
7
7
  [![Coverage Status](https://coveralls.io/repos/github/remarkablemark/style-to-object/badge.svg?branch=master)](https://coveralls.io/github/remarkablemark/style-to-object?branch=master)
8
8
  [![Dependency status](https://david-dm.org/remarkablemark/style-to-object.svg)](https://david-dm.org/remarkablemark/style-to-object)
9
+ [![NPM downloads](https://img.shields.io/npm/dm/style-to-object.svg?style=flat-square)](https://www.npmjs.com/package/style-to-object)
9
10
 
10
11
  Parses inline style to object:
11
12
 
12
13
  ```js
13
- var parser = require('style-to-object');
14
- parser('color: #C0FFEE; background: #BADA55;');
15
- // { color: "#C0FFEE", background: "#BADA55" }
14
+ var parse = require('style-to-object');
15
+ parse('color: #C0FFEE; background: #BADA55;');
16
16
  ```
17
17
 
18
- [JSFiddle](https://jsfiddle.net/remarkablemark/ykz2meot/)
18
+ Output:
19
+
20
+ ```js
21
+ { color: '#C0FFEE', background: '#BADA55' }
22
+ ```
23
+
24
+ [JSFiddle](https://jsfiddle.net/remarkablemark/ykz2meot/) | [Repl.it](https://repl.it/@remarkablemark/style-to-object) | [Examples](https://github.com/remarkablemark/style-to-object/tree/master/examples)
19
25
 
20
26
  ## Installation
21
27
 
22
28
  [NPM](https://www.npmjs.com/package/style-to-object):
23
29
 
24
30
  ```sh
25
- npm install style-to-object --save
31
+ $ npm install style-to-object --save
26
32
  ```
27
33
 
28
34
  [Yarn](https://yarn.fyi/style-to-object):
29
35
 
30
36
  ```sh
31
- yarn add style-to-object
37
+ $ yarn add style-to-object
32
38
  ```
33
39
 
34
40
  [CDN](https://unpkg.com/style-to-object/):
@@ -36,7 +42,7 @@ yarn add style-to-object
36
42
  ```html
37
43
  <script src="https://unpkg.com/style-to-object@latest/dist/style-to-object.min.js"></script>
38
44
  <script>
39
- var parser = window.StyleToObject;
45
+ window.StyleToObject(/* string */);
40
46
  </script>
41
47
  ```
42
48
 
@@ -46,50 +52,70 @@ Import the module:
46
52
 
47
53
  ```js
48
54
  // CommonJS
49
- const parser = require('style-to-object');
55
+ const parse = require('style-to-object');
50
56
 
51
57
  // ES Modules
52
- import parser from 'style-to-object';
58
+ import parse from 'style-to-object';
53
59
  ```
54
60
 
55
61
  Parse single declaration:
56
62
 
57
63
  ```js
58
- parse(`
59
- color: #f00
60
- `);
61
- // { color: '#f00' }
64
+ parse('line-height: 42');
65
+ ```
66
+
67
+ Output:
68
+
69
+ ```js
70
+ { 'line-height': '42' }
62
71
  ```
63
72
 
64
73
  Parse multiple declarations:
65
74
 
66
75
  ```js
67
76
  parse(`
68
- color: #f00;
69
- z-index: 42;
77
+ border-color: #ACE;
78
+ z-index: 1337;
70
79
  `);
71
- // { color: '#f00', 'z-index': '42' }
80
+ ```
81
+
82
+ Output:
83
+
84
+ ```js
85
+ { 'border-color': '#ACE', 'z-index': '1337' }
72
86
  ```
73
87
 
74
88
  Parse unknown declarations:
75
89
 
76
90
  ```js
77
- parse(`
78
- foo: bar;
79
- `);
80
- // { foo: 'bar' }
91
+ parse('answer: 42;');
92
+ ```
93
+
94
+ Output:
95
+
96
+ ```js
97
+ { 'answer': '42' }
81
98
  ```
82
99
 
83
- Invalid declarations:
100
+ Invalid declarations/arguments:
84
101
 
85
102
  ```js
86
- parse(1); // null
87
- parse('top:'); // null
88
103
  parse(`
89
104
  top: ;
90
105
  right: 1em;
91
106
  `); // { right: '1em' }
107
+
108
+ parse(); // null
109
+ parse(null); // null
110
+ parse(1); // null
111
+ parse(true); // null
112
+ parse('top:'); // null
113
+ parse(':12px'); // null
114
+ parse(':'); // null
115
+ parse(';'); // null
116
+
92
117
  parse('top'); // throws Error
118
+ parse('/*'); // throws Error
93
119
  ```
94
120
 
95
121
  ### Iterator
@@ -97,13 +123,13 @@ parse('top'); // throws Error
97
123
  If the 2nd argument is a function, then the parser will return `null`:
98
124
 
99
125
  ```js
100
- parser('color: #f00', function() {}); // null
126
+ parse('color: #f00', function() {}); // null
101
127
  ```
102
128
 
103
129
  But the function will iterate through each declaration:
104
130
 
105
131
  ```js
106
- parser('color: #f00', function(name, value, declaration) {
132
+ parse('color: #f00', function(name, value, declaration) {
107
133
  console.log(name); // 'color'
108
134
  console.log(value); // '#f00'
109
135
  console.log(declaration); // { type: 'declaration', property: 'color', value: '#f00' }
@@ -114,35 +140,73 @@ This makes it easy to customize the output:
114
140
 
115
141
  ```js
116
142
  const style = `
117
- color: #f00;
118
- background: #ba4;
143
+ color: red;
144
+ background: blue;
119
145
  `;
120
146
  const output = [];
121
- const iterator = (name, value) => {
147
+
148
+ function iterator(name, value) {
122
149
  output.push([name, value]);
123
- };
124
- parser(style, iterator);
125
- console.log(output); // [['color', '#f00'], ['background', '#ba4']]
150
+ }
151
+
152
+ parse(style, iterator);
153
+ console.log(output); // [['color', 'red'], ['background', 'blue']]
126
154
  ```
127
155
 
128
156
  ## Testing
129
157
 
158
+ Run tests:
159
+
130
160
  ```sh
131
161
  $ npm test
162
+ ```
163
+
164
+ Run tests in watch mode:
165
+
166
+ ```sh
167
+ $ npm run test:watch
168
+ ```
169
+
170
+ Run tests with coverage:
171
+
172
+ ```sh
173
+ $ npm run test:coverage
174
+
175
+ # generate html report
176
+ $ npm run test:coverage:report
177
+ ```
178
+
179
+ Lint files:
180
+
181
+ ```sh
132
182
  $ npm run lint
133
183
  ```
134
184
 
185
+ Fix lint errors:
186
+
187
+ ```sh
188
+ $ npm run lint:fix
189
+ ```
190
+
191
+ Test TypeScript declaration file for style and correctness:
192
+
193
+ ```sh
194
+ $ npm run lint:dts
195
+ ```
196
+
135
197
  ## Release
136
198
 
199
+ Only collaborators with credentials can release and publish:
200
+
137
201
  ```sh
138
202
  $ npm run release
139
- $ npm publish
140
- $ git push --follow-tags
203
+ $ git push --follow-tags && npm publish
141
204
  ```
142
205
 
143
206
  ## Special Thanks
144
207
 
145
- - [css](https://github.com/reworkcss/css)
208
+ - [inline-style-parser](https://github.com/remarkablemark/inline-style-parser)
209
+ - [Contributors](https://github.com/remarkablemark/style-to-object/graphs/contributors)
146
210
 
147
211
  ## License
148
212