🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
43
node_modules/style-to-object/index.js
generated
vendored
Normal file
43
node_modules/style-to-object/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
var parse = require('inline-style-parser');
|
||||
|
||||
/**
|
||||
* Parses inline style to object.
|
||||
*
|
||||
* @example
|
||||
* // returns { 'line-height': '42' }
|
||||
* StyleToObject('line-height: 42;');
|
||||
*
|
||||
* @param {String} style - The inline style.
|
||||
* @param {Function} [iterator] - The iterator function.
|
||||
* @return {null|Object}
|
||||
*/
|
||||
function StyleToObject(style, iterator) {
|
||||
var output = null;
|
||||
if (!style || typeof style !== 'string') {
|
||||
return output;
|
||||
}
|
||||
|
||||
var declaration;
|
||||
var declarations = parse(style);
|
||||
var hasIterator = typeof iterator === 'function';
|
||||
var property;
|
||||
var value;
|
||||
|
||||
for (var i = 0, len = declarations.length; i < len; i++) {
|
||||
declaration = declarations[i];
|
||||
property = declaration.property;
|
||||
value = declaration.value;
|
||||
|
||||
if (hasIterator) {
|
||||
iterator(property, value, declaration);
|
||||
} else if (value) {
|
||||
output || (output = {});
|
||||
output[property] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = StyleToObject;
|
||||
module.exports.default = StyleToObject; // ESM support
|
||||
Loading…
Add table
Add a link
Reference in a new issue