Skip to content

improve object iteration #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/assignStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ export default function assignStyle(
for (let i = 0, len = extendingStyles.length; i < len; ++i) {
const style = extendingStyles[i]

for (const property in style) {
const keys = Object.keys(style)
for (let j = 0, len2 = keys.length; j < len2; j++) {
const property = keys[j]
const value = style[property]
const baseValue = base[property]

if (baseValue && value) {
if (Array.isArray(baseValue)) {
base[property] = filterUniqueArray(baseValue.concat(value))
// eslint-disable-next-line no-continue
continue
}

if (Array.isArray(value)) {
base[property] = filterUniqueArray([baseValue, ...value])
// eslint-disable-next-line no-continue
continue
}

if (typeof value === 'object') {
base[property] = assignStyle({}, baseValue as StyleObject, value)
// eslint-disable-next-line no-continue
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/camelCaseProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type CacheObject = {
[key: string]: string
}

const CSS_VARIABLE = /^--/;
const CSS_VARIABLE = /^--/
const DASH = /-([a-z])/g
const MS = /^Ms/g
const cache: CacheObject = {}
Expand Down
20 changes: 11 additions & 9 deletions modules/cssifyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ export type StyleObject = {
export default function cssifyObject(style: StyleObject) {
let css = ''

for (const property in style) {
const keys = Object.keys(style)
for (let i = 0, len = keys.length; i < len; i++) {
const property = keys[i]
const value = style[property]
if (typeof value !== 'string' && typeof value !== 'number') {
continue
}
// do nothing
} else {
// prevents the semicolon after
// the last rule declaration
if (css) {
css += ';'
}

// prevents the semicolon after
// the last rule declaration
if (css) {
css += ';'
css += cssifyDeclaration(property, value)
}

css += cssifyDeclaration(property, value)
}

return css
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.2",
"jest": "^25.2.6",
"jest": "^29.7.0",
"prettier": "^1.7.4",
"rimraf": "^2.6.1",
"typescript": "^3.8.3"
Expand Down
Loading