style-to-object 0.3.0 → 0.4.1

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/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  [![NPM](https://nodei.co/npm/style-to-object.png)](https://nodei.co/npm/style-to-object/)
4
4
 
5
5
  [![NPM version](https://img.shields.io/npm/v/style-to-object.svg)](https://www.npmjs.com/package/style-to-object)
6
- [![Build Status](https://travis-ci.org/remarkablemark/style-to-object.svg?branch=master)](https://travis-ci.org/remarkablemark/style-to-object)
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
- [![Dependency status](https://david-dm.org/remarkablemark/style-to-object.svg)](https://david-dm.org/remarkablemark/style-to-object)
6
+ [![build](https://github.com/remarkablemark/style-to-object/actions/workflows/build.yml/badge.svg)](https://github.com/remarkablemark/style-to-object/actions/workflows/build.yml)
7
+ [![codecov](https://codecov.io/gh/remarkablemark/style-to-object/branch/master/graph/badge.svg?token=XWxph9dpa4)](https://codecov.io/gh/remarkablemark/style-to-object)
9
8
  [![NPM downloads](https://img.shields.io/npm/dm/style-to-object.svg?style=flat-square)](https://www.npmjs.com/package/style-to-object)
10
9
 
11
10
  Parses inline style to object:
@@ -21,20 +20,20 @@ Output:
21
20
  { color: '#C0FFEE', background: '#BADA55' }
22
21
  ```
23
22
 
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)
23
+ [JSFiddle](https://jsfiddle.net/remarkablemark/ykz2meot/) | [Replit](https://replit.com/@remarkablemark/style-to-object) | [Examples](https://github.com/remarkablemark/style-to-object/tree/master/examples)
25
24
 
26
25
  ## Installation
27
26
 
28
27
  [NPM](https://www.npmjs.com/package/style-to-object):
29
28
 
30
29
  ```sh
31
- $ npm install style-to-object --save
30
+ npm install style-to-object --save
32
31
  ```
33
32
 
34
33
  [Yarn](https://yarn.fyi/style-to-object):
35
34
 
36
35
  ```sh
37
- $ yarn add style-to-object
36
+ yarn add style-to-object
38
37
  ```
39
38
 
40
39
  [CDN](https://unpkg.com/style-to-object/):
@@ -99,6 +98,8 @@ Output:
99
98
 
100
99
  Invalid declarations/arguments:
101
100
 
101
+ <!-- prettier-ignore-start -->
102
+
102
103
  ```js
103
104
  parse(`
104
105
  top: ;
@@ -118,6 +119,8 @@ parse('top'); // throws Error
118
119
  parse('/*'); // throws Error
119
120
  ```
120
121
 
122
+ <!-- prettier-ignore-end -->
123
+
121
124
  ### Iterator
122
125
 
123
126
  If the 2nd argument is a function, then the parser will return `null`:
@@ -128,6 +131,8 @@ parse('color: #f00', function() {}); // null
128
131
 
129
132
  But the function will iterate through each declaration:
130
133
 
134
+ <!-- prettier-ignore-start -->
135
+
131
136
  ```js
132
137
  parse('color: #f00', function(name, value, declaration) {
133
138
  console.log(name); // 'color'
@@ -136,6 +141,8 @@ parse('color: #f00', function(name, value, declaration) {
136
141
  });
137
142
  ```
138
143
 
144
+ <!-- prettier-ignore-end -->
145
+
139
146
  This makes it easy to customize the output:
140
147
 
141
148
  ```js
@@ -158,50 +165,42 @@ console.log(output); // [['color', 'red'], ['background', 'blue']]
158
165
  Run tests:
159
166
 
160
167
  ```sh
161
- $ npm test
168
+ npm test
162
169
  ```
163
170
 
164
171
  Run tests in watch mode:
165
172
 
166
173
  ```sh
167
- $ npm run test:watch
174
+ npm run test:watch
168
175
  ```
169
176
 
170
177
  Run tests with coverage:
171
178
 
172
179
  ```sh
173
- $ npm run test:coverage
174
-
175
- # generate html report
176
- $ npm run test:coverage:report
180
+ npm run test:coverage
177
181
  ```
178
182
 
179
183
  Lint files:
180
184
 
181
185
  ```sh
182
- $ npm run lint
186
+ npm run lint
183
187
  ```
184
188
 
185
189
  Fix lint errors:
186
190
 
187
191
  ```sh
188
- $ npm run lint:fix
192
+ npm run lint:fix
189
193
  ```
190
194
 
191
195
  Test TypeScript declaration file for style and correctness:
192
196
 
193
197
  ```sh
194
- $ npm run lint:dts
198
+ npm run lint:dts
195
199
  ```
196
200
 
197
201
  ## Release
198
202
 
199
- Only collaborators with credentials can release and publish:
200
-
201
- ```sh
202
- $ npm run release
203
- $ git push --follow-tags && npm publish
204
- ```
203
+ Release and publish are automated by [Release Please](https://github.com/googleapis/release-please).
205
204
 
206
205
  ## Special Thanks
207
206
 
@@ -1,8 +1,14 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
- (global = global || self, global.StyleToObject = factory());
5
- }(this, (function () { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.StyleToObject = factory());
5
+ })(this, (function () { 'use strict';
6
+
7
+ exports["default"] = {};
8
+ var styleToObject = {
9
+ get exports(){ return exports["default"]; },
10
+ set exports(v){ exports["default"] = v; },
11
+ };
6
12
 
7
13
  // http://www.w3.org/TR/CSS21/grammar.html
8
14
  // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
@@ -262,6 +268,8 @@
262
268
  return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
263
269
  }
264
270
 
271
+ var parse = inlineStyleParser;
272
+
265
273
  /**
266
274
  * Parses inline style to object.
267
275
  *
@@ -280,7 +288,7 @@
280
288
  }
281
289
 
282
290
  var declaration;
283
- var declarations = inlineStyleParser(style);
291
+ var declarations = parse(style);
284
292
  var hasIterator = typeof iterator === 'function';
285
293
  var property;
286
294
  var value;
@@ -301,8 +309,9 @@
301
309
  return output;
302
310
  }
303
311
 
304
- var styleToObject = StyleToObject;
312
+ styleToObject.exports = StyleToObject;
313
+ exports["default"].default = StyleToObject; // ESM support
305
314
 
306
- return styleToObject;
315
+ return exports["default"];
307
316
 
308
- })));
317
+ }));
@@ -1,2 +1,2 @@
1
- !function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(n=n||self).StyleToObject=r()}(this,function(){"use strict";function s(e,t){if("string"!=typeof e)throw new TypeError("First argument must be a string");if(!e)return[];t=t||{};var o=1,i=1;function u(n){var r=n.match(g);r&&(o+=r.length);var t=n.lastIndexOf("\n");i=~t?n.length-t:i+n.length}function c(){var r={line:o,column:i};return function(n){return n.position=new f(r),l(),n}}function f(n){this.start=n,this.end={line:o,column:i},this.source=t.source}function a(n){var r=new Error(t.source+":"+o+":"+i+": "+n);if(r.reason=n,r.filename=t.source,r.line=o,r.column=i,r.source=e,!t.silent)throw r}function s(n){var r=n.exec(e);if(r){var t=r[0];return u(t),e=e.slice(t.length),r}}function l(){s(n)}function p(n){var r;for(n=n||[];r=h();)!1!==r&&n.push(r);return n}function h(){var n=c();if("/"==e.charAt(0)&&"*"==e.charAt(1)){for(var r=2;x!=e.charAt(r)&&("*"!=e.charAt(r)||"/"!=e.charAt(r+1));)++r;if(r+=2,x===e.charAt(r-1))return a("End of comment missing");var t=e.slice(2,r-2);return i+=2,u(t),e=e.slice(r),i+=2,n({type:"comment",comment:t})}}function v(){var n=c(),r=s(y);if(r){if(h(),!s(d))return a("property missing ':'");var t=s(w),e=n({type:"declaration",property:b(r[0].replace(m,x)),value:t?b(t[0].replace(m,x)):x});return s(A),e}}return f.prototype.content=e,l(),function(){var n,r=[];for(p(r);n=v();)!1!==n&&(r.push(n),p(r));return r}()}var m=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,g=/\n/g,n=/^\s*/,y=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,d=/^:\s*/,w=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,A=/^[;\s]*/,r=/^\s+|\s+$/g,x="";function b(n){return n?n.replace(r,x):x}return function(n,r){var t,e=null;if(!n||"string"!=typeof n)return e;for(var o,i,u=s(n),c="function"==typeof r,f=0,a=u.length;f<a;f++)o=(t=u[f]).property,i=t.value,c?r(o,i,t):i&&((e=e||{})[o]=i);return e}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).StyleToObject=t()}(this,(function(){"use strict";exports.default={};var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,r=/^\s*/,n=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,u=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,i=/^[;\s]*/,f=/^\s+|\s+$/g,s="";function a(e){return e?e.replace(f,s):s}var c=function(f,c){if("string"!=typeof f)throw new TypeError("First argument must be a string");if(!f)return[];c=c||{};var l=1,p=1;function h(e){var r=e.match(t);r&&(l+=r.length);var n=e.lastIndexOf("\n");p=~n?e.length-n:p+e.length}function d(){var e={line:l,column:p};return function(t){return t.position=new v(e),y(),t}}function v(e){this.start=e,this.end={line:l,column:p},this.source=c.source}function m(e){var t=new Error(c.source+":"+l+":"+p+": "+e);if(t.reason=e,t.filename=c.source,t.line=l,t.column=p,t.source=f,!c.silent)throw t}function g(e){var t=e.exec(f);if(t){var r=t[0];return h(r),f=f.slice(r.length),t}}function y(){g(r)}function x(e){var t;for(e=e||[];t=w();)!1!==t&&e.push(t);return e}function w(){var e=d();if("/"==f.charAt(0)&&"*"==f.charAt(1)){for(var t=2;s!=f.charAt(t)&&("*"!=f.charAt(t)||"/"!=f.charAt(t+1));)++t;if(t+=2,s===f.charAt(t-1))return m("End of comment missing");var r=f.slice(2,t-2);return p+=2,h(r),f=f.slice(t),p+=2,e({type:"comment",comment:r})}}function A(){var t=d(),r=g(n);if(r){if(w(),!g(o))return m("property missing ':'");var f=g(u),c=t({type:"declaration",property:a(r[0].replace(e,s)),value:f?a(f[0].replace(e,s)):s});return g(i),c}}return v.prototype.content=f,y(),function(){var e,t=[];for(x(t);e=A();)!1!==e&&(t.push(e),x(t));return t}()};function l(e,t){var r,n=null;if(!e||"string"!=typeof e)return n;for(var o,u,i=c(e),f="function"==typeof t,s=0,a=i.length;s<a;s++)o=(r=i[s]).property,u=r.value,f?t(o,u,r):u&&(n||(n={}),n[o]=u);return n}return{get exports(){return exports.default},set exports(e){exports.default=e}}.exports=l,exports.default.default=l,exports.default}));
2
2
  //# sourceMappingURL=style-to-object.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style-to-object.min.js","sources":["../node_modules/inline-style-parser/index.js","../index.js"],"sourcesContent":["// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar COMMENT_REGEX = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g;\n\nvar NEWLINE_REGEX = /\\n/g;\nvar WHITESPACE_REGEX = /^\\s*/;\n\n// declaration\nvar PROPERTY_REGEX = /^(\\*?[-#/*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/;\nvar COLON_REGEX = /^:\\s*/;\nvar VALUE_REGEX = /^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^)]*?\\)|[^};])+)/;\nvar SEMICOLON_REGEX = /^[;\\s]*/;\n\n// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill\nvar TRIM_REGEX = /^\\s+|\\s+$/g;\n\n// strings\nvar NEWLINE = '\\n';\nvar FORWARD_SLASH = '/';\nvar ASTERISK = '*';\nvar EMPTY_STRING = '';\n\n// types\nvar TYPE_COMMENT = 'comment';\nvar TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nmodule.exports = function(style, options) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n if (!style) return [];\n\n options = options || {};\n\n /**\n * Positional.\n */\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n *\n * @param {String} str\n */\n function updatePosition(str) {\n var lines = str.match(NEWLINE_REGEX);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf(NEWLINE);\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n *\n * @return {Function}\n */\n function position() {\n var start = { line: lineno, column: column };\n return function(node) {\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node.\n *\n * @constructor\n * @property {Object} start\n * @property {Object} end\n * @property {undefined|String} source\n */\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string.\n */\n Position.prototype.content = style;\n\n var errorsList = [];\n\n /**\n * Error `msg`.\n *\n * @param {String} msg\n * @throws {Error}\n */\n function error(msg) {\n var err = new Error(\n options.source + ':' + lineno + ':' + column + ': ' + msg\n );\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = style;\n\n if (options.silent) {\n errorsList.push(err);\n } else {\n throw err;\n }\n }\n\n /**\n * Match `re` and return captures.\n *\n * @param {RegExp} re\n * @return {undefined|Array}\n */\n function match(re) {\n var m = re.exec(style);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n style = style.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n function whitespace() {\n match(WHITESPACE_REGEX);\n }\n\n /**\n * Parse comments.\n *\n * @param {Object[]} [rules]\n * @return {Object[]}\n */\n function comments(rules) {\n var c;\n rules = rules || [];\n while ((c = comment())) {\n if (c !== false) {\n rules.push(c);\n }\n }\n return rules;\n }\n\n /**\n * Parse comment.\n *\n * @return {Object}\n * @throws {Error}\n */\n function comment() {\n var pos = position();\n if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;\n\n var i = 2;\n while (\n EMPTY_STRING != style.charAt(i) &&\n (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))\n ) {\n ++i;\n }\n i += 2;\n\n if (EMPTY_STRING === style.charAt(i - 1)) {\n return error('End of comment missing');\n }\n\n var str = style.slice(2, i - 2);\n column += 2;\n updatePosition(str);\n style = style.slice(i);\n column += 2;\n\n return pos({\n type: TYPE_COMMENT,\n comment: str\n });\n }\n\n /**\n * Parse declaration.\n *\n * @return {Object}\n * @throws {Error}\n */\n function declaration() {\n var pos = position();\n\n // prop\n var prop = match(PROPERTY_REGEX);\n if (!prop) return;\n comment();\n\n // :\n if (!match(COLON_REGEX)) return error(\"property missing ':'\");\n\n // val\n var val = match(VALUE_REGEX);\n\n var ret = pos({\n type: TYPE_DECLARATION,\n property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),\n value: val\n ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))\n : EMPTY_STRING\n });\n\n // ;\n match(SEMICOLON_REGEX);\n\n return ret;\n }\n\n /**\n * Parse declarations.\n *\n * @return {Object[]}\n */\n function declarations() {\n var decls = [];\n\n comments(decls);\n\n // declarations\n var decl;\n while ((decl = declaration())) {\n if (decl !== false) {\n decls.push(decl);\n comments(decls);\n }\n }\n\n return decls;\n }\n\n whitespace();\n return declarations();\n};\n\n/**\n * Trim `str`.\n *\n * @param {String} str\n * @return {String}\n */\nfunction trim(str) {\n return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;\n}\n","var parse = require('inline-style-parser');\n\n/**\n * Parses inline style to object.\n *\n * @example\n * // returns { 'line-height': '42' }\n * StyleToObject('line-height: 42;');\n *\n * @param {String} style - The inline style.\n * @param {Function} [iterator] - The iterator function.\n * @return {null|Object}\n */\nfunction StyleToObject(style, iterator) {\n var output = null;\n if (!style || typeof style !== 'string') {\n return output;\n }\n\n var declaration;\n var declarations = parse(style);\n var hasIterator = typeof iterator === 'function';\n var property;\n var value;\n\n for (var i = 0, len = declarations.length; i < len; i++) {\n declaration = declarations[i];\n property = declaration.property;\n value = declaration.value;\n\n if (hasIterator) {\n iterator(property, value, declaration);\n } else if (value) {\n output || (output = {});\n output[property] = value;\n }\n }\n\n return output;\n}\n\nmodule.exports = StyleToObject;\n"],"names":["style","options","TypeError","lineno","column","updatePosition","str","lines","match","NEWLINE_REGEX","length","i","lastIndexOf","position","start","line","node","Position","whitespace","this","end","source","error","msg","err","Error","reason","filename","silent","re","m","exec","slice","WHITESPACE_REGEX","comments","rules","c","comment","push","pos","charAt","EMPTY_STRING","type","declaration","prop","PROPERTY_REGEX","COLON_REGEX","val","VALUE_REGEX","ret","property","trim","replace","COMMENT_REGEX","value","SEMICOLON_REGEX","prototype","content","decl","decls","declarations","TRIM_REGEX","iterator","output","parse","hasIterator","len"],"mappings":"mMAiCiB,WAASA,EAAOC,GAC/B,GAAqB,iBAAVD,EACT,MAAM,IAAIE,UAAU,mCAGtB,IAAKF,EAAO,MAAO,GAEnBC,EAAUA,GAAW,GAKrB,IAAIE,EAAS,EACTC,EAAS,EAOb,SAASC,EAAeC,GACtB,IAAIC,EAAQD,EAAIE,MAAMC,GAClBF,IAAOJ,GAAUI,EAAMG,QAC3B,IAAIC,EAAIL,EAAIM,YAvCF,MAwCVR,GAAUO,EAAIL,EAAII,OAASC,EAAIP,EAASE,EAAII,OAQ9C,SAASG,IACP,IAAIC,EAAQ,CAAEC,KAAMZ,EAAQC,OAAQA,GACpC,OAAO,SAASY,GAGd,OAFAA,EAAKH,SAAW,IAAII,EAASH,GAC7BI,IACOF,GAYX,SAASC,EAASH,GAChBK,KAAKL,MAAQA,EACbK,KAAKC,IAAM,CAAEL,KAAMZ,EAAQC,OAAQA,GACnCe,KAAKE,OAASpB,EAAQoB,OAgBxB,SAASC,EAAMC,GACb,IAAIC,EAAM,IAAIC,MACZxB,EAAQoB,OAAS,IAAMlB,EAAS,IAAMC,EAAS,KAAOmB,GAQxD,GANAC,EAAIE,OAASH,EACbC,EAAIG,SAAW1B,EAAQoB,OACvBG,EAAIT,KAAOZ,EACXqB,EAAIpB,OAASA,EACboB,EAA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AUC,QAAUzD,EA6J7BkB,IAjBA,WACE,IAKIwC,EALAC,EAAQ,GAMZ,IAJAzB,EAASyB,GAIDD,EAAOf,MACA,IAATe,IACFC,EAAMrB,KAAKoB,GACXxB,EAASyB,IAIb,OAAOA,EAIFC,GAvPT,IAAIP,EAAgB,kCAEhB5C,EAAgB,MAChBwB,EAAmB,OAGnBY,EAAiB,yCACjBC,EAAc,QACdE,EAAc,uDACdO,EAAkB,UAGlBM,EAAa,aAMbpB,EAAe,GA8OnB,SAASU,EAAK7C,GACZ,OAAOA,EAAMA,EAAI8C,QAAQS,EAAYpB,GAAgBA,SCtPvD,SAAuBzC,EAAO8D,GAC5B,IAKInB,EALAoB,EAAS,KACb,IAAK/D,GAA0B,iBAAVA,EACnB,OAAO+D,EAST,IALA,IAEIb,EACAI,EAHAM,EAAeI,EAAMhE,GACrBiE,EAAkC,mBAAbH,EAIhBnD,EAAI,EAAGuD,EAAMN,EAAalD,OAAQC,EAAIuD,EAAKvD,IAElDuC,GADAP,EAAciB,EAAajD,IACJuC,SACvBI,EAAQX,EAAYW,MAEhBW,EACFH,EAASZ,EAAUI,EAAOX,GACjBW,KACES,EAAXA,GAAoB,IACbb,GAAYI,GAIvB,OAAOS"}
1
+ {"version":3,"file":"style-to-object.min.js","sources":["../node_modules/inline-style-parser/index.js","../index.js"],"sourcesContent":["// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar COMMENT_REGEX = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g;\n\nvar NEWLINE_REGEX = /\\n/g;\nvar WHITESPACE_REGEX = /^\\s*/;\n\n// declaration\nvar PROPERTY_REGEX = /^(\\*?[-#/*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/;\nvar COLON_REGEX = /^:\\s*/;\nvar VALUE_REGEX = /^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^)]*?\\)|[^};])+)/;\nvar SEMICOLON_REGEX = /^[;\\s]*/;\n\n// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill\nvar TRIM_REGEX = /^\\s+|\\s+$/g;\n\n// strings\nvar NEWLINE = '\\n';\nvar FORWARD_SLASH = '/';\nvar ASTERISK = '*';\nvar EMPTY_STRING = '';\n\n// types\nvar TYPE_COMMENT = 'comment';\nvar TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nmodule.exports = function(style, options) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n if (!style) return [];\n\n options = options || {};\n\n /**\n * Positional.\n */\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n *\n * @param {String} str\n */\n function updatePosition(str) {\n var lines = str.match(NEWLINE_REGEX);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf(NEWLINE);\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n *\n * @return {Function}\n */\n function position() {\n var start = { line: lineno, column: column };\n return function(node) {\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node.\n *\n * @constructor\n * @property {Object} start\n * @property {Object} end\n * @property {undefined|String} source\n */\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string.\n */\n Position.prototype.content = style;\n\n var errorsList = [];\n\n /**\n * Error `msg`.\n *\n * @param {String} msg\n * @throws {Error}\n */\n function error(msg) {\n var err = new Error(\n options.source + ':' + lineno + ':' + column + ': ' + msg\n );\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = style;\n\n if (options.silent) {\n errorsList.push(err);\n } else {\n throw err;\n }\n }\n\n /**\n * Match `re` and return captures.\n *\n * @param {RegExp} re\n * @return {undefined|Array}\n */\n function match(re) {\n var m = re.exec(style);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n style = style.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n function whitespace() {\n match(WHITESPACE_REGEX);\n }\n\n /**\n * Parse comments.\n *\n * @param {Object[]} [rules]\n * @return {Object[]}\n */\n function comments(rules) {\n var c;\n rules = rules || [];\n while ((c = comment())) {\n if (c !== false) {\n rules.push(c);\n }\n }\n return rules;\n }\n\n /**\n * Parse comment.\n *\n * @return {Object}\n * @throws {Error}\n */\n function comment() {\n var pos = position();\n if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;\n\n var i = 2;\n while (\n EMPTY_STRING != style.charAt(i) &&\n (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))\n ) {\n ++i;\n }\n i += 2;\n\n if (EMPTY_STRING === style.charAt(i - 1)) {\n return error('End of comment missing');\n }\n\n var str = style.slice(2, i - 2);\n column += 2;\n updatePosition(str);\n style = style.slice(i);\n column += 2;\n\n return pos({\n type: TYPE_COMMENT,\n comment: str\n });\n }\n\n /**\n * Parse declaration.\n *\n * @return {Object}\n * @throws {Error}\n */\n function declaration() {\n var pos = position();\n\n // prop\n var prop = match(PROPERTY_REGEX);\n if (!prop) return;\n comment();\n\n // :\n if (!match(COLON_REGEX)) return error(\"property missing ':'\");\n\n // val\n var val = match(VALUE_REGEX);\n\n var ret = pos({\n type: TYPE_DECLARATION,\n property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),\n value: val\n ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))\n : EMPTY_STRING\n });\n\n // ;\n match(SEMICOLON_REGEX);\n\n return ret;\n }\n\n /**\n * Parse declarations.\n *\n * @return {Object[]}\n */\n function declarations() {\n var decls = [];\n\n comments(decls);\n\n // declarations\n var decl;\n while ((decl = declaration())) {\n if (decl !== false) {\n decls.push(decl);\n comments(decls);\n }\n }\n\n return decls;\n }\n\n whitespace();\n return declarations();\n};\n\n/**\n * Trim `str`.\n *\n * @param {String} str\n * @return {String}\n */\nfunction trim(str) {\n return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;\n}\n","var parse = require('inline-style-parser');\n\n/**\n * Parses inline style to object.\n *\n * @example\n * // returns { 'line-height': '42' }\n * StyleToObject('line-height: 42;');\n *\n * @param {String} style - The inline style.\n * @param {Function} [iterator] - The iterator function.\n * @return {null|Object}\n */\nfunction StyleToObject(style, iterator) {\n var output = null;\n if (!style || typeof style !== 'string') {\n return output;\n }\n\n var declaration;\n var declarations = parse(style);\n var hasIterator = typeof iterator === 'function';\n var property;\n var value;\n\n for (var i = 0, len = declarations.length; i < len; i++) {\n declaration = declarations[i];\n property = declaration.property;\n value = declaration.value;\n\n if (hasIterator) {\n iterator(property, value, declaration);\n } else if (value) {\n output || (output = {});\n output[property] = value;\n }\n }\n\n return output;\n}\n\nmodule.exports = StyleToObject;\nmodule.exports.default = StyleToObject; // ESM support\n"],"names":["COMMENT_REGEX","NEWLINE_REGEX","WHITESPACE_REGEX","PROPERTY_REGEX","COLON_REGEX","VALUE_REGEX","SEMICOLON_REGEX","TRIM_REGEX","EMPTY_STRING","trim","str","replace","parse","style","options","TypeError","lineno","column","updatePosition","lines","match","length","i","lastIndexOf","position","start","line","node","Position","whitespace","this","end","source","error","msg","err","Error","reason","filename","silent","re","m","exec","slice","comments","rules","c","comment","push","pos","charAt","type","declaration","prop","val","ret","property","value","prototype","content","decl","decls","declarations","StyleToObject","iterator","output","hasIterator","len","exports","default"],"mappings":"qQAEIA,EAAgB,kCAEhBC,EAAgB,MAChBC,EAAmB,OAGnBC,EAAiB,yCACjBC,EAAc,QACdC,EAAc,uDACdC,EAAkB,UAGlBC,EAAa,aAMbC,EAAe,GA8OnB,SAASC,EAAKC,GACZ,OAAOA,EAAMA,EAAIC,QAAQJ,EAAYC,GAAgBA,CACvD,CCpQA,IAAII,EDiCa,SAASC,EAAOC,GAC/B,GAAqB,iBAAVD,EACT,MAAM,IAAIE,UAAU,m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,EAAaxC,IACJkC,SACvBC,EAAQL,EAAYK,MAEhBS,EACFF,EAASR,EAAUC,EAAOL,GACjBK,IACTQ,IAAWA,EAAS,CAAA,GACpBA,EAAOT,GAAYC,GAIvB,OAAOQ,CACT,iFAEcG,QAAGL,EACKK,QAAA,QAAAC,QAAGN"}
package/index.js CHANGED
@@ -40,3 +40,4 @@ function StyleToObject(style, iterator) {
40
40
  }
41
41
 
42
42
  module.exports = StyleToObject;
43
+ module.exports.default = StyleToObject; // ESM support
package/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import StyleToObject from './index.js';
2
+
3
+ export default StyleToObject;
package/package.json CHANGED
@@ -1,25 +1,31 @@
1
1
  {
2
2
  "name": "style-to-object",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Converts inline style to object.",
5
5
  "author": "Mark <mark@remarkablemark.org>",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
+ "module": "index.mjs",
9
+ "exports": {
10
+ "types": "./index.d.ts",
11
+ "import": "./index.mjs",
12
+ "require": "./index.js"
13
+ },
8
14
  "scripts": {
9
15
  "build": "run-s build:*",
10
16
  "build:min": "NODE_ENV=production rollup --config --file dist/style-to-object.min.js --sourcemap",
11
17
  "build:unmin": "NODE_ENV=development rollup --config --file dist/style-to-object.js",
12
18
  "clean": "rm -rf dist",
13
- "coveralls": "nyc report --reporter=text-lcov | coveralls",
14
19
  "lint": "eslint --ignore-path .gitignore .",
15
20
  "lint:fix": "npm run lint -- --fix",
16
21
  "lint:dts": "dtslint .",
17
- "prepublishOnly": "run-s lint lint:dts test clean build",
18
- "release": "standard-version --no-verify",
19
- "test": "mocha",
22
+ "_postinstall": "husky install",
23
+ "postpublish": "pinst --enable",
24
+ "prepublishOnly": "pinst --disable && run-s lint lint:dts test clean build",
25
+ "test": "mocha --exclude **/*.mjs",
20
26
  "test:coverage": "nyc npm test",
21
- "test:coverage:report": "nyc report --reporter=html",
22
- "test:watch": "mocha --watch"
27
+ "test:module": "node --experimental-modules test/index.mjs",
28
+ "test:watch": "npm run test -- --watch"
23
29
  },
24
30
  "repository": {
25
31
  "type": "git",
@@ -41,27 +47,29 @@
41
47
  "inline-style-parser": "0.1.1"
42
48
  },
43
49
  "devDependencies": {
44
- "@commitlint/cli": "^8.2.0",
45
- "@commitlint/config-conventional": "^8.2.0",
46
- "coveralls": "^3.0.7",
47
- "dtslint": "^1.0.3",
48
- "eslint": "^6.6.0",
49
- "eslint-plugin-prettier": "^3.1.1",
50
- "husky": "^3.0.9",
51
- "lint-staged": "^9.4.2",
52
- "mocha": "^6.2.2",
53
- "npm-run-all": "^4.1.5",
54
- "nyc": "^14.1.1",
55
- "prettier": "^1.18.2",
56
- "rollup": "^1.26.3",
57
- "rollup-plugin-commonjs": "^10.1.0",
58
- "rollup-plugin-node-resolve": "^5.2.0",
59
- "rollup-plugin-uglify": "^6.0.3",
60
- "standard-version": "^6"
50
+ "@commitlint/cli": "17.4.2",
51
+ "@commitlint/config-conventional": "17.4.2",
52
+ "@rollup/plugin-commonjs": "24.0.0",
53
+ "@rollup/plugin-node-resolve": "15.0.1",
54
+ "@rollup/plugin-terser": "0.3.0",
55
+ "dtslint": "4.2.1",
56
+ "eslint": "8.32.0",
57
+ "eslint-plugin-prettier": "4.2.1",
58
+ "husky": "8.0.3",
59
+ "lint-staged": "13.1.0",
60
+ "mocha": "10.2.0",
61
+ "npm-run-all": "4.1.5",
62
+ "nyc": "15.1.0",
63
+ "pinst": "3.0.0",
64
+ "prettier": "2.8.3",
65
+ "rollup": "2.79.1",
66
+ "typescript": "4.9.4"
61
67
  },
62
68
  "files": [
63
69
  "/dist",
64
- "index.d.ts"
70
+ "index.d.ts",
71
+ "index.js",
72
+ "index.mjs"
65
73
  ],
66
74
  "license": "MIT"
67
75
  }
package/CHANGELOG.md DELETED
@@ -1,83 +0,0 @@
1
- # Changelog
2
-
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
-
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
-
60
- <a name="0.2.0"></a>
61
- # [0.2.0](https://github.com/remarkablemark/style-to-object/compare/v0.1.0...v0.2.0) (2017-11-26)
62
-
63
-
64
- ### Features
65
-
66
- * **parser:** add optional argument iterator ([a3deea8](https://github.com/remarkablemark/style-to-object/commit/a3deea8))
67
-
68
-
69
-
70
- <a name="0.1.0"></a>
71
- # 0.1.0 (2017-11-23)
72
-
73
-
74
- ### Bug Fixes
75
-
76
- * **parser:** do not add to output if css value is empty ([0759da7](https://github.com/remarkablemark/style-to-object/commit/0759da7))
77
-
78
-
79
- ### Features
80
-
81
- * **parser:** create client parser ([cd85a31](https://github.com/remarkablemark/style-to-object/commit/cd85a31))
82
- * **parser:** create parser that returns null for invalid values ([24f4f02](https://github.com/remarkablemark/style-to-object/commit/24f4f02))
83
- * **parser:** parse inline style to object with css.parse ([04793b0](https://github.com/remarkablemark/style-to-object/commit/04793b0))