{"name":"style-to-object","version":"1.0.9","keywords":["style-to-object","inline","style","parser","css","object","pojo"],"author":{"name":"Mark","email":"mark@remarkablemark.org"},"license":"MIT","_id":"style-to-object@1.0.9","maintainers":[{"name":"remarkablemark","email":"mark@remarkablemark.org"}],"homepage":"https://github.com/remarkablemark/style-to-object#readme","bugs":{"url":"https://github.com/remarkablemark/style-to-object/issues"},"dist":{"shasum":"35c65b713f4a6dba22d3d0c61435f965423653f0","tarball":"http://registry-npm.ywwl.com/style-to-object/download/style-to-object-1.0.9.tgz","fileCount":14,"integrity":"sha512-G4qppLgKu/k6FwRpHiGiKPaPTFcG3g4wNVX/Qsfu+RqQM30E7Tyu/TEgxcL9PNLF5pdRLwQdE3YKKf+KF2Dzlw==","signatures":[{"sig":"MEUCIQC/SD4LxD438eTMAx1rzXtJjjpsPXQlhcPDYdBpyjyDVgIgFOgKFHRjKcMcNmvW85lxEqHKLyZfVJlH69TZqSKbPOI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/style-to-object@1.0.9","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":41917,"size":11480,"noattachment":false,"key":"/style-to-object/-/style-to-object-1.0.9.tgz"},"main":"./cjs/index.js","types":"./cjs/index.d.ts","module":"./esm/index.mjs","exports":{"import":"./esm/index.mjs","require":"./cjs/index.js"},"gitHead":"36a7d48e2bd9d85a5e43e823d1db5c67557a9586","scripts":{"lint":"eslint .","test":"jest","build":"run-s build:*","clean":"rm -rf cjs coverage dist","prepare":"husky","test:ci":"CI=true jest --ci --colors --coverage","lint:fix":"npm run lint -- --fix","lint:tsc":"tsc --noEmit","test:esm":"npm run build:cjs && node --test __tests__","build:cjs":"tsc","build:esm":"awk '!/sourceMappingURL/' cjs/index.d.ts > esm/index.d.mts","build:umd":"rollup --config --failAfterWarnings","test:watch":"npm run test -- --watch","prepublishOnly":"run-s lint lint:tsc test clean build"},"_npmUser":{"name":"remarkablemark","email":"mark@remarkablemark.org"},"repository":{"url":"git+https://github.com/remarkablemark/style-to-object.git","type":"git"},"_npmVersion":"10.8.2","description":"Parse CSS inline style to JavaScript object.","directories":{},"_nodeVersion":"20.19.2","dependencies":{"inline-style-parser":"0.2.4"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.7.0","husky":"9.1.7","eslint":"9.28.0","rollup":"4.42.0","globals":"16.2.0","ts-jest":"29.3.4","ts-node":"10.9.2","prettier":"3.5.3","@eslint/js":"9.28.0","typescript":"5.8.3","@types/jest":"29.5.14","@types/node":"22.15.30","lint-staged":"16.1.0","npm-run-all":"4.1.5","@eslint/compat":"1.2.9","@commitlint/cli":"19.8.1","@eslint/eslintrc":"3.3.1","@rollup/plugin-terser":"0.4.4","eslint-plugin-prettier":"5.4.1","@rollup/plugin-commonjs":"28.0.3","@rollup/plugin-typescript":"12.1.2","@typescript-eslint/parser":"8.33.1","@rollup/plugin-node-resolve":"16.0.1","@commitlint/config-conventional":"19.8.1","@typescript-eslint/eslint-plugin":"8.33.1","eslint-plugin-simple-import-sort":"12.1.1"},"_npmOperationalInternal":{"tmp":"tmp/style-to-object_1.0.9_1749230107191_0.4631695129825104","host":"s3://npm-registry-packages-npm-production"},"readme":"# style-to-object\n\n[![NPM](https://nodei.co/npm/style-to-object.svg)](https://b.remarkabl.org/style-to-object)\n\n[![NPM version](https://img.shields.io/npm/v/style-to-object)](https://www.npmjs.com/package/style-to-object)\n[![NPM bundle size](https://img.shields.io/bundlephobia/minzip/style-to-object)](https://bundlephobia.com/package/style-to-object)\n[![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)\n[![codecov](https://codecov.io/gh/remarkablemark/style-to-object/branch/master/graph/badge.svg?token=XWxph9dpa4)](https://codecov.io/gh/remarkablemark/style-to-object)\n[![NPM downloads](https://img.shields.io/npm/dm/style-to-object)](https://www.npmjs.com/package/style-to-object)\n\nParse CSS inline style to JavaScript object:\n\n```js\nimport parse from 'style-to-object';\n\nparse('color: #C0FFEE; background: #BADA55;');\n```\n\nOutput:\n\n```js\n{ color: '#C0FFEE', background: '#BADA55' }\n```\n\n[JSFiddle](https://jsfiddle.net/remarkablemark/ykz2meot/) | [Examples](https://github.com/remarkablemark/style-to-object/tree/master/examples)\n\n## Installation\n\n[NPM](https://www.npmjs.com/package/style-to-object):\n\n```sh\nnpm install style-to-object --save\n```\n\n[Yarn](https://yarn.fyi/style-to-object):\n\n```sh\nyarn add style-to-object\n```\n\n[CDN](https://unpkg.com/style-to-object/):\n\n```html\n<script src=\"https://unpkg.com/style-to-object@latest/dist/style-to-object.min.js\"></script>\n<script>\n  window.StyleToObject(/* string */);\n</script>\n```\n\n## Usage\n\nImport with ES Modules:\n\n```js\nimport parse from 'style-to-object';\n```\n\nRequire with CommonJS:\n\n```js\nconst parse = require('style-to-object').default;\n```\n\nParse single declaration:\n\n```js\nparse('line-height: 42');\n```\n\nOutput:\n\n```js\n{ 'line-height': '42' }\n```\n\nParse multiple declarations:\n\n```js\nparse(`\n  border-color: #ACE;\n  z-index: 1337;\n`);\n```\n\nOutput:\n\n```js\n{ 'border-color': '#ACE', 'z-index': '1337' }\n```\n\nParse unknown declarations:\n\n```js\nparse('answer: 42;');\n```\n\nOutput:\n\n```js\n{ 'answer': '42' }\n```\n\nInvalid declarations/arguments:\n\n<!-- prettier-ignore-start -->\n\n```js\nparse(`\n  top: ;\n  right: 1em;\n`); // { right: '1em' }\n\nparse();        // null\nparse(null);    // null\nparse(1);       // null\nparse(true);    // null\nparse('top:');  // null\nparse(':12px'); // null\nparse(':');     // null\nparse(';');     // null\n\nparse('top'); // throws Error\nparse('/*');  // throws Error\n```\n\n<!-- prettier-ignore-end -->\n\n### Iterator\n\nIf the 2nd argument is a function, then the parser will return `null`:\n\n```js\nparse('color: #f00', () => {}); // null\n```\n\nBut the function will iterate through each declaration:\n\n<!-- prettier-ignore-start -->\n\n```js\nparse('color: #f00', (name, value, declaration) => {\n  console.log(name);        // 'color'\n  console.log(value);       // '#f00'\n  console.log(declaration); // { type: 'declaration', property: 'color', value: '#f00' }\n});\n```\n\n<!-- prettier-ignore-end -->\n\nThis makes it easy to customize the output:\n\n```js\nconst style = `\n  color: red;\n  background: blue;\n`;\nconst output = [];\n\nfunction iterator(name, value) {\n  output.push([name, value]);\n}\n\nparse(style, iterator);\nconsole.log(output); // [['color', 'red'], ['background', 'blue']]\n```\n\n## Migration\n\n### v2\n\nChanged build target from `es5` to `es6`.\n\n### v1\n\nMigrated to TypeScript. Iterator excludes `Comment`. CommonJS requires the `.default` key:\n\n```js\nconst parse = require('style-to-object').default;\n```\n\n## Release\n\nRelease and publish are automated by [Release Please](https://github.com/googleapis/release-please).\n\n## Special Thanks\n\n- [inline-style-parser](https://github.com/remarkablemark/inline-style-parser)\n- [Contributors](https://github.com/remarkablemark/style-to-object/graphs/contributors)\n\n## License\n\n[MIT](https://github.com/remarkablemark/style-to-object/blob/master/LICENSE)\n","publish_time":1749230107389,"_cnpm_publish_time":1749230107389,"dist-tags":{"latest":"2.0.2"}}