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.
@@ -1 +1,2 @@
1
- !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):r.StyleToObject=e()}(this,function(){"use strict";function r(r){return r?r.replace(/^\s+|\s+$/g,""):""}function e(r,n){var t=r&&"string"==typeof r.type,i=t?r:n;for(var s in r){var a=r[s];Array.isArray(a)?a.forEach(function(r){e(r,i)}):a&&"object"==typeof a&&e(a,i)}return t&&Object.defineProperty(r,"parent",{configurable:!0,writable:!0,enumerable:!1,value:n||null}),r}var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;return function(t,i){if(!t||"string"!=typeof t)return null;for(var s,a,u,o=function(t,i){function s(r){var e=r.match(/\n/g);e&&(A+=e.length);var n=r.lastIndexOf("\n");b=~n?r.length-n:b+r.length}function a(){var r={line:A,column:b};return function(e){return e.position=new u(r),l(),e}}function u(r){this.start=r,this.end={line:A,column:b},this.source=i.source}function o(r){var e=new Error(i.source+":"+A+":"+b+": "+r);if(e.reason=r,e.filename=i.source,e.line=A,e.column=b,e.source=t,!i.silent)throw e;k.push(e)}function c(){return m(/^{\s*/)}function f(){return m(/^}/)}function p(){var e,n=[];for(l(),v(n);t.length&&"}"!=t.charAt(0)&&(e=function(){if("@"==t[0])return function(){var r=a(),e=m(/^@([-\w]+)?keyframes\s*/);if(e){var n=e[1];if(!(e=m(/^([-\w]+)\s*/)))return o("@keyframes missing name");var t=e[1];if(!c())return o("@keyframes missing '{'");for(var i,s=v();i=h();)s.push(i),s=s.concat(v());return f()?r({type:"keyframes",name:t,vendor:n,keyframes:s}):o("@keyframes missing '}'")}}()||function(){var e=a(),t=m(/^@media *([^{]+)/);if(t){var i=r(t[1]);if(!c())return o("@media missing '{'");var s=v().concat(n());return f()?e({type:"media",media:i,rules:s}):o("@media missing '}'")}}()||function(){var e=a(),n=m(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);if(n)return e({type:"custom-media",name:r(n[1]),media:r(n[2])})}()||function(){var e=a(),t=m(/^@supports *([^{]+)/);if(t){var i=r(t[1]);if(!c())return o("@supports missing '{'");var s=v().concat(n());return f()?e({type:"supports",supports:i,rules:s}):o("@supports missing '}'")}}()||x()||E()||j()||function(){var e=a(),t=m(/^@([-\w]+)?document *([^{]+)/);if(t){var i=r(t[1]),s=r(t[2]);if(!c())return o("@document missing '{'");var u=v().concat(n());return f()?e({type:"document",document:s,vendor:i,rules:u}):o("@document missing '}'")}}()||function(){var r=a();if(m(/^@page */)){var e=g()||[];if(!c())return o("@page missing '{'");for(var n,t=v();n=y();)t.push(n),t=t.concat(v());return f()?r({type:"page",selectors:e,declarations:t}):o("@page missing '}'")}}()||function(){var r=a();if(m(/^@host\s*/)){if(!c())return o("@host missing '{'");var e=v().concat(n());return f()?r({type:"host",rules:e}):o("@host missing '}'")}}()||function(){var r=a();if(m(/^@font-face\s*/)){if(!c())return o("@font-face missing '{'");for(var e,n=v();e=y();)n.push(e),n=n.concat(v());return f()?r({type:"font-face",declarations:n}):o("@font-face missing '}'")}}()}()||function(){var r=a(),e=g();return e?(v(),r({type:"rule",selectors:e,declarations:d()})):o("selector missing")}());)!1!==e&&(n.push(e),v(n));return n}function m(r){var e=r.exec(t);if(e){var n=e[0];return s(n),t=t.slice(n.length),e}}function l(){m(/^\s*/)}function v(r){var e;for(r=r||[];e=function(){var r=a();if("/"==t.charAt(0)&&"*"==t.charAt(1)){for(var e=2;""!=t.charAt(e)&&("*"!=t.charAt(e)||"/"!=t.charAt(e+1));)++e;if(e+=2,""===t.charAt(e-1))return o("End of comment missing");var n=t.slice(2,e-2);return b+=2,s(n),t=t.slice(e),b+=2,r({type:"comment",comment:n})}}();)!1!==e&&r.push(e);return r}function g(){var e=m(/^([^{]+)/);if(e)return r(e[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,function(r){return r.replace(/,/g,"‌")}).split(/\s*(?![^(]*\)),\s*/).map(function(r){return r.replace(/\u200C/g,",")})}function y(){var e=a(),t=m(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(t){if(t=r(t[0]),!m(/^:\s*/))return o("property missing ':'");var i=m(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/),s=e({type:"declaration",property:t.replace(n,""),value:i?r(i[0]).replace(n,""):""});return m(/^[;\s]*/),s}}function d(){var r=[];if(!c())return o("missing '{'");v(r);for(var e;e=y();)!1!==e&&(r.push(e),v(r));return f()?r:o("missing '}'")}function h(){for(var r,e=[],n=a();r=m(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)e.push(r[1]),m(/^,\s*/);if(e.length)return n({type:"keyframe",values:e,declarations:d()})}function w(r){var e=new RegExp("^@"+r+"\\s*([^;]+);");return function(){var n=a(),t=m(e);if(t){var i={type:r};return i[r]=t[1].trim(),n(i)}}}i=i||{};var A=1,b=1;u.prototype.content=t;var k=[],x=w("import"),E=w("charset"),j=w("namespace");return e({type:"stylesheet",stylesheet:{rules:p(),parsingErrors:k}})}("p{"+t+"}").stylesheet.rules[0].declarations,c=null,f="function"==typeof i,p=0,m=o.length;p<m;p++)a=(s=o[p]).property,u=s.value,f?i(a,u,s):u&&(c||(c={}),c[a]=u);return c}});
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}});
2
+ //# sourceMappingURL=style-to-object.min.js.map
@@ -0,0 +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,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+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"}
package/index.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Parses inline style to object.
3
+ *
4
+ * @example
5
+ * import StyleToObject from 'style-to-object';
6
+ * StyleToObject('line-height: 42;');
7
+ */
8
+ declare function StyleToObject(
9
+ style: string,
10
+ iterator?: StyleToObject.Iterator
11
+ ): { [name: string]: string } | null;
12
+
13
+ export = StyleToObject;
14
+
15
+ declare namespace StyleToObject {
16
+ interface DeclarationPos {
17
+ line: number;
18
+ column: number;
19
+ }
20
+
21
+ // declaration is an object from module `inline-style-parser`
22
+ interface Declaration {
23
+ type: string;
24
+ property: string;
25
+ value: string;
26
+ position: {
27
+ start: DeclarationPos;
28
+ end: DeclarationPos;
29
+ source: any;
30
+ };
31
+ }
32
+
33
+ type Iterator = (
34
+ property: string,
35
+ value: string,
36
+ declaration: Declaration
37
+ ) => void;
38
+ }
package/index.js CHANGED
@@ -1,23 +1,27 @@
1
- var parse = require('css/lib/parse');
1
+ var parse = require('inline-style-parser');
2
2
 
3
3
  /**
4
- * Parses inline style.
4
+ * Parses inline style to object.
5
5
  *
6
- * Example: 'color:red' => { color: 'red' }
6
+ * @example
7
+ * // returns { 'line-height': '42' }
8
+ * StyleToObject('line-height: 42;');
7
9
  *
8
10
  * @param {String} style - The inline style.
9
11
  * @param {Function} [iterator] - The iterator function.
10
12
  * @return {null|Object}
11
13
  */
12
- module.exports = function parseInlineStyle(style, iterator) {
13
- if (!style || typeof style !== 'string') return null;
14
-
15
- // make sure to wrap declarations in placeholder
16
- var declarations = parse('p{' + style + '}').stylesheet.rules[0].declarations;
17
- var declaration, property, value;
18
-
14
+ function StyleToObject(style, iterator) {
19
15
  var output = null;
16
+ if (!style || typeof style !== 'string') {
17
+ return output;
18
+ }
19
+
20
+ var declaration;
21
+ var declarations = parse(style);
20
22
  var hasIterator = typeof iterator === 'function';
23
+ var property;
24
+ var value;
21
25
 
22
26
  for (var i = 0, len = declarations.length; i < len; i++) {
23
27
  declaration = declarations[i];
@@ -33,4 +37,6 @@ module.exports = function parseInlineStyle(style, iterator) {
33
37
  }
34
38
 
35
39
  return output;
36
- };
40
+ }
41
+
42
+ module.exports = StyleToObject;
package/package.json CHANGED
@@ -1,20 +1,25 @@
1
1
  {
2
2
  "name": "style-to-object",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Converts inline style to object.",
5
5
  "author": "Mark <mark@remarkablemark.org>",
6
6
  "main": "index.js",
7
+ "types": "index.d.ts",
7
8
  "scripts": {
8
- "prepublishOnly": "npm run build",
9
- "release": "standard-version",
10
- "test": "mocha",
11
- "lint": "eslint --ignore-path .gitignore .",
12
- "cover": "istanbul cover _mocha -- -R spec \"test/**/*.js\"",
13
- "coveralls": "cat coverage/lcov.info | coveralls",
9
+ "build": "run-s build:*",
10
+ "build:min": "NODE_ENV=production rollup --config --file dist/style-to-object.min.js --sourcemap",
11
+ "build:unmin": "NODE_ENV=development rollup --config --file dist/style-to-object.js",
14
12
  "clean": "rm -rf dist",
15
- "build": "npm run clean && npm run build:min && npm run build:unmin",
16
- "build:min": "NODE_ENV=production rollup --config --output.file dist/style-to-object.min.js",
17
- "build:unmin": "rollup --config --output.file dist/style-to-object.js"
13
+ "coveralls": "nyc report --reporter=text-lcov | coveralls",
14
+ "lint": "eslint --ignore-path .gitignore .",
15
+ "lint:fix": "npm run lint -- --fix",
16
+ "lint:dts": "dtslint .",
17
+ "prepublishOnly": "run-s lint lint:dts test clean build",
18
+ "release": "standard-version --no-verify",
19
+ "test": "mocha",
20
+ "test:coverage": "nyc npm test",
21
+ "test:coverage:report": "nyc report --reporter=html",
22
+ "test:watch": "mocha --watch"
18
23
  },
19
24
  "repository": {
20
25
  "type": "git",
@@ -24,26 +29,39 @@
24
29
  "url": "https://github.com/remarkablemark/style-to-object/issues"
25
30
  },
26
31
  "keywords": [
32
+ "style-to-object",
27
33
  "inline",
28
- "css",
29
34
  "style",
35
+ "parser",
36
+ "css",
30
37
  "object",
31
38
  "pojo"
32
39
  ],
33
40
  "dependencies": {
34
- "css": "2.2.1"
41
+ "inline-style-parser": "0.1.1"
35
42
  },
36
43
  "devDependencies": {
37
- "coveralls": "3.0.0",
38
- "eslint": "4.11.0",
39
- "istanbul": "0.4.5",
40
- "mocha": "4.0.1",
41
- "rollup": "0.51.5",
42
- "rollup-plugin-commonjs": "8.2.6",
43
- "rollup-plugin-node-resolve": "3.0.0",
44
- "rollup-plugin-uglify": "2.0.1",
45
- "standard-version": "4.2.0",
46
- "uglify-es": "3.1.9"
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"
47
61
  },
62
+ "files": [
63
+ "/dist",
64
+ "index.d.ts"
65
+ ],
48
66
  "license": "MIT"
49
67
  }