• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

forsigner / fower / #33

pending completion
#33

push

travis-pro

forsigner
feat: create fower-plugin-grid

457 of 624 branches covered (73.24%)

Branch coverage included in aggregate %.

14 of 14 new or added lines in 2 files covered. (100.0%)

1589 of 1697 relevant lines covered (93.64%)

12.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.23
/packages/fower-plugin-flexbox/src/index.ts
1
import { Atom } from '@fower/core'
2
import { FowerPlugin } from '@fower/core'
3
import { kebab } from '@fower/utils'
1✔
4

5
export const flexMaps: Record<string, string> = {
1✔
6
  auto: '1 1 auto',
7
  initial: '0 1 auto',
8
  none: 'none',
9
}
10

11
const flexReg = /^flex(Auto|Initial|None)$/i
1✔
12
const wrapReg = /^flex(Wrap(Reverse)?|Nowrap)$/i
1✔
13

14
const isFlexProps = (key: string) => /^order$|^flex(Grow|Shrink|Basis|Wrap)?$/i.test(key)
13✔
15

16
export function isMatch(key: string) {
1✔
17
  return isFlexProps(key) || flexReg.test(key) || wrapReg.test(key)
12✔
18
}
19

20
export function toStyle(atom: Atom) {
1✔
21
  const { key, value } = atom
4✔
22
  const style: any = {}
4✔
23

24
  if (key === 'flex' && /^\d+/.test(value)) {
4✔
25
    return { flex: Number(value) }
2✔
26
  }
27

28
  if (wrapReg.test(key) && atom.isTruePropValue) {
2✔
29
    const postfix = key.replace(/^flex/, '')
1✔
30
    style.flexWrap = kebab(postfix).toLowerCase()
1✔
31
    return style
1✔
32
  }
33

34
  if (isFlexProps(key)) {
1!
35
    const shouldKebab = /^flex(Grow|Shrink|Basis|Wrap)$/i.test(key)
×
36
    const newKey = shouldKebab ? kebab(key.replace(/^flex/, 'flex-')) : key
×
37

38
    style[newKey] = value
×
39
  }
40

41
  if (flexReg.test(key)) {
1✔
42
    const postfix = key.replace(/^flex/, '').toLowerCase()
1✔
43
    style.flex = flexMaps[postfix]
1✔
44
  }
45

46
  return style
1✔
47
}
48

49
export default (): FowerPlugin => {
1✔
50
  return {
1✔
51
    isMatch,
52
    handleAtom(atom) {
53
      // special key: flex={true} -> display: 'flex'
54
      if (atom.propKey === 'flex' && atom.isTruePropValue) {
5✔
55
        atom.style = { display: 'flex' }
1✔
56
      } else {
57
        atom.style = toStyle(atom)
4✔
58
      }
59

60
      return atom
5✔
61
    },
62
  }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc