AK-21/Graphite-Industrial-Intelligence
0
1# inline-style-parser2 3[](https://nodei.co/npm/inline-style-parser/)4 5[](https://www.npmjs.com/package/inline-style-parser)6[](https://bundlephobia.com/package/inline-style-parser)7[](https://github.com/remarkablemark/inline-style-parser/actions/workflows/build.yml)8[](https://codecov.io/gh/remarkablemark/inline-style-parser)9[](https://www.npmjs.com/package/inline-style-parser)10 11Inline style parser copied from [`css/lib/parse/index.js`](https://github.com/reworkcss/css/blob/v2.2.4/lib/parse/index.js):12 13```14InlineStyleParser(string)15```16 17Example:18 19```js20const parse = require('inline-style-parser');21 22parse('color: #BADA55;');23```24 25Output:26 27```js28[ { type: 'declaration',29 property: 'color',30 value: '#BADA55',31 position: Position { start: [Object], end: [Object], source: undefined } } ]32```33 34[JSFiddle](https://jsfiddle.net/remarkablemark/hcxbpwq8/) | [Examples](https://github.com/remarkablemark/inline-style-parser/tree/master/examples)35 36## Installation37 38[NPM](https://www.npmjs.com/package/inline-style-parser):39 40```sh41npm install inline-style-parser --save42```43 44[Yarn](https://yarnpkg.com/package/inline-style-parser):45 46```sh47yarn add inline-style-parser48```49 50[CDN](https://unpkg.com/inline-style-parser/):51 52```html53<script src="https://unpkg.com/inline-style-parser@latest/dist/inline-style-parser.min.js"></script>54<script>55 window.InlineStyleParser(/* string */);56</script>57```58 59## Usage60 61Import with ES Modules:62 63```js64import parse from 'inline-style-parser';65```66 67Or require with CommonJS:68 69```js70const parse = require('inline-style-parser');71```72 73Parse single declaration:74 75```js76parse('left: 0');77```78 79Output:80 81```js82[83 {84 type: 'declaration',85 property: 'left',86 value: '0',87 position: {88 start: { line: 1, column: 1 },89 end: { line: 1, column: 8 },90 source: undefined91 }92 }93]94```95 96Parse multiple declarations:97 98```js99parse('left: 0; right: 100px;');100```101 102Output:103 104```js105[106 {107 type: 'declaration',108 property: 'left',109 value: '0',110 position: {111 start: { line: 1, column: 1 },112 end: { line: 1, column: 8 },113 source: undefined114 }115 },116 {117 type: 'declaration',118 property: 'right',119 value: '100px',120 position: {121 start: { line: 1, column: 10 },122 end: { line: 1, column: 22 },123 source: undefined124 }125 }126]127```128 129Parse declaration with missing value:130 131```js132parse('top:');133```134 135Output:136 137```js138[139 {140 type: 'declaration',141 property: 'top',142 value: '',143 position: {144 start: { line: 1, column: 1 },145 end: { line: 1, column: 5 },146 source: undefined147 }148 }149]150```151 152Parse unknown declaration:153 154```js155parse('answer: 42;');156```157 158Output:159 160```js161[162 {163 type: 'declaration',164 property: 'answer',165 value: '42',166 position: {167 start: { line: 1, column: 1 },168 end: { line: 1, column: 11 },169 source: undefined170 }171 }172]173```174 175Invalid declarations:176 177```js178parse(''); // []179parse(); // throws TypeError180parse(1); // throws TypeError181parse('width'); // throws Error182parse('/*'); // throws Error183```184 185## Testing186 187Run tests:188 189```sh190npm test191```192 193Run tests in watch mode:194 195```sh196npm run test:watch197```198 199Run tests with coverage:200 201```sh202npm run test:coverage203```204 205Run tests in CI mode:206 207```sh208npm run test:ci209```210 211Lint files:212 213```sh214npm run lint215```216 217Fix lint errors:218 219```sh220npm run lint:fix221```222 223## Release224 225Release and publish are automated by [Release Please](https://github.com/googleapis/release-please).226 227## License228 229[MIT](https://github.com/remarkablemark/inline-style-parser/blob/master/LICENSE). See the [license](https://github.com/reworkcss/css/blob/v2.2.4/LICENSE) from the original project.230 