style-to-object 1.0.13 → 2.0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # style-to-object
2
2
 
3
- [![NPM](https://nodei.co/npm/style-to-object.png)](https://nodei.co/npm/style-to-object/)
3
+ [![NPM](https://nodei.co/npm/style-to-object.svg)](https://b.remarkabl.org/style-to-object)
4
4
 
5
5
  [![NPM version](https://img.shields.io/npm/v/style-to-object)](https://www.npmjs.com/package/style-to-object)
6
6
  [![NPM bundle size](https://img.shields.io/bundlephobia/minzip/style-to-object)](https://bundlephobia.com/package/style-to-object)
@@ -166,6 +166,10 @@ console.log(output); // [['color', 'red'], ['background', 'blue']]
166
166
 
167
167
  ## Migration
168
168
 
169
+ ### v2
170
+
171
+ Changed build target from `es5` to `es6`.
172
+
169
173
  ### v1
170
174
 
171
175
  Migrated to TypeScript. Iterator excludes `Comment`. CommonJS requires the `.default` key:
package/cjs/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import type { Declaration } from 'inline-style-parser';
2
- export { Declaration };
3
- export interface StyleObject {
4
- [name: string]: string;
5
- }
1
+ import { Declaration } from "inline-style-parser";
2
+
3
+ //#region src/index.d.ts
4
+ type StyleObject = Record<string, string>;
6
5
  type Iterator = (property: string, value: string, declaration: Declaration) => void;
7
6
  /**
8
7
  * Parses inline style to object.
@@ -18,5 +17,7 @@ type Iterator = (property: string, value: string, declaration: Declaration) => v
18
17
  * parse('line-height: 42;'); // { 'line-height': '42' }
19
18
  * ```
20
19
  */
21
- export default function StyleToObject(style: string, iterator?: Iterator): StyleObject | null;
20
+ declare function StyleToObject(style: string, iterator?: Iterator): StyleObject | null;
21
+ //#endregion
22
+ export { type Declaration, StyleObject, StyleToObject as default };
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,MAAM,WAAW,WAAW;IAC1B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,KAAK,QAAQ,GAAG,CACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,KACrB,IAAI,CAAC;AAEV;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,QAAQ,GAClB,WAAW,GAAG,IAAI,CA0BpB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;KAKY,WAAA,GAAc,MAAM;AAAA,KAE3B,QAAA,IACH,QAAA,UACA,KAAA,UACA,WAAA,EAAa,WAAW;;;;AALM;AAAiB;;;;;;;;;AAKvB;iBAiBF,aAAA,CACtB,KAAA,UACA,QAAA,GAAW,QAAA,GACV,WAAW"}
package/cjs/index.js CHANGED
@@ -1,44 +1,59 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
4
17
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = StyleToObject;
7
- const inline_style_parser_1 = __importDefault(require("inline-style-parser"));
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let inline_style_parser = require("inline-style-parser");
24
+ inline_style_parser = __toESM(inline_style_parser);
25
+ //#region src/index.ts
8
26
  /**
9
- * Parses inline style to object.
10
- *
11
- * @param style - Inline style.
12
- * @param iterator - Iterator.
13
- * @returns - Style object or null.
14
- *
15
- * @example Parsing inline style to object:
16
- *
17
- * ```js
18
- * import parse from 'style-to-object';
19
- * parse('line-height: 42;'); // { 'line-height': '42' }
20
- * ```
21
- */
27
+ * Parses inline style to object.
28
+ *
29
+ * @param style - Inline style.
30
+ * @param iterator - Iterator.
31
+ * @returns - Style object or null.
32
+ *
33
+ * @example Parsing inline style to object:
34
+ *
35
+ * ```js
36
+ * import parse from 'style-to-object';
37
+ * parse('line-height: 42;'); // { 'line-height': '42' }
38
+ * ```
39
+ */
22
40
  function StyleToObject(style, iterator) {
23
- let styleObject = null;
24
- if (!style || typeof style !== 'string') {
25
- return styleObject;
26
- }
27
- const declarations = (0, inline_style_parser_1.default)(style);
28
- const hasIterator = typeof iterator === 'function';
29
- declarations.forEach((declaration) => {
30
- if (declaration.type !== 'declaration') {
31
- return;
32
- }
33
- const { property, value } = declaration;
34
- if (hasIterator) {
35
- iterator(property, value, declaration);
36
- }
37
- else if (value) {
38
- styleObject = styleObject || {};
39
- styleObject[property] = value;
40
- }
41
- });
42
- return styleObject;
41
+ let styleObject = null;
42
+ if (!style || typeof style !== "string") return styleObject;
43
+ const declarations = (0, inline_style_parser.default)(style);
44
+ const hasIterator = typeof iterator === "function";
45
+ declarations.forEach((declaration) => {
46
+ if (declaration.type !== "declaration") return;
47
+ const { property, value } = declaration;
48
+ if (hasIterator) iterator(property, value, declaration);
49
+ else if (value) {
50
+ styleObject = styleObject ?? {};
51
+ styleObject[property] = value;
52
+ }
53
+ });
54
+ return styleObject;
43
55
  }
56
+ //#endregion
57
+ module.exports = StyleToObject;
58
+
44
59
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AA6BA,gCA6BC;AAzDD,8EAAwC;AAcxC;;;;;;;;;;;;;GAaG;AACH,SAAwB,aAAa,CACnC,KAAa,EACb,QAAmB;IAEnB,IAAI,WAAW,GAAuB,IAAI,CAAC;IAE3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,6BAAK,EAAC,KAAK,CAAC,CAAC;IAClC,MAAM,WAAW,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC;IAEnD,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QACnC,IAAI,WAAW,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC;QAExC,IAAI,WAAW,EAAE,CAAC;YAChB,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QACzC,CAAC;aAAM,IAAI,KAAK,EAAE,CAAC;YACjB,WAAW,GAAG,WAAW,IAAI,EAAE,CAAC;YAChC,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;QAChC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Declaration } from 'inline-style-parser';\nimport parse from 'inline-style-parser';\n\nexport { Declaration };\n\nexport type StyleObject = Record<string, string>;\n\ntype Iterator = (\n property: string,\n value: string,\n declaration: Declaration,\n) => void;\n\n/**\n * Parses inline style to object.\n *\n * @param style - Inline style.\n * @param iterator - Iterator.\n * @returns - Style object or null.\n *\n * @example Parsing inline style to object:\n *\n * ```js\n * import parse from 'style-to-object';\n * parse('line-height: 42;'); // { 'line-height': '42' }\n * ```\n */\nexport default function StyleToObject(\n style: string,\n iterator?: Iterator,\n): StyleObject | null {\n let styleObject: StyleObject | null = null;\n\n if (!style || typeof style !== 'string') {\n return styleObject;\n }\n\n const declarations = parse(style);\n const hasIterator = typeof iterator === 'function';\n\n declarations.forEach((declaration) => {\n if (declaration.type !== 'declaration') {\n return;\n }\n\n const { property, value } = declaration;\n\n if (hasIterator) {\n iterator(property, value, declaration);\n } else if (value) {\n styleObject = styleObject ?? {};\n styleObject[property] = value;\n }\n });\n\n return styleObject;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAwB,cACtB,OACA,UACoB;CACpB,IAAI,cAAkC;CAEtC,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;CAGT,MAAM,gBAAA,GAAA,oBAAA,QAAA,CAAqB,KAAK;CAChC,MAAM,cAAc,OAAO,aAAa;CAExC,aAAa,SAAS,gBAAgB;EACpC,IAAI,YAAY,SAAS,eACvB;EAGF,MAAM,EAAE,UAAU,UAAU;EAE5B,IAAI,aACF,SAAS,UAAU,OAAO,WAAW;OAChC,IAAI,OAAO;GAChB,cAAc,eAAe,CAAC;GAC9B,YAAY,YAAY;EAC1B;CACF,CAAC;CAED,OAAO;AACT"}
@@ -1,305 +1,62 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.StyleToObject = factory());
5
- })(this, (function () { 'use strict';
6
-
7
- // http://www.w3.org/TR/CSS21/grammar.html
8
- // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
9
- var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
10
-
11
- var NEWLINE_REGEX = /\n/g;
12
- var WHITESPACE_REGEX = /^\s*/;
13
-
14
- // declaration
15
- var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
16
- var COLON_REGEX = /^:\s*/;
17
- var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
18
- var SEMICOLON_REGEX = /^[;\s]*/;
19
-
20
- // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
21
- var TRIM_REGEX = /^\s+|\s+$/g;
22
-
23
- // strings
24
- var NEWLINE = '\n';
25
- var FORWARD_SLASH = '/';
26
- var ASTERISK = '*';
27
- var EMPTY_STRING = '';
28
-
29
- // types
30
- var TYPE_COMMENT = 'comment';
31
- var TYPE_DECLARATION = 'declaration';
32
-
33
- /**
34
- * @param {String} style
35
- * @param {Object} [options]
36
- * @return {Object[]}
37
- * @throws {TypeError}
38
- * @throws {Error}
39
- */
40
- function index (style, options) {
41
- if (typeof style !== 'string') {
42
- throw new TypeError('First argument must be a string');
43
- }
44
-
45
- if (!style) return [];
46
-
47
- options = options || {};
48
-
49
- /**
50
- * Positional.
51
- */
52
- var lineno = 1;
53
- var column = 1;
54
-
55
- /**
56
- * Update lineno and column based on `str`.
57
- *
58
- * @param {String} str
59
- */
60
- function updatePosition(str) {
61
- var lines = str.match(NEWLINE_REGEX);
62
- if (lines) lineno += lines.length;
63
- var i = str.lastIndexOf(NEWLINE);
64
- column = ~i ? str.length - i : column + str.length;
65
- }
66
-
67
- /**
68
- * Mark position and patch `node.position`.
69
- *
70
- * @return {Function}
71
- */
72
- function position() {
73
- var start = { line: lineno, column: column };
74
- return function (node) {
75
- node.position = new Position(start);
76
- whitespace();
77
- return node;
78
- };
79
- }
80
-
81
- /**
82
- * Store position information for a node.
83
- *
84
- * @constructor
85
- * @property {Object} start
86
- * @property {Object} end
87
- * @property {undefined|String} source
88
- */
89
- function Position(start) {
90
- this.start = start;
91
- this.end = { line: lineno, column: column };
92
- this.source = options.source;
93
- }
94
-
95
- /**
96
- * Non-enumerable source string.
97
- */
98
- Position.prototype.content = style;
99
-
100
- /**
101
- * Error `msg`.
102
- *
103
- * @param {String} msg
104
- * @throws {Error}
105
- */
106
- function error(msg) {
107
- var err = new Error(
108
- options.source + ':' + lineno + ':' + column + ': ' + msg
109
- );
110
- err.reason = msg;
111
- err.filename = options.source;
112
- err.line = lineno;
113
- err.column = column;
114
- err.source = style;
115
-
116
- if (options.silent) ; else {
117
- throw err;
118
- }
119
- }
120
-
121
- /**
122
- * Match `re` and return captures.
123
- *
124
- * @param {RegExp} re
125
- * @return {undefined|Array}
126
- */
127
- function match(re) {
128
- var m = re.exec(style);
129
- if (!m) return;
130
- var str = m[0];
131
- updatePosition(str);
132
- style = style.slice(str.length);
133
- return m;
134
- }
135
-
136
- /**
137
- * Parse whitespace.
138
- */
139
- function whitespace() {
140
- match(WHITESPACE_REGEX);
141
- }
142
-
143
- /**
144
- * Parse comments.
145
- *
146
- * @param {Object[]} [rules]
147
- * @return {Object[]}
148
- */
149
- function comments(rules) {
150
- var c;
151
- rules = rules || [];
152
- while ((c = comment())) {
153
- if (c !== false) {
154
- rules.push(c);
155
- }
156
- }
157
- return rules;
158
- }
159
-
160
- /**
161
- * Parse comment.
162
- *
163
- * @return {Object}
164
- * @throws {Error}
165
- */
166
- function comment() {
167
- var pos = position();
168
- if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
169
-
170
- var i = 2;
171
- while (
172
- EMPTY_STRING != style.charAt(i) &&
173
- (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
174
- ) {
175
- ++i;
176
- }
177
- i += 2;
178
-
179
- if (EMPTY_STRING === style.charAt(i - 1)) {
180
- return error('End of comment missing');
181
- }
182
-
183
- var str = style.slice(2, i - 2);
184
- column += 2;
185
- updatePosition(str);
186
- style = style.slice(i);
187
- column += 2;
188
-
189
- return pos({
190
- type: TYPE_COMMENT,
191
- comment: str
192
- });
193
- }
194
-
195
- /**
196
- * Parse declaration.
197
- *
198
- * @return {Object}
199
- * @throws {Error}
200
- */
201
- function declaration() {
202
- var pos = position();
203
-
204
- // prop
205
- var prop = match(PROPERTY_REGEX);
206
- if (!prop) return;
207
- comment();
208
-
209
- // :
210
- if (!match(COLON_REGEX)) return error("property missing ':'");
211
-
212
- // val
213
- var val = match(VALUE_REGEX);
214
-
215
- var ret = pos({
216
- type: TYPE_DECLARATION,
217
- property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
218
- value: val
219
- ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
220
- : EMPTY_STRING
221
- });
222
-
223
- // ;
224
- match(SEMICOLON_REGEX);
225
-
226
- return ret;
227
- }
228
-
229
- /**
230
- * Parse declarations.
231
- *
232
- * @return {Object[]}
233
- */
234
- function declarations() {
235
- var decls = [];
236
-
237
- comments(decls);
238
-
239
- // declarations
240
- var decl;
241
- while ((decl = declaration())) {
242
- if (decl !== false) {
243
- decls.push(decl);
244
- comments(decls);
245
- }
246
- }
247
-
248
- return decls;
249
- }
250
-
251
- whitespace();
252
- return declarations();
253
- }
254
-
255
- /**
256
- * Trim `str`.
257
- *
258
- * @param {String} str
259
- * @return {String}
260
- */
261
- function trim(str) {
262
- return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
263
- }
264
-
265
- /**
266
- * Parses inline style to object.
267
- *
268
- * @param style - Inline style.
269
- * @param iterator - Iterator.
270
- * @returns - Style object or null.
271
- *
272
- * @example Parsing inline style to object:
273
- *
274
- * ```js
275
- * import parse from 'style-to-object';
276
- * parse('line-height: 42;'); // { 'line-height': '42' }
277
- * ```
278
- */
279
- function StyleToObject(style, iterator) {
280
- let styleObject = null;
281
- if (!style || typeof style !== 'string') {
282
- return styleObject;
283
- }
284
- const declarations = index(style);
285
- const hasIterator = typeof iterator === 'function';
286
- declarations.forEach((declaration) => {
287
- if (declaration.type !== 'declaration') {
288
- return;
289
- }
290
- const { property, value } = declaration;
291
- if (hasIterator) {
292
- iterator(property, value, declaration);
293
- }
294
- else if (value) {
295
- styleObject = styleObject || {};
296
- styleObject[property] = value;
297
- }
298
- });
299
- return styleObject;
300
- }
301
-
302
- return StyleToObject;
303
-
304
- }));
305
- //# sourceMappingURL=style-to-object.js.map
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(require("inline-style-parser")) : typeof define === "function" && define.amd ? define(["inline-style-parser"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.StyleToObject = factory(global.inline_style_parser));
3
+ })(this, function(inline_style_parser) {
4
+ //#region \0rolldown/runtime.js
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ //#endregion
26
+ inline_style_parser = __toESM(inline_style_parser);
27
+ //#region src/index.ts
28
+ /**
29
+ * Parses inline style to object.
30
+ *
31
+ * @param style - Inline style.
32
+ * @param iterator - Iterator.
33
+ * @returns - Style object or null.
34
+ *
35
+ * @example Parsing inline style to object:
36
+ *
37
+ * ```js
38
+ * import parse from 'style-to-object';
39
+ * parse('line-height: 42;'); // { 'line-height': '42' }
40
+ * ```
41
+ */
42
+ function StyleToObject(style, iterator) {
43
+ let styleObject = null;
44
+ if (!style || typeof style !== "string") return styleObject;
45
+ const declarations = (0, inline_style_parser.default)(style);
46
+ const hasIterator = typeof iterator === "function";
47
+ declarations.forEach((declaration) => {
48
+ if (declaration.type !== "declaration") return;
49
+ const { property, value } = declaration;
50
+ if (hasIterator) iterator(property, value, declaration);
51
+ else if (value) {
52
+ styleObject = styleObject ?? {};
53
+ styleObject[property] = value;
54
+ }
55
+ });
56
+ return styleObject;
57
+ }
58
+ //#endregion
59
+ return StyleToObject;
60
+ });
61
+
62
+ //# sourceMappingURL=style-to-object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style-to-object.js","sources":["../node_modules/inline-style-parser/esm/index.mjs","../src/index.ts"],"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 */\nfunction index (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 /**\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) ; 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) : EMPT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AO,CAAC,CAAC,WAAW,KAAI;EACnC,QAAA,IAAI,WAAW,CAAC,IAAI,KAAK,aAAa,EAAE;cACtC;UACF;EAEA,QAAA,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,WAAW;UAEvC,IAAI,WAAW,EAAE;EACf,YAAA,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC;UACxC;eAAO,IAAI,KAAK,EAAE;EAChB,YAAA,WAAW,GAAG,WAAW,IAAI,EAAE;EAC/B,YAAA,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK;UAC/B;EACF,IAAA,CAAC,CAAC;EAEF,IAAA,OAAO,WAAW;EACpB;;;;;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"style-to-object.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Declaration } from 'inline-style-parser';\nimport parse from 'inline-style-parser';\n\nexport { Declaration };\n\nexport type StyleObject = Record<string, string>;\n\ntype Iterator = (\n property: string,\n value: string,\n declaration: Declaration,\n) => void;\n\n/**\n * Parses inline style to object.\n *\n * @param style - Inline style.\n * @param iterator - Iterator.\n * @returns - Style object or null.\n *\n * @example Parsing inline style to object:\n *\n * ```js\n * import parse from 'style-to-object';\n * parse('line-height: 42;'); // { 'line-height': '42' }\n * ```\n */\nexport default function StyleToObject(\n style: string,\n iterator?: Iterator,\n): StyleObject | null {\n let styleObject: StyleObject | null = null;\n\n if (!style || typeof style !== 'string') {\n return styleObject;\n }\n\n const declarations = parse(style);\n const hasIterator = typeof iterator === 'function';\n\n declarations.forEach((declaration) => {\n if (declaration.type !== 'declaration') {\n return;\n }\n\n const { property, value } = declaration;\n\n if (hasIterator) {\n iterator(property, value, declaration);\n } else if (value) {\n styleObject = styleObject ?? {};\n styleObject[property] = value;\n }\n });\n\n return styleObject;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BA,SAAwB,cACtB,OACA,UACoB;EACpB,IAAI,cAAkC;EAEtC,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;EAGT,MAAM,gBAAA,GAAA,oBAAA,QAAA,CAAqB,KAAK;EAChC,MAAM,cAAc,OAAO,aAAa;EAExC,aAAa,SAAS,gBAAgB;GACpC,IAAI,YAAY,SAAS,eACvB;GAGF,MAAM,EAAE,UAAU,UAAU;GAE5B,IAAI,aACF,SAAS,UAAU,OAAO,WAAW;QAChC,IAAI,OAAO;IAChB,cAAc,eAAe,CAAC;IAC9B,YAAY,YAAY;GAC1B;EACF,CAAC;EAED,OAAO;CACT"}
@@ -1,2 +1,2 @@
1
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).StyleToObject=t()}(this,(function(){"use strict";var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,e=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,i=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,u=/^[;\s]*/,c=/^\s+|\s+$/g,f="";function s(n){return n?n.replace(c,f):f}return function(c,a){let l=null;if(!c||"string"!=typeof c)return l;const p=function(c,a){if("string"!=typeof c)throw new TypeError("First argument must be a string");if(!c)return[];a=a||{};var l=1,p=1;function h(n){var e=n.match(t);e&&(l+=e.length);var r=n.lastIndexOf("\n");p=~r?n.length-r:p+n.length}function m(){var n={line:l,column:p};return function(t){return t.position=new v(n),g(),t}}function v(n){this.start=n,this.end={line:l,column:p},this.source=a.source}function y(n){var t=new Error(a.source+":"+l+":"+p+": "+n);if(t.reason=n,t.filename=a.source,t.line=l,t.column=p,t.source=c,!a.silent)throw t}function d(n){var t=n.exec(c);if(t){var e=t[0];return h(e),c=c.slice(e.length),t}}function g(){d(e)}function w(n){var t;for(n=n||[];t=A();)!1!==t&&n.push(t);return n}function A(){var n=m();if("/"==c.charAt(0)&&"*"==c.charAt(1)){for(var t=2;f!=c.charAt(t)&&("*"!=c.charAt(t)||"/"!=c.charAt(t+1));)++t;if(t+=2,f===c.charAt(t-1))return y("End of comment missing");var e=c.slice(2,t-2);return p+=2,h(e),c=c.slice(t),p+=2,n({type:"comment",comment:e})}}function b(){var t=m(),e=d(r);if(e){if(A(),!d(o))return y("property missing ':'");var c=d(i),a=t({type:"declaration",property:s(e[0].replace(n,f)),value:c?s(c[0].replace(n,f)):f});return d(u),a}}return v.prototype.content=c,g(),function(){var n,t=[];for(w(t);n=b();)!1!==n&&(t.push(n),w(t));return t}()}(c),h="function"==typeof a;return p.forEach((n=>{if("declaration"!==n.type)return;const{property:t,value:e}=n;h?a(t,e,n):e&&(l=l||{},l[t]=e)})),l}}));
2
- //# sourceMappingURL=style-to-object.min.js.map
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t(require("inline-style-parser")):typeof define==`function`&&define.amd?define([`inline-style-parser`],t):(e=typeof globalThis<`u`?globalThis:e||self,e.StyleToObject=t(e.inline_style_parser))})(this,function(e){var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e};e=((e,r,i)=>(i=e==null?{}:t(a(e)),s(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)))(e);function c(t,n){let r=null;if(!t||typeof t!=`string`)return r;let i=(0,e.default)(t),a=typeof n==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:t,value:i}=e;a?n(t,i,e):i&&(r??={},r[t]=i)}),r}return c});
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/esm/index.mjs","../src/index.ts"],"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 */\nfunction index (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 /**\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) ; 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\nexport { index as default };\n//# sourceMappingURL=index.mjs.map\n",null],"names":["COMMENT_REGEX","NEWLINE_REGEX","WHITESPACE_REGEX","PROPERTY_REGEX","COLON_REGEX","VALUE_REGEX","SEMICOLON_REGEX","TRIM_REGEX","EMPTY_STRING","trim","str","replace","style","iterator","styleObject","declarations","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","parse","hasIterator","forEach"],"mappings":"8OAEA,IAAIA,EAAgB,kCAEhBC,EAAgB,MAChBC,EAAmB,OAGnBC,EAAiB,yCACjBC,EAAc,QACdC,EAAc,uDACdC,EAAkB,UAGlBC,EAAa,aAMbC,EAAe,GA0OnB,SAASC,EAAKC,GACZ,OAAOA,EAAMA,EAAIC,QAAQJ,EAAYC,GAAgBA,CACvD,QCnOc,SACZI,EACAC,GAEA,IAAIC,EAAkC,KAEtC,IAAKF,GAA0B,iBAAVA,EACnB,OAAOE,EA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,EAAS6C,EAAUC,EAAOL,GACjBK,IACT7C,EAAcA,GAAe,CAAA,EAC7BA,EAAY4C,GAAYC,EAC1B,IAGK7C,CACT","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"style-to-object.min.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Declaration } from 'inline-style-parser';\nimport parse from 'inline-style-parser';\n\nexport { Declaration };\n\nexport type StyleObject = Record<string, string>;\n\ntype Iterator = (\n property: string,\n value: string,\n declaration: Declaration,\n) => void;\n\n/**\n * Parses inline style to object.\n *\n * @param style - Inline style.\n * @param iterator - Iterator.\n * @returns - Style object or null.\n *\n * @example Parsing inline style to object:\n *\n * ```js\n * import parse from 'style-to-object';\n * parse('line-height: 42;'); // { 'line-height': '42' }\n * ```\n */\nexport default function StyleToObject(\n style: string,\n iterator?: Iterator,\n): StyleObject | null {\n let styleObject: StyleObject | null = null;\n\n if (!style || typeof style !== 'string') {\n return styleObject;\n }\n\n const declarations = parse(style);\n const hasIterator = typeof iterator === 'function';\n\n declarations.forEach((declaration) => {\n if (declaration.type !== 'declaration') {\n return;\n }\n\n const { property, value } = declaration;\n\n if (hasIterator) {\n iterator(property, value, declaration);\n } else if (value) {\n styleObject = styleObject ?? {};\n styleObject[property] = value;\n }\n });\n\n return styleObject;\n}\n"],"mappings":"gwBA2BA,SAAwB,EACtB,EACA,EACoB,CACpB,IAAI,EAAkC,KAEtC,GAAI,CAAC,GAAS,OAAO,GAAU,SAC7B,OAAO,EAGT,IAAM,GAAA,EAAA,EAAA,QAAA,CAAqB,CAAK,EAC1B,EAAc,OAAO,GAAa,WAiBxC,OAfA,EAAa,QAAS,GAAgB,CACpC,GAAI,EAAY,OAAS,cACvB,OAGF,GAAM,CAAE,WAAU,SAAU,EAExB,EACF,EAAS,EAAU,EAAO,CAAW,EAC5B,IACT,IAA6B,CAAC,EAC9B,EAAY,GAAY,EAE5B,CAAC,EAEM,CACT"}
@@ -1,8 +1,7 @@
1
- import type { Declaration } from 'inline-style-parser';
2
- export { Declaration };
3
- export interface StyleObject {
4
- [name: string]: string;
5
- }
1
+ import { Declaration } from "inline-style-parser";
2
+
3
+ //#region src/index.d.ts
4
+ type StyleObject = Record<string, string>;
6
5
  type Iterator = (property: string, value: string, declaration: Declaration) => void;
7
6
  /**
8
7
  * Parses inline style to object.
@@ -18,5 +17,7 @@ type Iterator = (property: string, value: string, declaration: Declaration) => v
18
17
  * parse('line-height: 42;'); // { 'line-height': '42' }
19
18
  * ```
20
19
  */
21
- export default function StyleToObject(style: string, iterator?: Iterator): StyleObject | null;
22
- //# sourceMappingURL=index.d.ts.map
20
+ declare function StyleToObject(style: string, iterator?: Iterator): StyleObject | null;
21
+ //#endregion
22
+ export { type Declaration, StyleObject, StyleToObject as default };
23
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;KAKY,WAAA,GAAc,MAAM;AAAA,KAE3B,QAAA,IACH,QAAA,UACA,KAAA,UACA,WAAA,EAAa,WAAW;;;;AALM;AAAiB;;;;;;;;;AAKvB;iBAiBF,aAAA,CACtB,KAAA,UACA,QAAA,GAAW,QAAA,GACV,WAAW"}
package/esm/index.mjs CHANGED
@@ -1,41 +1,36 @@
1
- import parse from 'inline-style-parser';
2
-
1
+ import parse from "inline-style-parser";
2
+ //#region src/index.ts
3
3
  /**
4
- * Parses inline style to object.
5
- *
6
- * @param style - Inline style.
7
- * @param iterator - Iterator.
8
- * @returns - Style object or null.
9
- *
10
- * @example Parsing inline style to object:
11
- *
12
- * ```js
13
- * import parse from 'style-to-object';
14
- * parse('line-height: 42;'); // { 'line-height': '42' }
15
- * ```
16
- */
4
+ * Parses inline style to object.
5
+ *
6
+ * @param style - Inline style.
7
+ * @param iterator - Iterator.
8
+ * @returns - Style object or null.
9
+ *
10
+ * @example Parsing inline style to object:
11
+ *
12
+ * ```js
13
+ * import parse from 'style-to-object';
14
+ * parse('line-height: 42;'); // { 'line-height': '42' }
15
+ * ```
16
+ */
17
17
  function StyleToObject(style, iterator) {
18
- let styleObject = null;
19
- if (!style || typeof style !== 'string') {
20
- return styleObject;
21
- }
22
- const declarations = parse(style);
23
- const hasIterator = typeof iterator === 'function';
24
- declarations.forEach((declaration) => {
25
- if (declaration.type !== 'declaration') {
26
- return;
27
- }
28
- const { property, value } = declaration;
29
- if (hasIterator) {
30
- iterator(property, value, declaration);
31
- }
32
- else if (value) {
33
- styleObject = styleObject || {};
34
- styleObject[property] = value;
35
- }
36
- });
37
- return styleObject;
18
+ let styleObject = null;
19
+ if (!style || typeof style !== "string") return styleObject;
20
+ const declarations = parse(style);
21
+ const hasIterator = typeof iterator === "function";
22
+ declarations.forEach((declaration) => {
23
+ if (declaration.type !== "declaration") return;
24
+ const { property, value } = declaration;
25
+ if (hasIterator) iterator(property, value, declaration);
26
+ else if (value) {
27
+ styleObject = styleObject ?? {};
28
+ styleObject[property] = value;
29
+ }
30
+ });
31
+ return styleObject;
38
32
  }
39
-
33
+ //#endregion
40
34
  export { StyleToObject as default };
41
- //# sourceMappingURL=index.mjs.map
35
+
36
+ //# sourceMappingURL=index.mjs.map
package/esm/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAeA;;;;;;;;;;;;;AAaG;AACW,SAAU,aAAa,CACnC,KAAa,EACb,QAAmB,EAAA;IAEnB,IAAI,WAAW,GAAuB,IAAI;IAE1C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AACvC,QAAA,OAAO,WAAW;IACpB;AAEA,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC;AACjC,IAAA,MAAM,WAAW,GAAG,OAAO,QAAQ,KAAK,UAAU;AAElD,IAAA,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,KAAI;AACnC,QAAA,IAAI,WAAW,CAAC,IAAI,KAAK,aAAa,EAAE;YACtC;QACF;AAEA,QAAA,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,WAAW;QAEvC,IAAI,WAAW,EAAE;AACf,YAAA,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC;QACxC;aAAO,IAAI,KAAK,EAAE;AAChB,YAAA,WAAW,GAAG,WAAW,IAAI,EAAE;AAC/B,YAAA,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK;QAC/B;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,WAAW;AACpB;;;;"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Declaration } from 'inline-style-parser';\nimport parse from 'inline-style-parser';\n\nexport { Declaration };\n\nexport type StyleObject = Record<string, string>;\n\ntype Iterator = (\n property: string,\n value: string,\n declaration: Declaration,\n) => void;\n\n/**\n * Parses inline style to object.\n *\n * @param style - Inline style.\n * @param iterator - Iterator.\n * @returns - Style object or null.\n *\n * @example Parsing inline style to object:\n *\n * ```js\n * import parse from 'style-to-object';\n * parse('line-height: 42;'); // { 'line-height': '42' }\n * ```\n */\nexport default function StyleToObject(\n style: string,\n iterator?: Iterator,\n): StyleObject | null {\n let styleObject: StyleObject | null = null;\n\n if (!style || typeof style !== 'string') {\n return styleObject;\n }\n\n const declarations = parse(style);\n const hasIterator = typeof iterator === 'function';\n\n declarations.forEach((declaration) => {\n if (declaration.type !== 'declaration') {\n return;\n }\n\n const { property, value } = declaration;\n\n if (hasIterator) {\n iterator(property, value, declaration);\n } else if (value) {\n styleObject = styleObject ?? {};\n styleObject[property] = value;\n }\n });\n\n return styleObject;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,SAAwB,cACtB,OACA,UACoB;CACpB,IAAI,cAAkC;CAEtC,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;CAGT,MAAM,eAAe,MAAM,KAAK;CAChC,MAAM,cAAc,OAAO,aAAa;CAExC,aAAa,SAAS,gBAAgB;EACpC,IAAI,YAAY,SAAS,eACvB;EAGF,MAAM,EAAE,UAAU,UAAU;EAE5B,IAAI,aACF,SAAS,UAAU,OAAO,WAAW;OAChC,IAAI,OAAO;GAChB,cAAc,eAAe,CAAC;GAC9B,YAAY,YAAY;EAC1B;CACF,CAAC;CAED,OAAO;AACT"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "style-to-object",
3
- "version": "1.0.13",
3
+ "version": "2.0.0",
4
4
  "description": "Parse CSS inline style to JavaScript object.",
5
5
  "author": "Mark <mark@remarkablemark.org>",
6
6
  "main": "./cjs/index.js",
7
7
  "module": "./esm/index.mjs",
8
- "types": "./esm/index.d.ts",
8
+ "types": "./cjs/index.d.ts",
9
9
  "exports": {
10
10
  "import": {
11
- "types": "./esm/index.d.ts",
11
+ "types": "./esm/index.d.mts",
12
12
  "default": "./esm/index.mjs"
13
13
  },
14
14
  "require": {
@@ -17,17 +17,14 @@
17
17
  }
18
18
  },
19
19
  "scripts": {
20
- "build": "run-s build:*",
21
- "build:cjs": "tsc --project tsconfig.cjs.json",
22
- "build:esm": "tsc --project tsconfig.json",
23
- "build:umd": "rollup --config --failAfterWarnings",
20
+ "build": "tsdown",
24
21
  "clean": "rm -rf cjs coverage dist esm",
25
22
  "lint": "eslint .",
26
23
  "lint:fix": "npm run lint -- --fix",
27
24
  "lint:package": "publint",
28
25
  "lint:tsc": "tsc --noEmit",
29
26
  "prepare": "husky",
30
- "prepublishOnly": "run-s lint lint:tsc test clean build",
27
+ "prepublishOnly": "run-s clean build lint lint:tsc test",
31
28
  "test": "jest",
32
29
  "test:ci": "CI=true jest --ci --colors --coverage",
33
30
  "test:esm": "npm run build && node --test **/*.test.mjs",
@@ -50,37 +47,29 @@
50
47
  "pojo"
51
48
  ],
52
49
  "dependencies": {
53
- "inline-style-parser": "0.2.6"
50
+ "inline-style-parser": "0.2.7"
54
51
  },
55
52
  "devDependencies": {
56
- "@commitlint/cli": "20.1.0",
57
- "@commitlint/config-conventional": "20.0.0",
58
- "@eslint/compat": "2.0.0",
59
- "@eslint/eslintrc": "3.3.1",
60
- "@eslint/js": "9.39.1",
61
- "@rollup/plugin-commonjs": "29.0.0",
62
- "@rollup/plugin-node-resolve": "16.0.3",
63
- "@rollup/plugin-terser": "0.4.4",
64
- "@rollup/plugin-typescript": "12.3.0",
53
+ "@commitlint/cli": "21.0.2",
54
+ "@commitlint/config-conventional": "21.0.2",
55
+ "@eslint/js": "10.0.1",
56
+ "tsdown": "0.22.2",
65
57
  "@types/jest": "30.0.0",
66
- "@types/node": "24.10.1",
67
- "@typescript-eslint/eslint-plugin": "8.46.4",
68
- "@typescript-eslint/parser": "8.46.4",
69
- "eslint": "9.39.1",
70
- "eslint-plugin-prettier": "5.5.4",
71
- "eslint-plugin-simple-import-sort": "12.1.1",
72
- "globals": "16.5.0",
58
+ "@types/node": "25.9.3",
59
+ "eslint": "10.5.0",
60
+ "eslint-plugin-prettier": "5.5.6",
61
+ "eslint-plugin-simple-import-sort": "13.0.0",
62
+ "globals": "17.6.0",
73
63
  "husky": "9.1.7",
74
- "jest": "30.2.0",
75
- "lint-staged": "16.2.6",
64
+ "jest": "30.4.2",
65
+ "lint-staged": "17.0.7",
76
66
  "npm-run-all": "4.1.5",
77
- "prettier": "3.6.2",
78
- "publint": "0.3.15",
79
- "rollup": "4.53.2",
80
- "ts-jest": "29.4.5",
67
+ "prettier": "3.8.4",
68
+ "publint": "0.3.21",
69
+ "ts-jest": "29.4.11",
81
70
  "ts-node": "10.9.2",
82
- "tslib": "2.8.1",
83
- "typescript": "5.9.3"
71
+ "typescript": "6.0.3",
72
+ "typescript-eslint": "8.61.0"
84
73
  },
85
74
  "files": [
86
75
  "/cjs",
package/src/index.ts CHANGED
@@ -3,9 +3,7 @@ import parse from 'inline-style-parser';
3
3
 
4
4
  export { Declaration };
5
5
 
6
- export interface StyleObject {
7
- [name: string]: string;
8
- }
6
+ export type StyleObject = Record<string, string>;
9
7
 
10
8
  type Iterator = (
11
9
  property: string,
@@ -50,7 +48,7 @@ export default function StyleToObject(
50
48
  if (hasIterator) {
51
49
  iterator(property, value, declaration);
52
50
  } else if (value) {
53
- styleObject = styleObject || {};
51
+ styleObject = styleObject ?? {};
54
52
  styleObject[property] = value;
55
53
  }
56
54
  });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,MAAM,WAAW,WAAW;IAC1B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,KAAK,QAAQ,GAAG,CACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,KACrB,IAAI,CAAC;AAEV;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,QAAQ,GAClB,WAAW,GAAG,IAAI,CA0BpB"}
package/esm/index.js DELETED
@@ -1,38 +0,0 @@
1
- import parse from 'inline-style-parser';
2
- /**
3
- * Parses inline style to object.
4
- *
5
- * @param style - Inline style.
6
- * @param iterator - Iterator.
7
- * @returns - Style object or null.
8
- *
9
- * @example Parsing inline style to object:
10
- *
11
- * ```js
12
- * import parse from 'style-to-object';
13
- * parse('line-height: 42;'); // { 'line-height': '42' }
14
- * ```
15
- */
16
- export default function StyleToObject(style, iterator) {
17
- let styleObject = null;
18
- if (!style || typeof style !== 'string') {
19
- return styleObject;
20
- }
21
- const declarations = parse(style);
22
- const hasIterator = typeof iterator === 'function';
23
- declarations.forEach((declaration) => {
24
- if (declaration.type !== 'declaration') {
25
- return;
26
- }
27
- const { property, value } = declaration;
28
- if (hasIterator) {
29
- iterator(property, value, declaration);
30
- }
31
- else if (value) {
32
- styleObject = styleObject || {};
33
- styleObject[property] = value;
34
- }
35
- });
36
- return styleObject;
37
- }
38
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,qBAAqB,CAAC;AAcxC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,KAAa,EACb,QAAmB;IAEnB,IAAI,WAAW,GAAuB,IAAI,CAAC;IAE3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,WAAW,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC;IAEnD,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QACnC,IAAI,WAAW,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC;QAExC,IAAI,WAAW,EAAE,CAAC;YAChB,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QACzC,CAAC;aAAM,IAAI,KAAK,EAAE,CAAC;YACjB,WAAW,GAAG,WAAW,IAAI,EAAE,CAAC;YAChC,WAAW,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;QAChC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC"}