Gathering detailed insights and metrics for style-to-object
Gathering detailed insights and metrics for style-to-object
Gathering detailed insights and metrics for style-to-object
Gathering detailed insights and metrics for style-to-object
📝 Parse CSS inline style to JavaScript object.
npm install style-to-object
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
54 Stars
685 Commits
3 Forks
1 Watching
1 Branches
4 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
TypeScript (71.82%)
JavaScript (28.18%)
Cumulative downloads
Total Downloads
Last day
-1.7%
1,490,042
Compared to previous day
Last week
4%
7,827,166
Compared to previous week
Last month
11.9%
32,807,303
Compared to previous month
Last year
15.4%
345,597,294
Compared to previous year
1
25
Parse CSS inline style to JavaScript object:
1import parse from 'style-to-object'; 2 3parse('color: #C0FFEE; background: #BADA55;');
Output:
1{ color: '#C0FFEE', background: '#BADA55' }
NPM:
1npm install style-to-object --save
Yarn:
1yarn add style-to-object
CDN:
1<script src="https://unpkg.com/style-to-object@latest/dist/style-to-object.min.js"></script> 2<script> 3 window.StyleToObject(/* string */); 4</script>
Import with ES Modules:
1import parse from 'style-to-object';
Require with CommonJS:
1const parse = require('style-to-object').default;
Parse single declaration:
1parse('line-height: 42');
Output:
1{ 'line-height': '42' }
Parse multiple declarations:
1parse(` 2 border-color: #ACE; 3 z-index: 1337; 4`);
Output:
1{ 'border-color': '#ACE', 'z-index': '1337' }
Parse unknown declarations:
1parse('answer: 42;');
Output:
1{ 'answer': '42' }
Invalid declarations/arguments:
1parse(` 2 top: ; 3 right: 1em; 4`); // { right: '1em' } 5 6parse(); // null 7parse(null); // null 8parse(1); // null 9parse(true); // null 10parse('top:'); // null 11parse(':12px'); // null 12parse(':'); // null 13parse(';'); // null 14 15parse('top'); // throws Error 16parse('/*'); // throws Error
If the 2nd argument is a function, then the parser will return null
:
1parse('color: #f00', () => {}); // null
But the function will iterate through each declaration:
1parse('color: #f00', (name, value, declaration) => { 2 console.log(name); // 'color' 3 console.log(value); // '#f00' 4 console.log(declaration); // { type: 'declaration', property: 'color', value: '#f00' } 5});
This makes it easy to customize the output:
1const style = ` 2 color: red; 3 background: blue; 4`; 5const output = []; 6 7function iterator(name, value) { 8 output.push([name, value]); 9} 10 11parse(style, iterator); 12console.log(output); // [['color', 'red'], ['background', 'blue']]
Migrated to TypeScript. Iterator excludes Comment
. CommonJS requires the .default
key:
1const parse = require('style-to-object').default;
Release and publish are automated by Release Please.
No vulnerabilities found.
Reason
30 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool is run on all commits
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More