| 9 | * specific to properties. |
| 10 | */ |
| 11 | export default class StyleNormalizer { |
| 12 | constructor() { |
| 13 | this.normalizers = {}; |
| 14 | this.createNormalizers('margin', [HORIZONTAL, VERTICAL, SIDES]); |
| 15 | this.createNormalizers('padding', [HORIZONTAL, VERTICAL, SIDES]); |
| 16 | } |
| 17 | |
| 18 | createNormalizers(prop, shorthands, suffix = '') { |
| 19 | shorthands.forEach(shorthand => { |
| 20 | const propName = prop + shorthand.type + suffix; |
| 21 | |
| 22 | if (this.normalizerExists(propName)) { |
| 23 | throw Error(`Normalizer for '${propName}' shorthand already exists`); |
| 24 | } |
| 25 | |
| 26 | this.normalizers[propName] = ShorthandsNormalizerFactory.createNormalizer( |
| 27 | prop, |
| 28 | shorthand, |
| 29 | suffix, |
| 30 | ); |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | normalizerExists(normalizerName) { |
| 35 | return !!this.normalizers[normalizerName]; |
| 36 | } |
| 37 | |
| 38 | canNormalize(prop) { |
| 39 | return this.normalizerExists(prop); |
| 40 | } |
| 41 | |
| 42 | normalize(prop, val) { |
| 43 | return this.normalizers[prop](val); |
| 44 | } |
| 45 | } |
nothing calls this directly
no outgoing calls
no test coverage detected