0.2.0 • Published 7 years ago
flow-type-complexity v0.2.0
flow-type-complexity
Calculates complexity of each Flow type alias in a file.
Installation
$ [sudo] npm install -g flow-type-complexityUsage
$ flow-type-complexity <filename>By default, only 5 types with the greatest complexity are showing.
To see complexity of all types, use option -a (or --show-all).
See help:
$ flow-type-complexity --helpExamples
1.js:
// @flow
export type TypeA = 5 | TypeB
type TypeB = { a: number, b: 2, c: null }
type TypeC = {
d: 4,
b: TypeB
}$ flow-type-complexity 1.jsOutput:
TypeA: { unions: 1, primitives: 4 }
TypeC: { unions: 0, primitives: 4 }
TypeB: { unions: 0, primitives: 3 }2.js:
// @flow
type TypeA = { a: 2 } | void
type TypeB = { a: TypeA } | { b: 2 } | { c: null }
type TypeC = { d: 4, b: TypeB }
type TypeD = { a: string, c: TypeC | 'str', b: any }
type TypeE = { a: mixed, d: TypeD }
type TypeF = { e: TypeE, x: number }$ flow-type-complexity 2.jsOutput:
TypeF: { unions: 4, primitives: 10 }
TypeE: { unions: 4, primitives: 9 }
TypeD: { unions: 4, primitives: 8 }
TypeC: { unions: 3, primitives: 5 }
TypeB: { unions: 3, primitives: 4 }With show-all:
$ flow-type-complexity 2.js --show-allOutput:
TypeF: { unions: 4, primitives: 10 }
TypeE: { unions: 4, primitives: 9 }
TypeD: { unions: 4, primitives: 8 }
TypeC: { unions: 3, primitives: 5 }
TypeB: { unions: 3, primitives: 4 }
TypeA: { unions: 1, primitives: 2 }0.2.0
7 years ago