Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { camelCase } from './camelCase'
|
||||
|
||||
type Style = string | Partial<CSSStyleDeclaration>
|
||||
|
||||
/**
|
||||
* Converts a CSS Style string
|
||||
* @param {string | Partial<CSSStyleDeclaration>} style A string to convert, or object to return
|
||||
* @returns {Partial<CSSStyleDeclaration>} a partial CSSStyleDeclaration
|
||||
*/
|
||||
export const parseStyle = (style: Style): Partial<CSSStyleDeclaration> | undefined => {
|
||||
switch (typeof style) {
|
||||
case 'string':
|
||||
return style.split(';').filter(r => r)
|
||||
.reduce((map, rule) => {
|
||||
const name = rule.slice(0, rule.indexOf(':')).trim()
|
||||
const value = rule.slice(rule.indexOf(':') + 1).trim()
|
||||
|
||||
return {
|
||||
...map,
|
||||
[camelCase(name)]: value,
|
||||
}
|
||||
}, {})
|
||||
case 'object':
|
||||
return style
|
||||
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user