forked from rrweb-io/rrweb
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(repo): Format files with prettier (#19)
- Loading branch information
Showing
13 changed files
with
225 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
export function parseCSSText(cssText: string): Record<string, string> { | ||
const res: Record<string, string> = {}; | ||
const listDelimiter = /;(?![^(]*\))/g; | ||
const propertyDelimiter = /:(.+)/; | ||
cssText.split(listDelimiter).forEach(function (item) { | ||
if (item) { | ||
const tmp = item.split(propertyDelimiter); | ||
tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim()); | ||
} | ||
}); | ||
return res; | ||
const res: Record<string, string> = {}; | ||
const listDelimiter = /;(?![^(]*\))/g; | ||
const propertyDelimiter = /:(.+)/; | ||
cssText.split(listDelimiter).forEach(function (item) { | ||
if (item) { | ||
const tmp = item.split(propertyDelimiter); | ||
tmp.length > 1 && (res[camelize(tmp[0].trim())] = tmp[1].trim()); | ||
} | ||
}); | ||
return res; | ||
} | ||
|
||
export function toCSSText(style: Record<string, string>): string { | ||
const properties = []; | ||
for (let name in style) { | ||
const value = style[name]; | ||
if (typeof value !== 'string') continue; | ||
const normalizedName = hyphenate(name); | ||
properties.push(`${normalizedName}:${value};`); | ||
} | ||
|
||
export function toCSSText(style: Record<string, string>): string { | ||
const properties = []; | ||
for (let name in style) { | ||
const value = style[name]; | ||
if (typeof value !== 'string') continue; | ||
const normalizedName = hyphenate(name); | ||
properties.push(`${normalizedName}:${value};`); | ||
} | ||
return properties.join(' '); | ||
} | ||
|
||
/** | ||
* Camelize a hyphen-delimited string. | ||
*/ | ||
const camelizeRE = /-(\w)/g; | ||
export const camelize = (str: string): string => { | ||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); | ||
}; | ||
|
||
/** | ||
* Hyphenate a camelCase string. | ||
*/ | ||
const hyphenateRE = /\B([A-Z])/g; | ||
export const hyphenate = (str: string): string => { | ||
return str.replace(hyphenateRE, '-$1').toLowerCase(); | ||
}; | ||
|
||
return properties.join(' '); | ||
} | ||
|
||
/** | ||
* Camelize a hyphen-delimited string. | ||
*/ | ||
const camelizeRE = /-(\w)/g; | ||
export const camelize = (str: string): string => { | ||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); | ||
}; | ||
|
||
/** | ||
* Hyphenate a camelCase string. | ||
*/ | ||
const hyphenateRE = /\B([A-Z])/g; | ||
export const hyphenate = (str: string): string => { | ||
return str.replace(hyphenateRE, '-$1').toLowerCase(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.