| Total Complexity | 6 |
| Complexity/F | 1.5 |
| Lines of Code | 34 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | const stringifyProperty: SymbolConstructor["toPrimitive"] | "valueOf" | "toString" = Symbol.toPrimitive |
||
| 2 | |||
| 3 | const { |
||
| 4 | defineProperty: $defineProperty |
||
| 5 | } = Object |
||
| 6 | |||
| 7 | export { |
||
| 8 | stringifyClassNamed, emptize |
||
| 9 | } |
||
| 10 | |||
| 11 | function stringifyClassNamed<T extends {className: string}>(source: T) :T { |
||
| 12 | if (!source.hasOwnProperty(stringifyProperty)) |
||
| 13 | $defineProperty(source, stringifyProperty, {value: classNamedToString}) |
||
| 14 | |||
| 15 | return source |
||
| 16 | } |
||
| 17 | |||
| 18 | function classNamedToString(this: {className: string}) { |
||
| 19 | return this.className |
||
| 20 | } |
||
| 21 | |||
| 22 | function emptize(source: undefined|Record<string, any>) { |
||
| 23 | if ( |
||
| 24 | source |
||
| 25 | && !source.hasOwnProperty(stringifyProperty) |
||
| 26 | ) |
||
| 27 | $defineProperty(source, stringifyProperty, {value: emptyLambda}) |
||
| 28 | return source |
||
| 29 | } |
||
| 30 | |||
| 31 | function emptyLambda() { |
||
| 32 | return "" as const |
||
| 33 | } |
||
| 34 |