{"name":"style-to-object","version":"2.0.1","keywords":["style-to-object","inline","style","parser","css","object","pojo"],"author":{"name":"Mark","email":"mark@remarkablemark.org"},"license":"MIT","_id":"style-to-object@2.0.1","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":"3875570c417375833a7021a89ac9f6306d90bfe0","tarball":"http://registry-npm.ywwl.com/style-to-object/download/style-to-object-2.0.1.tgz","fileCount":16,"integrity":"sha512-NOTjzoUkWfIkNQ9C9t1cLJJyt5wDEM2q8rfXhUy03HoE/Uls9JL+Z4oCgZRJC2VKMt123wFaFYRRs1b5PoqwBA==","signatures":[{"sig":"MEQCIDSIBFTbvYY/oMGtqVCYi6pOKXsdVRZbqrCgn2z1yIRDAiAy6gRvj7+4iLsvfNifjXKUTA/bzJnFGgtkkM8gKGIJGA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/style-to-object@2.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":43275,"size":10582,"noattachment":false,"key":"/style-to-object/-/style-to-object-2.0.1.tgz"},"main":"./cjs/index.js","types":"./cjs/index.d.ts","module":"./esm/index.mjs","exports":{"import":{"types":"./esm/index.d.mts","default":"./esm/index.mjs"},"require":{"types":"./cjs/index.d.ts","default":"./cjs/index.js"}},"gitHead":"7340bf3c49f748a2244241df53b7726de67ee870","scripts":{"lint":"eslint .","test":"jest","build":"tsdown","clean":"rm -rf cjs coverage dist esm","prepare":"husky","test:ci":"CI=true jest --ci --colors --coverage","lint:fix":"npm run lint -- --fix","lint:tsc":"tsc --project tsconfig.test.json","test:esm":"npm run build && node --test **/*.test.mjs","test:watch":"npm run test -- --watch","lint:package":"publint","prepublishOnly":"run-s clean build lint lint:tsc test"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:af9d056a-8a05-4e9d-92ba-8e56a5c48c5c"}},"repository":{"url":"git+https://github.com/remarkablemark/style-to-object.git","type":"git"},"_npmVersion":"11.16.0","description":"Parse CSS inline style to JavaScript object.","directories":{},"_nodeVersion":"24.18.0","dependencies":{"inline-style-parser":"0.2.8"},"_hasShrinkwrap":false,"devDependencies":{"jest":"30.4.2","husky":"9.1.7","eslint":"10.6.0","tsdown":"0.22.3","globals":"17.7.0","publint":"0.3.21","ts-jest":"29.4.11","ts-node":"10.9.2","prettier":"3.9.4","@eslint/js":"10.0.1","typescript":"6.0.3","@types/jest":"30.0.0","@types/node":"26.1.0","lint-staged":"17.0.8","npm-run-all":"4.1.5","@commitlint/cli":"21.2.0","typescript-eslint":"8.62.1","eslint-plugin-prettier":"5.5.6","@commitlint/config-conventional":"21.2.0","eslint-plugin-simple-import-sort":"13.0.0"},"_npmOperationalInternal":{"tmp":"tmp/style-to-object_2.0.1_1783180031092_0.3306946825322681","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":1783180031227,"_cnpm_publish_time":1783180031227,"dist-tags":{"latest":"2.0.2"}}